Skip to contents

This function fits two models—one with and one without an interaction term between an exposure and a potential effect modifier— and compares them using either a likelihood ratio test (LRT) or Wald test. It is useful for assessing whether there is statistical evidence of interaction (effect modification).

Usage

interaction_models(
  data,
  outcome,
  exposure,
  covariates = NULL,
  effect_modifier,
  approach = "logit",
  test = c("LRT", "Wald"),
  verbose = TRUE
)

Arguments

data

A data frame containing all required variables.

outcome

The name of the outcome variable

exposure

The name of the main exposure variable.

covariates

character vector of additional covariates to adjust for

effect_modifier

The name of the variable to test for interaction

approach

The regression modeling approach to use. One of: "logit", "log-binomial", "poisson", "robpoisson", "negbin", or "linear".

test

Type of statistical test for model comparison. Either: "LRT" (likelihood ratio test, default) or "Wald".

verbose

Logical; if TRUE, prints a basic interpretation of whether interaction is likely present (default = FALSE).

Value

A list with the following elements:

  • model_no_interaction: The model without the interaction term.

  • model_with_interaction: The model with the interaction term.

  • p_value: The p-value for interaction (based on selected test).

  • interpretation: A brief text interpretation if verbose = TRUE.

Examples

data <- data_PimaIndiansDiabetes