Function adapted from gtforester::tbl_subgroups().

tbl_roche_subgroups(data, rsp, by, subgroups, .tbl_fun, time_to_event = NULL)

Arguments

data

(data.frame, survey.design)
a data frame or survey object

rsp

(tidy-select)
Variable to use in responder rate calculations.

by

(tidy-select)
Variable to make comparison between groups.

subgroups

(tidy-select)
Variables to perform stratified analyses for.

.tbl_fun

(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.

time_to_event

(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.

Value

a 'gtsummary' table

Examples

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**")
Baseline Risk Factors Total n
Arm A
Arm B
Odds Ratio 95% CI p-value
n Response (%) n Response (%)
All Participants 100 50 (64.0 %) 50 (40.0 %) 0.79 0.65, 0.95 0.0161
grade





    I 57 33 (66.7 %) 24 (37.5 %) 0.75 0.58, 0.96 0.0292
    II 43 17 (58.8 %) 26 (42.3 %) 0.85 0.62, 1.15 0.3007
# 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**")
Baseline Risk Factors Total n
Arm A
Arm B
Hazard Ratio 95% CI p-value
n Median (Months) n Median (Months)
All Participants 100 50 7.8 50 8.1 0.70 0.40, 1.23 0.2126
grade







    I 57 33 6.8 24 10.2 0.48 0.22, 1.07 0.0718
    II 43 17 8.4 26 7.6 1.26 0.48, 3.34 0.6396
strata







    1 52 27 8.0 25 7.7 0.65 0.29, 1.45 0.2901
    2 48 23 5.5 25 9.6 0.73 0.33, 1.63 0.4442