Reputation: 33
Please, how do I assign the N, Log-likelihood, AIC, and BIC values to each of the multivariate regression models in a merged gtsummary
table output?
I am a Rmerteur trying to fit additive multivariate models adding higher-level variables to subsequent models (see below example). Meanwhile, I could not retain the N, Log-likelihood, AIC, and BIC values for each model fit once I merge the separate models. I need the estimates to compare the fit across the models.
Is there an easy way to get this done?
Thank you for your help!
m1<-
tbl_regression(mod1,
exponentiate = T, hide_n = T,
add_estimate_to_reference_rows = T,
estimate_fun = ~style_ratio(.x, digits = 2),
pvalue_fun = ~style_pvalue(.x, digits = 2),
label = list(age_yr_grp ~ "Age",
educ ~ "Education")) %>%
bold_p(t = 0.05) %>%
add_glance_source_note()
m2<-
tbl_regression(mod2,
exponentiate = T, hide_n = T,
add_estimate_to_reference_rows = T,
estimate_fun = ~style_ratio(.x, digits = 2),
pvalue_fun = ~style_pvalue(.x, digits = 2),
label = list(age_yr_grp ~ "Age",
educ ~ "Education",
hhwealth ~ "Household wealth",
hhsize ~ "Household size")) %>%
bold_p(t = 0.05) %>%
add_glance_source_note()
m3<-
tbl_regression(mod3,
exponentiate = T, hide_n = T,
add_estimate_to_reference_rows = T,
estimate_fun = ~style_ratio(.x, digits = 2),
pvalue_fun = ~style_pvalue(.x, digits = 2),
label = list(age_yr_grp ~ "Age",
educ ~ "Education",
hhwealth ~ "Household wealth",
hhsize ~ "Household size",
placeres~ "Area of residence")) %>%
bold_p(t = 0.05) %>%
add_glance_source_note()
tab3_multivars_models=
tbl_merge(list(m1,m2,m3),
tab_spanner= c("**Mod 1**","**Mod 2**","**Mod 3**"))%>%
as_gt() %>%
tab_header(title = "Table title here") %>%
tab_source_note(gt::md("*Notes here"))
gt::gtsave(tab3_multivars_models, "dir\\tab3_multivars_models.html", inline_css = TRUE)
Upvotes: 2
Views: 333
Reputation: 11680
You'll want to use add_glance_table()
instead of the source note version.
library(gtsummary)
#> #Uighur
packageVersion("gtsummary")
#> [1] '1.4.0'
tbl1 <-
lm(age ~ marker + grade, trial) %>%
tbl_regression() %>%
add_glance_table(
label = list(sigma ~ "\U03C3"),
include = c(r.squared, AIC, sigma)
)
tbl2 <- tbl_merge(list(tbl1, tbl1))
Created on 2021-04-17 by the reprex package (v2.0.0)
Upvotes: 2