Skip to contents

[Experimental]

Usage

leo_cox_subgroup(
  df,
  y_out,
  x_exp,
  x_subgroup,
  x_cov = NULL,
  event_value = 1,
  min_followup_time = 0,
  x_exp_type = "auto",
  x_subgroup_type = "categorical",
  add_interaction = TRUE,
  add_heterogeneity = FALSE,
  verbose = TRUE
)

leo_cox_subgroup_format(x, style = "wide")

Arguments

df

Data frame containing the outcome, follow-up time, exposure, subgroup variables, and covariates.

y_out

Character vector of length 2 giving the event and follow-up time column names: c(event, time).

x_exp

Character scalar giving the exposure column name.

x_subgroup

Character vector giving one or more subgroup column names.

x_cov

NULL, a character vector of covariate column names, or a list of covariate column-name vectors.

event_value

Value in the event column that indicates incident events.

min_followup_time

Numeric scalar; keep rows with time > min_followup_time.

x_exp_type

Exposure type handling for x_exp.

x_subgroup_type

Type handling for x_subgroup. Subgroup analyses are expected to use categorical grouping variables.

add_interaction

Logical; whether to append P for interaction from leo_cox_interaction().

add_heterogeneity

Logical; whether to calculate a heterogeneity P value from subgroup summary statistics.

verbose

Logical; print progress messages.

x

Result returned by leo_cox_subgroup().

style

One of "wide" or "tidy".

Value

A leo_cox_subgroup object containing a subgroup result table in $result and, when requested, interaction test objects in $interaction. When x_subgroup has length 1, $interaction is a single leo_cox_interaction object; otherwise it is a named list of leo_cox_interaction objects keyed by subgroup variable.

Details

leo_cox_subgroup() runs leo_cox() within each level of one or more subgroup variables and appends a P for interaction from leo_cox_interaction(). Optionally, it also calculates a summary-statistic heterogeneity P value using leo_heterogeneity_p().

Examples

lung_df <- stats::na.omit(
  dplyr::transmute(
    survival::lung,
    outcome = as.integer(status == 2),
    outcome_censor = time / 365.25,
    age = age,
    sex = factor(sex, levels = c(1, 2), labels = c("Male", "Female")),
    ecog_group = factor(ph.ecog, levels = 0:3, labels = c("ECOG0", "ECOG1", "ECOG2", "ECOG3"))
  )
)

model <- list("Crude" = NULL, "Model A" = c("ecog_group"))
res_sub <- leo_cox_subgroup(
  df = lung_df, y_out = c("outcome", "outcome_censor"),
  x_exp = "age", x_subgroup = "sex", x_cov = model, verbose = FALSE
)
res_sub$result
#>   Subgroup  Level   N   Model Exposure Outcome    Exposure level Case N
#> 1      sex   Male 137   Crude      age outcome Per unit increase    111
#> 2      sex   Male 137 Model A      age outcome Per unit increase    111
#> 3      sex Female  90   Crude      age outcome Per unit increase     53
#> 4      sex Female  90 Model A      age outcome Per unit increase     53
#>   Control N Person-years    HR       95% CI P value P for interaction
#> 1        26    106.81725 1.020 0.997, 1.043   0.088             0.602
#> 2        26    106.81725 1.018 0.996, 1.042   0.114             0.195
#> 3        37     83.52361 1.011 0.980, 1.042   0.494             0.602
#> 4        37     83.52361 0.985 0.952, 1.019   0.377             0.195
leo_cox_subgroup_format(res_sub, style = "wide")
#>   Subgroup  Level   N Exposure Outcome    Exposure level Case N Control N
#> 1      sex   Male 137      age outcome Per unit increase    111        26
#> 2      sex Female  90      age outcome Per unit increase     53        37
#>   Person-years Crude HR Crude 95% CI Crude P value Crude P for interaction
#> 1    106.81725    1.020 0.997, 1.043         0.088                   0.602
#> 2     83.52361    1.011 0.980, 1.042         0.494                   0.602
#>   Model A HR Model A 95% CI Model A P value Model A P for interaction
#> 1      1.018   0.996, 1.042           0.114                     0.195
#> 2      0.985   0.952, 1.019           0.377                     0.195