使用 gtsummary 显示多个模型的 r 平方、aic、bic 和偏​​差

show r squared, aic, bic, and deviance for multiple models using gtsummary

希望在合并输出中为此处的四个模型中的每一个提供 r 平方、aic、bic 和偏​​差值

mod0 <- lm(surv_time ~ Age + Gender + Education + `Standardized MoCA`, data = surv_tbldata_converters)
mod1 <- lm(surv_time ~ Age + Gender + Education + `Global Composite`, data = surv_tbldata_converters)

mod2 <- lm(surv_time ~ Age + Gender + Education + `Standardized MoCA`, data = surv_tbldata)
mod3 <- lm(surv_time ~ Age + Gender + Education + `Global Composite`, data = surv_tbldata)

mod0_tbl <- mod0 %>%
  tbl_regression(exponentiate = F) %>%
  add_glance_source_note(include = c(r.squared, AIC, BIC, deviance))

mod1_tbl <- mod1 %>%
  tbl_regression(exponentiate = F) %>%
  add_glance_source_note(include = c(r.squared, AIC, BIC, deviance))

mod2_tbl <- mod2 %>%
  tbl_regression(exponentiate = F) %>%
  add_glance_source_note(include = c(r.squared, AIC, BIC, deviance))

mod3_tbl <- mod3 %>%
  tbl_regression(exponentiate = F) %>%
  add_glance_source_note(include = c(r.squared, AIC, BIC, deviance))

# merge tables 
tbl_merge(tbls = list(mod2_tbl, mod3_tbl, mod0_tbl, mod1_tbl),
          tab_spanner = c("**MoCA Model (Full Sample)**", "**Global Composite Model (Full Sample)**", "**MoCA Model (Converters Only)**", "**Global Composite Model (Converters Only)**")) %>%
  modify_header(label = "**Predictor**") %>%
  modify_caption("**Table 3. Study One Model Comparisons**")  %>%
  bold_labels() 

add_glance_source_note()函数将统计数据添加为一个源注释,table可能只有一个源注释。使用 add_glance_table() 函数将统计信息添加到 table 的底部,您将能够毫无问题地合并 table。示例如下!

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.4.1'

lm1 <- lm(age ~ trt + grade, trial) 
lm2 <- lm(marker ~ trt + grade, trial)

tbl1 <-
  tbl_regression(lm1) %>%
  add_glance_table(include = c(r.squared, AIC, BIC, deviance))
tbl2 <-
  tbl_regression(lm2) %>%
  add_glance_table(include = c(r.squared, AIC, BIC, deviance))


tbl_all <- tbl_merge(list(tbl1, tbl2))

reprex package (v2.0.0)

于 2021-06-08 创建