I am using Rmarkdown. I would like to display the results of fitting an ordinal regression model (fitted using the rms package) in a table using the tbl_regression function. The tbl_regression function seems to work and display the fitted coefficients for continuous variables but it omits the results for factors. See the example below:
knitr::opts_chunk$set(echo = FALSE,
message = FALSE,
warning = FALSE)
library(tidyverse)
library(Hmisc)
library(rms)
library(gt)
library(gtsummary)
summary(mtcars)
# convert cyl into an ordinal variable
mtcars$cyl <- ordered(mtcars$cyl,
levels = c("4","6","8"))
# convert gear and am into factors
mtcars$gear <- as.factor(mtcars$gear)
mtcars$am <- as.factor(mtcars$am)
# run the dd comand for the rms package
dd <- datadist(mtcars)
options(datadist="dd")
# fit the model using the orm function
model1 <- orm(cyl ~ gear + am + wt,
data = mtcars,
x = TRUE,
y = TRUE)
print(model1)
model1 %>%
tbl_regression(exponentiate = TRUE)
In the example above the results for the continuous variable wt are displayed in the summary table but the results for the factors am and wt are omitted. Is it possible to display the results for the factors?
I tried to explicitly include the factors using the include argument but an error occured:
model1 %>% tbl_regression(exponentiate = TRUE, include = c(VAM, Mindset, Preference, study_cat, points))
! broom::tidy() failed to tidy the model.
✔ tidy_parameters() used instead.
ℹ Add tidy_fun = broom.helpers::tidy_parameters to quiet these messages.
Error:
! Error in include= argument input. Select from ‘wt’
Backtrace:
- model1 %>% ...
- broom.helpers::tidy_select_variables(...)
- broom.helpers::.select_to_varnames(...)
- base::tryCatch(...)
- base (local) tryCatchList(expr, classes, parentenv, handlers)
- base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
- value[3L]
Any information would be appreciated.