问题
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