mediation_inference: Mediation Inference via De-biased Lasso

View source: R/10_mediation_inference.R

mediation_inferenceR Documentation

Mediation Inference via De-biased Lasso

Description

Step 2 of the TransHDM pipeline: de-biased lasso estimation following screening (SIS, Step 1). It consists of two sub-steps:

  • Step 2.1 — Outcome model (beta): estimates mediator-outcome effects by regressing the outcome Y on all retained mediators, the exposure D, and covariates X.

  • Step 2.2 — Mediator models (alpha): estimates exposure-mediator effects by regressing each mediator on D and X.

Both steps support transfer learning. A list of source datasets is row-bound into one source before estimation. Results are passed to joint_test (Step 3) for multiple testing.

Usage

mediation_inference(
  screen_result = NULL,
  target_data = NULL,
  source_data = NULL,
  Y = NULL,
  D = NULL,
  M = NULL,
  X = NULL,
  transfer = FALSE,
  verbose = TRUE,
  ncore = 1
)

Arguments

screen_result

An object of class "SIS" returned by SIS. When provided, Y, D, M, and X are automatically extracted from it. If NULL, target_data (and optionally source_data) are used directly without screening, and Y, D, M, X must be supplied explicitly.

target_data

A data frame containing the target dataset. Required when screen_result = NULL. Ignored otherwise.

source_data

A data frame, or a list of data frames, containing source datasets (optional, default: NULL). Used only when transfer = TRUE and screen_result = NULL. A list is row-bound into one source dataset before estimation.

Y

Character string specifying the outcome variable name. Required only when screen_result = NULL; otherwise extracted from screen_result.

D

Character string specifying the exposure variable name. Required only when screen_result = NULL.

M

Character vector specifying the full set of mediator variable names (before screening). Required only when screen_result = NULL; otherwise extracted from screen_result.

X

Character vector specifying covariate variable names. Required only when screen_result = NULL.

transfer

A logical value (default: FALSE) indicating whether to enable transfer learning.

verbose

A logical value (default: TRUE) controlling whether progress messages are printed.

ncore

An integer (default: 1) specifying the number of CPU cores for parallel computation of mediator models.

Details

The variance estimator follows Algorithm 3 of Tian and Feng (2023). For Gaussian linear models, it assumes unit error variance. Under the required source-target heterogeneity conditions, pooled source and target design information is used to estimate the correlation structure, while the debiasing correction is based on target-domain data. This assumption is not automatically verified by the function.

Value

An object of class "mediation_inference" — a list with:

  • DE_est: Estimated direct effect of D on Y.

  • alpha_SIS_est: Named numeric vector of alpha estimates (exposure-mediator effects) for all mediators in M. Non-selected mediators are set to zero.

  • P_alpha_SIS: Named numeric vector of p-values for alpha.

  • beta_SIS_est: Named numeric vector of beta estimates (mediator-outcome effects) for all mediators in M. Non-selected mediators are set to zero.

  • P_beta_SIS: Named numeric vector of p-values for beta.

  • M: The full mediator name vector.

  • M_SIS: Mediators retained after screening.

  • D: The exposure variable name.

See Also

TransHDM, joint_test, SIS

Examples


set.seed(123)
target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data
source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1,
  source = TRUE, transferable = TRUE)$data
M_vars <- paste0("M", 1:20)
X_vars <- paste0("X", 1:3)

# With screening (SIS)
sis <- SIS(target_data, source_data, Y = "Y", D = "D", M = M_vars,
  X = X_vars, transfer = TRUE, topN = 10)
infer <- mediation_inference(sis, transfer = TRUE)

# Without screening (use all mediators directly)
infer_ns <- mediation_inference(
  target_data = target_data, source_data = source_data,
  Y = "Y", D = "D", M = M_vars, X = X_vars,
  transfer = TRUE)



TransHDM documentation built on Nov. 24, 2026, 9:06 a.m.