Function adapted from gtforester::tbl_subgroups().
tbl_roche_subgroups(data, rsp, by, subgroups, .tbl_fun, time_to_event = NULL)(data.frame, survey.design)
a data frame or survey object
(tidy-select)
Variable to use in responder rate calculations.
(tidy-select)
Variable to make comparison between groups.
(tidy-select)
Variables to perform stratified analyses for.
(function)
A function or formula. If a function, it is used as is.
If a formula, e.g. ~ .x %>% tbl_summary() %>% add_p(), it is converted to a function.
The stratified data frame is passed to this function.
(tidy-select)
Variable to use in time-to-event analyses. If specified, the mid table will
show the median time-to-event instead of responder rates.
a 'gtsummary' table
set.seed(1)
# prepare sample data
df_adtte <- data.frame(
time = rexp(100, rate = 0.1),
status = sample(c(0, 1), 100, replace = TRUE),
arm = sample(c("Arm A", "Arm B"), 100, replace = TRUE),
grade = sample(c("I", "II"), 100, replace = TRUE),
strata = sample(c("1", "2"), 100, replace = TRUE)
) |>
mutate(arm = relevel(factor(arm), ref = "Arm A")) # Set Reference
# logistic regression -------------------------------------------------------
df_adtte |>
tbl_roche_subgroups(
rsp = "status",
by = "arm",
subgroups = c("grade"),
.tbl_fun =
~ glm(status ~ arm, data = .x) |>
tbl_regression(
show_single_row = arm,
exponentiate = TRUE # , tidy_fun = broom.helpers::tidy_parameters
)
) |>
modify_header(starts_with("estimate") ~ "**Odds Ratio**")
n Response (%)
n Response (%)
# coxph regression ----------------------------------------------------------
# please use browser() inside .tbl_fun to check if the coxph model throws an error
# and use tryCatch to modify the input/output accordingly
df_adtte |>
tbl_roche_subgroups(
rsp = status,
by = arm,
time_to_event = time, # Specify time variable for time-to-event analyses (different mid table)
subgroups = c(grade, strata),
~ survival::coxph( # Please use coxph for time-to-event analyses
survival::Surv(time, status) ~ arm,
data = .x,
ties = "exact"
) |> # Exact Ties
tbl_regression(
show_single_row = arm,
exponentiate = TRUE # Get Hazard Ratios
)
) |>
modify_header(starts_with("estimate") ~ "**Hazard Ratio**")
n
Median (Months)
n
Median (Months)