2022-08-03 13:52:23 +02:00
|
|
|
## =============================================================================
|
|
|
|
## Requirements
|
|
|
|
## =============================================================================
|
|
|
|
|
|
|
|
library(gtsummary)
|
|
|
|
|
|
|
|
## =============================================================================
|
|
|
|
## Loop
|
|
|
|
## =============================================================================
|
|
|
|
|
|
|
|
bm_list_strat<-list()
|
|
|
|
|
|
|
|
for (i in 1:length(outs)){
|
|
|
|
## Bivariate
|
|
|
|
biv<-dta |>
|
2022-09-14 14:34:34 +02:00
|
|
|
dplyr::select(all_of(c("active_treat",vars,outs[i]))) |>
|
2022-08-03 13:52:23 +02:00
|
|
|
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 |>
|
2022-09-14 14:34:34 +02:00
|
|
|
dplyr::select(all_of(c("active_treat",vars,outs[i]))) |>
|
2022-08-03 13:52:23 +02:00
|
|
|
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**")
|
|
|
|
)
|