在 gtsummary 包中使用tbl_regression
函数我试图堆叠两个线性回归表。一个有一个额外的列,另一个没有。尝试使用该tbl_merge()
功能时,会并排创建两个表,而不是完全堆叠的表(见下图)。
无论如何堆叠两个回归表,以便合并列,并且只有以下四列之一Beta, 95% CI1,p-value,p-trend?
# load packages
library(gtsummary)
theme_gtsummary_compact()
# model 1 ------------------------------------------------------------------
# model cyl as a categorical
mod1 <- lm(mpg ~ cyl, data = mtcars %>% dplyr::mutate(cyl = factor(cyl)))
# model cyl as continuous (p-trend)
mod2 <- lm(mpg ~ cyl, data = mtcars)
# summarize primary model
tbl1 <- tbl_regression(mod1)
# summarize model with p-trend, and hide the estimate and CI
tbl2 <- tbl_regression(mod2) %>%
modify_table_header(c(estimate, ci), hide = TRUE) %>%
modify_header(p.value ~ "**p-trend**")
# merge primary model and p-trend
tbl3 <- tbl_merge(list(tbl1, tbl2)) %>%
# remove spanning header
modify_spanning_header(everything() ~ NA)
# model 2 ------------------------------------------------------------------
# model cyl as a categorical
mod3 <- lm(mpg ~ carb, data = mtcars)
# summarize primary model
tbl4 <- tbl_regression(mod3) %>%
# remove spanning header
modify_spanning_header(everything() ~ NA)
# merge model 1 and 2 ------------------------------------------------------
bl3 <- tbl_merge(
tbls = list(tbl3, tbl4)
)
bl3