library(dplyr)
ADEX <- ex_adsl |> select(USUBJID, ARM, TRTSDTM, EOSSTT, EOSDY)
trtvar <- "ARM"
ctrl_grp <- "B: Placebo"
cutoffd <- as.Date("2023-09-24")
ADEX <- ADEX |>
create_colspan_var(
non_active_grp = ctrl_grp,
non_active_grp_span_lbl = " ",
active_grp_span_lbl = "Active Study Agent",
colspan_var = "colspan_trt",
trt_var = trtvar
) |>
mutate(
diff_header = "Difference in Means (95% CI)",
diff_label = paste(!!rlang::sym(trtvar), "vs", ctrl_grp),
TRTDURY = case_when(
!is.na(EOSDY) ~ EOSDY,
TRUE ~ as.integer(cutoffd - as.Date(TRTSDTM) + 1)
)
)
colspan_trt_map <- create_colspan_map(ADEX,
non_active_grp = ctrl_grp,
non_active_grp_span_lbl = " ",
active_grp_span_lbl = "Active Study Agent",
colspan_var = "colspan_trt",
trt_var = trtvar
)
ref_path <- c("colspan_trt", "", trtvar, ctrl_grp)
lyt <- basic_table() |>
split_cols_by(
"colspan_trt",
split_fun = trim_levels_to_map(map = colspan_trt_map)
) |>
split_cols_by(trtvar) |>
split_cols_by("diff_header", nested = FALSE) |>
split_cols_by(
trtvar,
split_fun = remove_split_levels(ctrl_grp),
labels_var = "diff_label"
) |>
analyze("EOSDY",
afun = a_summarize_ex_j, var_labels = "Duration of treatment (Days)",
show_labels = "visible",
indent_mod = 0L,
extra_args = list(
daysconv = 1,
ref_path = ref_path,
variables = list(arm = trtvar, covariates = NULL),
ancova = TRUE,
comp_btw_group = TRUE
)
)
result <- build_table(lyt, ADEX, alt_counts_df = ADEX)
result
Run the code above in your browser using DataLab