Skip to contents

This wrapper function automates the creation of a three-panel interaction report (Joint Effects, Simple Effects, Additive Interaction). It can return the data as a list, render to the RStudio Viewer, or save the source .Rmd file.

It takes a **single pre-fitted model** as input and works for `glm`, `svyglm`, `coxph`, and `svycoxph` objects.

Usage

reportint(
  interaction_model,
  factor1_name = NULL,
  factor2_name = NULL,
  output = c("list", "viewer", "rmd"),
  output_file = NULL,
  digits_ratio = 2,
  digits_additive = 3,
  conf.level = 0.95,
  verbose = FALSE
)

Arguments

interaction_model

A fitted model object containing an interaction term (e.g., `outcome ~ factor1 * factor2 + ...`).

factor1_name

Character string. The name of the first factor variable. If `NULL` (default), the function will attempt to auto-detect the interaction terms.

factor2_name

Character string. The name of the second factor variable. If `NULL` (default), the function will attempt to auto-detect the interaction terms.

output

Character string. The desired output type:

  • `"list"` (default): Returns a named list containing the data frames for Panel A, B, C, and the notes for Panel D.

  • `"viewer"`: Renders an HTML report to the RStudio Viewer (or default browser).

  • `"rmd"`: Saves the auto-generated .Rmd file. Requires `output_file` to be set.

output_file

Character string. The file path to save the .Rmd file (e.g., "my_report.Rmd"). Only used if `output = "rmd"`.

digits_ratio

Integer. Digits for rounding ORs/CIs in Panels A & B.

digits_additive

Integer. Digits for rounding RERI/AP/S in Panel C.

conf.level

Confidence level (default 0.95).

verbose

Logical. If `TRUE`, prints status messages to the console.

Value

If `output = "list"`, returns a named list of data frames. The list contains: `joint_effects`, `stratum_specific_effects`, `additive_interaction`, `multiplicative_scale`, `model_details`, and two publication-ready summary tables: `effect_modification_report` and `Interaction_report`.

Details

This function requires the 'svyTable1' and 'Publish' packages.

Examples

if (FALSE) { # \dontrun{
# --- Load required libraries for the example ---
if (requireNamespace("svyTable1", quietly = TRUE) &&
    requireNamespace("Publish", quietly = TRUE) &&
    requireNamespace("survey", quietly = TRUE) &&
    requireNamespace("NHANES", quietly = TRUE) &&
    requireNamespace("dplyr", quietly = TRUE) &&
    requireNamespace("tidyr", quietly = TRUE) &&
    requireNamespace("broom", quietly = TRUE)) {

  library(svyTable1)
  library(Publish)
  library(survey)
  library(NHANES)
  library(dplyr)
  library(tidyr)
  library(broom)

  # --- 1. Data Preparation (NHANES Example) ---
  data(NHANESraw)

  vars_needed <- c("Age", "Race1", "BPSysAve", "BMI", "ObeseStatus", "Hypertension_130",
                   "SDMVPSU", "SDMVSTRA", "WTMEC2YR")

  nhanes_adults_processed <- NHANESraw %>%
    dplyr::filter(Age >= 20) %>%
    dplyr::mutate(
      ObeseStatus = factor(ifelse(BMI >= 30, "Obese", "Not Obese"),
                           levels = c("Not Obese", "Obese")),
      Hypertension_130 = factor(ifelse(BPSysAve >= 130, "Yes", "No"),
                                  levels = c("No", "Yes")),
      Race1 = relevel(as.factor(Race1), ref = "White")
    ) %>%
    dplyr::select(dplyr::all_of(vars_needed)) %>%
    tidyr::drop_na()

  adult_design_binary <- svydesign(
    id = ~SDMVPSU, strata = ~SDMVSTRA, weights = ~WTMEC2YR,
    nest = TRUE, data = nhanes_adults_processed
  )

  # --- 2. FIT ONLY THE INTERACTION MODEL ---

  interaction_model_fit <- svyglm(
    Hypertension_130 ~ Race1 * ObeseStatus + Age,
    design = adult_design_binary, family = quasibinomial()
  )

  # --- 3. Run the wrapper function ---

  report_list <- reportint(
    interaction_model = interaction_model_fit
  )

  # You can then print the individual panel tables:
  # print(report_list$joint_effects)
  # print(report_list$stratum_specific_effects)

  # --- OR ---

  # Print the single, publication-ready summary tables:
  # print(report_list$effect_modification_report)
  # print(report_list$Interaction_report)

}
} # }