如何将 N、对数似然、AIC 和 BIC 值分配给合并的“gtsummary”table 输出中的每个多元回归模型?
How to assign the N, Log-likelihood, AIC, and BIC values to each of multivariate regression models in a merged `gtsummary` table output?
请问,如何将 N、对数似然、AIC 和 BIC 值分配给合并的 gtsummary
table 输出中的每个多元回归模型?
我是一个 Rmerteur 试图拟合加性多变量模型,向后续模型添加更高级别的变量(参见下面的示例)。同时,一旦我合并了单独的模型,我就无法保留每个模型拟合的 N、对数似然、AIC 和 BIC 值。我需要估计值来比较模型之间的拟合度。
有没有简单的方法来完成这个?
感谢您的帮助!
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)
您需要使用 add_glance_table()
而不是源注释版本。
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))
由 reprex package (v2.0.0)
于 2021-04-17 创建
请问,如何将 N、对数似然、AIC 和 BIC 值分配给合并的 gtsummary
table 输出中的每个多元回归模型?
我是一个 Rmerteur 试图拟合加性多变量模型,向后续模型添加更高级别的变量(参见下面的示例)。同时,一旦我合并了单独的模型,我就无法保留每个模型拟合的 N、对数似然、AIC 和 BIC 值。我需要估计值来比较模型之间的拟合度。
有没有简单的方法来完成这个?
感谢您的帮助!
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)
您需要使用 add_glance_table()
而不是源注释版本。
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))