Merging tbl_svysummary and stacked tbl_regression tables with different variable names but same labels

五迷三道 提交于 2021-01-28 07:55:09

问题


Follow up question to (Renaming Rows in gtsummary, tbl_regression/tbl_stack):

I am now trying to merge the renamed, stacked table (Table 1) with a tbl_summary table that includes the prevalence for each of the outcomes (Table 2). However, because each renamed line of Table 1 is, in reality, just the same variable repeated over and over again, it doesn't merge with Table 2, instead creating a (Table 3) that has duplicated outcome names stacked onto one another. Any way to merge these tables so that the lines of Table 1 match seamlessly with those from Table 2?


回答1:


I think this is what you're after....regardless, I hope it helps.

library(gtsummary)
packageVersion("gtsummary")
#> '1.3.6'

# 1. build reg models for varying outcomes, 
# 2. show covariate for age in table for all outcomes, 
# 3. adjust all models for marker level
tbl_reg <- 
  trial %>%
  select(response, death, age, marker) %>%
  tbl_uvregression(
    x = age, 
    method = glm,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    formula = "{y} ~ {x} + marker",
    hide_n = TRUE,
    include = -marker
  ) %>%
  modify_header(
    list(label ~ "**Outcome**", 
         estimate ~ "**Age OR**")) 

# Create summary table showing prev. of outcomes
tbl_prev <-
  trial %>%
  select(response, death) %>%
  tbl_summary(missing = "no") %>%
  modify_header(stat_0 ~ "**Outcome Prevalence**")

tbl_merge(list(tbl_prev, tbl_reg)) %>%
  modify_spanning_header(everything() ~ NA) %>%
  as_gt() %>%
  gt::tab_source_note("All models adjusted for marker level at baseline.")



来源:https://stackoverflow.com/questions/65673290/merging-tbl-svysummary-and-stacked-tbl-regression-tables-with-different-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!