talos-pa-depression/Archive/biv_mul_strat.R

70 lines
1.9 KiB
R
Raw Normal View History

## =============================================================================
## Requirements
## =============================================================================
library(gtsummary)
## =============================================================================
## Loop
## =============================================================================
bm_list_strat<-list()
for (i in 1:length(outs)){
## Bivariate
biv<-dta |>
dplyr::select(all_of(c("active_treat",vars,outs[i]))) |>
tbl_strata(
strata = active_treat,
.tbl_fun =
~ .x %>%
tbl_uvregression(data=.,
y=outs[i],
method=lm,
label = lab_sel(labels_all,vars)
)|>
add_global_p()|>
bold_p() |>
bold_labels() |>
italicize_levels(),
.header = "**{strata}**, N = {n}"
)
## Multivariate
mul<-dta |>
dplyr::select(all_of(c("active_treat",vars,outs[i]))) |>
tbl_strata(
strata = active_treat,
.tbl_fun =
~ .x %>%
lm(formula(paste(c(outs[i],"."),collapse="~")),
data = .) |>
tbl_regression(label = lab_sel(labels_all,vars)
)|>
add_n() |>
add_global_p() |>
bold_p() |>
bold_labels() |>
italicize_levels(),
.header = "**{strata}**, N = {n}"
)
## Merge
biv_mul_strat<-tbl_merge(
tbls = list(biv, mul),
tab_spanner = c("**Bivariate linear regression**",
"**Multivariate linear regression**")
)
bm_list_strat[[i]]<-biv_mul_strat
}
## =============================================================================
## Big merge
## =============================================================================
bm_16_tbl_strat<-tbl_merge(
tbls = bm_list_strat,
tab_spanner = c("**One month follow up**",
"**Six months follow up**")
)