Skip to contents

[Experimental]

Usage

leo_cox_interaction(
  df,
  y_out,
  x_exp,
  x_inter,
  x_cov = NULL,
  event_value = 1,
  min_followup_time = 0,
  x_exp_type = "auto",
  x_inter_type = "auto",
  verbose = TRUE
)

leo_cox_add_interaction(
  df,
  y_out,
  x_exp,
  x_inter,
  x_cov = NULL,
  event_value = 1,
  min_followup_time = 0,
  reference_group = c("auto", "double_negative"),
  verbose = TRUE
)

Arguments

df

Data frame containing the outcome, follow-up time, exposure, interaction variable, 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_inter

Character scalar giving the interaction variable column name.

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_inter_type

Interaction-variable type handling for x_inter.

verbose

Logical; print progress messages.

reference_group

Reference-group strategy for additive interaction. Use "auto" to follow the preventive-exposure recode convention described by interactionR, or "double_negative" to keep the original double-negative group as the reference.

Value

A leo_cox_interaction object containing a display table in $result, the fitted no-interaction Cox models in $fit_main, the fitted interaction Cox models in $fit_inter, and the corresponding model formulas in $formula_main and $formula_inter.

A leo_cox_add_interaction object containing a display table in $result, the fitted no-interaction Cox models in $fit_main, the fitted interaction Cox models in $fit_inter, the corresponding model formulas in $formula_main and $formula_inter, and the raw interactionR backend objects in $backend.

Details

leo_cox_interaction() tests whether the association between an exposure and an incident outcome differs by a candidate interaction variable. It compares nested Cox models with and without the interaction term using stats::anova(..., test = "Chisq").

leo_cox_add_interaction() focuses on the binary-binary setting and reports additive interaction summaries from a Cox model, including RERI, AP, and S, together with the multiplicative interaction estimate. When the original binary coding does not follow the reference-group convention expected by interactionR, leo_cox_add_interaction() can either keep the original double-negative group as the reference or manually recode the two binary variables before handing the fitted interaction model to interactionR.

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"))
leo_cox_interaction(
  df = lung_df, y_out = c("outcome", "outcome_censor"),
  x_exp = "age", x_inter = "sex", x_cov = model, verbose = FALSE
)$result
#>     Model Exposure Interaction   N Case N Control N Person-years Interaction DF
#> 1   Crude      age         sex 227    164        63     190.3409              1
#> 2 Model A      age         sex 227    164        63     190.3409              1
#>   P for interaction Exposure class Interaction class
#> 1             0.602     Continuous            Binary
#> 2             0.195     Continuous            Binary
if (requireNamespace("interactionR", quietly = TRUE)) {
  lung_df <- stats::na.omit(
    dplyr::transmute(
      survival::lung,
      outcome = as.integer(status == 2),
      outcome_censor = time / 365.25,
      smoking = factor(age > median(age), levels = c(FALSE, TRUE), labels = c("Low", "High")),
      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"))
  leo_cox_add_interaction(
    df = lung_df, y_out = c("outcome", "outcome_censor"),
    x_exp = "smoking", x_inter = "sex", x_cov = model, verbose = FALSE
  )$result
}
#>     Model Exposure Interaction   N Case N Control N Person-years
#> 1   Crude  smoking         sex 227    164        63     190.3409
#> 2 Model A  smoking         sex 227    164        63     190.3409
#>            Reference group Recode applied Multiplicative interaction
#> 1  smoking=Low, sex=Female           TRUE                      1.299
#> 2 smoking=High, sex=Female           TRUE                      0.655
#>   Multiplicative 95% CI P for interaction   RERI   RERI 95% CI     AP
#> 1          0.670, 2.520             0.439  0.502 -0.308, 1.312  0.245
#> 2          0.335, 1.281             0.216 -0.646 -1.727, 0.435 -0.380
#>       AP 95% CI     S     S 95% CI
#> 1 -0.147, 0.637 1.918 0.402, 9.155
#> 2 -0.998, 0.237 0.520 0.220, 1.229