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 shows n (subjects), Events (from rsp), and Median per arm instead of responder rates. The total column shows Total Events instead of Total n.

Value

a 'gtsummary' table

Examples

if (FALSE) { # identical(Sys.getenv("NOT_CRAN"), "true")
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**")
}
# 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
# \donttest{
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**")
#> Error: object 'df_adtte' not found
# }