合并两个tbl_regression表时,列未合并

时间:2020-11-06 06:47:52

标签: r gtsummary

在gtsummary包中使用tbl_regression函数,我试图堆叠两个线性回归表。一个有一个附加列,另一个没有。尝试使用tbl_merge()函数时,将并排创建两个表,而不是完全堆叠这些表(请参见下图)。

无论如何,都需要堆叠两个回归表,以便合并列,并且以下四个列中只有一个 Beta 95%CI1 ,< em> p值, p趋势

# 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

enter image description here

0 个答案:

没有答案