Created
January 11, 2021 21:19
-
-
Save ddsjoberg/3c3a705c4f64769e8f0423c0eb020f1b to your computer and use it in GitHub Desktop.
SO Possible Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original stack overflow post | |
# https://stackoverflow.com/questions/65673290/merging-tbl-svysummary-and-stacked-tbl-regression-tables-with-different-variable | |
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.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment