合并后维护 glance 脚注
Maintaining glance footnotes after merge
我希望在创建 gtsummary::tbl_merge()
时获得与 gtsummary::add_glance_source_note()
相同的结果。
该函数本身接受一个 tbl_regression
作为参数,因此在合并管道中没有使用它,如果我将注释添加到单个 table,当 tables 被合并。
library(tidyverse)
library(gtsummary)
library(nycflights13)
lm_1 <- lm(arr_delay ~ air_time, flights)
tbl_1 <- tbl_regression(lm_1, exponentiate = F) %>%
add_glance_source_note(include = c('r.squared'))
lm_2 <- lm(distance ~ air_time, flights)
tbl_2 <- tbl_regression(lm_2, exponentiate = F) %>%
add_glance_source_note(include = c('r.squared'))
tbl_1
tbl_2
两个 table 都有脚注表明他们模型的 R 平方。但是,当我合并 tables 时,脚注中的适合信息丢失了:
table.pub <- tbl_merge(
list(tbl_1, tbl_2),
tab_spanner = c("Delay", "Distance")
)
有什么办法可以保留“glance
”的信息,或者在最后合并的时候重新附加上table?
谢谢!
更新:从 gtsummary v.1.4.0 开始,使用 add_glance_table()
.
可以更轻松地完成此操作
library(gtsummary)
library(nycflights13)
packageVersion("gtsummary")
#> [1] '1.4.0'
tbl_1 <-
lm(arr_delay ~ air_time, flights) %>%
tbl_regression(exponentiate = F) %>%
add_glance_table(include = c('r.squared'))
tbl_2 <-
lm(distance ~ air_time, flights) %>%
tbl_regression(exponentiate = F) %>%
add_glance_table(include = c('r.squared'))
tbl <-
tbl_merge(
list(tbl_1, tbl_2),
tab_spanner = c("**Delay**", "**Distance**")
)
由 reprex package (v2.0.0)
于 2021-04-15 创建
先前的回复:
glance 统计数据已添加为源注释。棘手的是源注释适用于整个 table。当您只有一个 tbl_regression()
table 时,统计数据指的是什么就一目了然了。但是一旦合并了一个或多个,源注释应该如何呈现就不清楚了。因此,它们在合并后不会显示。
但是,注释保存在 gtsummary table 中,您可以打印它们。在下面的示例中,我根据模型的结果标记每个 R2 值,并将它们添加到合并的 table.
编程愉快!
library(tidyverse)
library(gtsummary)
library(nycflights13)
lm_1 <- lm(arr_delay ~ air_time, flights)
tbl_1 <- tbl_regression(lm_1, exponentiate = F) %>%
add_glance_source_note(include = c('r.squared'))
lm_2 <- lm(distance ~ air_time, flights)
tbl_2 <- tbl_regression(lm_2, exponentiate = F) %>%
add_glance_source_note(include = c('r.squared'))
tbl_1
tbl_2
tbl_merge(
list(tbl_1, tbl_2),
tab_spanner = c("**Delay**", "**Distance**")
) %>%
as_gt() %>%
gt::tab_source_note(
str_glue("Delay {tbl_1$list_output$source_note}; ",
"Distance {tbl_1$list_output$source_note}")
)
我希望在创建 gtsummary::tbl_merge()
时获得与 gtsummary::add_glance_source_note()
相同的结果。
该函数本身接受一个 tbl_regression
作为参数,因此在合并管道中没有使用它,如果我将注释添加到单个 table,当 tables 被合并。
library(tidyverse)
library(gtsummary)
library(nycflights13)
lm_1 <- lm(arr_delay ~ air_time, flights)
tbl_1 <- tbl_regression(lm_1, exponentiate = F) %>%
add_glance_source_note(include = c('r.squared'))
lm_2 <- lm(distance ~ air_time, flights)
tbl_2 <- tbl_regression(lm_2, exponentiate = F) %>%
add_glance_source_note(include = c('r.squared'))
tbl_1
tbl_2
两个 table 都有脚注表明他们模型的 R 平方。但是,当我合并 tables 时,脚注中的适合信息丢失了:
table.pub <- tbl_merge(
list(tbl_1, tbl_2),
tab_spanner = c("Delay", "Distance")
)
有什么办法可以保留“glance
”的信息,或者在最后合并的时候重新附加上table?
谢谢!
更新:从 gtsummary v.1.4.0 开始,使用 add_glance_table()
.
library(gtsummary)
library(nycflights13)
packageVersion("gtsummary")
#> [1] '1.4.0'
tbl_1 <-
lm(arr_delay ~ air_time, flights) %>%
tbl_regression(exponentiate = F) %>%
add_glance_table(include = c('r.squared'))
tbl_2 <-
lm(distance ~ air_time, flights) %>%
tbl_regression(exponentiate = F) %>%
add_glance_table(include = c('r.squared'))
tbl <-
tbl_merge(
list(tbl_1, tbl_2),
tab_spanner = c("**Delay**", "**Distance**")
)
先前的回复:
glance 统计数据已添加为源注释。棘手的是源注释适用于整个 table。当您只有一个 tbl_regression()
table 时,统计数据指的是什么就一目了然了。但是一旦合并了一个或多个,源注释应该如何呈现就不清楚了。因此,它们在合并后不会显示。
但是,注释保存在 gtsummary table 中,您可以打印它们。在下面的示例中,我根据模型的结果标记每个 R2 值,并将它们添加到合并的 table.
编程愉快!
library(tidyverse)
library(gtsummary)
library(nycflights13)
lm_1 <- lm(arr_delay ~ air_time, flights)
tbl_1 <- tbl_regression(lm_1, exponentiate = F) %>%
add_glance_source_note(include = c('r.squared'))
lm_2 <- lm(distance ~ air_time, flights)
tbl_2 <- tbl_regression(lm_2, exponentiate = F) %>%
add_glance_source_note(include = c('r.squared'))
tbl_1
tbl_2
tbl_merge(
list(tbl_1, tbl_2),
tab_spanner = c("**Delay**", "**Distance**")
) %>%
as_gt() %>%
gt::tab_source_note(
str_glue("Delay {tbl_1$list_output$source_note}; ",
"Distance {tbl_1$list_output$source_note}")
)