← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-causal-genomics-mediation-analysis / references / usage-guide.md

Mediation Analysis - Usage Guide

Overview

Decomposes the total effect of an exposure (genotype, treatment, environmental factor) on an outcome into direct and indirect paths through one or more mediators. Covers single-mediator observational mediation (mediation::mediate), 4-way decomposition with exposure-mediator interaction (CMAverse), high-dimensional EWAS / transcriptome-wide mediator screening (HIMA / HIMA2 / BAMA), MR-based mediation when sequential ignorability is implausible (two-step MR, MVMR-mediation), and doubly-robust double-ML mediation (causalweight::medDML). Sequential ignorability is fundamentally untestable, so every reported result is paired with a sensitivity analysis (Imai rho or mediational E-value).

Prerequisites

# CRAN
install.packages(c('mediation','bama','causalweight','EValue'))

# GitHub (NOT on CRAN; HIMA archived from CRAN 2026-07 -- needs archived scalreg)
remotes::install_github('YinanZheng/HIMA')
remotes::install_github('BS1125/CMAverse')
remotes::install_github('WSpiller/MVMR')

# r-universe (see causal-genomics/mendelian-randomization)
install.packages('TwoSampleMR', repos=c('https://mrcieu.r-universe.dev','https://cloud.r-project.org'))

# Optional: longitudinal / time-varying confounding
install.packages('gfoRmula')

Compute requirements: - Single-mediator + 5000 bootstrap sims: minutes on a laptop. - HIMA on ~500k CpGs, n=500: 30-60 min with parallel=TRUE, ncore=8. - BAMA Bayesian MCMC: 1-6 hours depending on chain length. - medDML cross-fitted random forests: 10-30 min for n=2000.

Quick Start

Tell the AI agent what kind of mediation question is being asked: - "Test whether expression of GENE_X mediates the effect of rs12345 on disease risk; include sensitivity to unmeasured confounding" - "Run 4-way decomposition for treatment-mediator-outcome with exposure-mediator interaction" - "Screen all 450k CpGs for mediators of smoking-lung-cancer association using HIMA2" - "Run MR-mediation to estimate the fraction of the BMI-CHD effect that goes through LDL" - "Use double-ML mediation to estimate ACME with random-forest nuisance models" - "Compute the mediational E-value for an ACME of 0.04 with 95% CI [0.01, 0.07]"

Example Prompts

Single-Mediator Observational

"I have individual-level data on genotype, gene expression, and binary disease status with covariates age/sex/PCs. Test whether expression mediates the genotype-disease association and report ACME with 95% CI and proportion mediated."

"Run mediation analysis for SNP rs7412 with LDL cholesterol as the mediator and Alzheimer's disease as the outcome; include Imai sensitivity analysis."

4-Way Decomposition with Interaction

"Decompose the smoking-COPD effect into CDE, PIE, INTref, INTmed using FEV1 as the mediator and CMAverse; outcome is binary with rare-disease prevalence around 5%."

"Fit a regression-based 4-way decomposition with exposure-mediator interaction and exposure-set-to-0 reference."

High-Dimensional EWAS / Transcriptome

"Run HIMA2 on the Illumina EPIC methylation matrix to identify CpGs mediating the prenatal-smoking-birthweight relationship; control FDR at 0.05."

"I have RNA-seq counts for 20k genes, n=200 subjects, and a binary case/control outcome. Use HIMA-binomial to find transcripts that mediate exposure-disease."

"Run BAMA with Bayesian shrinkage on 5000 candidate protein mediators."

MR-Mediation

"Run two-step MR for BMI -> diastolic blood pressure -> coronary artery disease using independent instruments at each step; apply Steiger filter."

"Use MVMR-mediation to estimate the direct effect of LDL on CHD adjusting for HDL; report conditional F for each exposure and the indirect path through HDL."

Longitudinal / Time-Varying Confounding

"Run g-formula mediation via CMAverse for treatment exposure with time-varying confounders measured at three timepoints."

Sensitivity

"Compute the mediational E-value for my ACME of 0.05 (95% CI 0.02-0.08) on a binary outcome."

"Run medsens on this mediate result and tell me whether rho_crit is above 0.3."

What the Agent Will Do

  1. Identify the analytic regime: single vs high-D mediators; observational vs IV-based; continuous / binary / survival outcome; presence of suspected E-M interaction.
  2. Choose method: mediation for default observational; CMAverse for interaction or non-trivial outcome models; HIMA / HIMA2 / BAMA for high-D; MR-mediation when IVs are stronger evidence than measured confounder set; medDML for doubly-robust under rich confounders.
  3. Fit mediator and outcome models with appropriate link functions (linear, logistic, Cox).
  4. Bootstrap or analytic CIs (>= 1000 sims exploratory, >= 5000 publication).
  5. Report ACME / ADE / total effect / proportion mediated AND a sensitivity result (Imai rho_crit or mediational E-value).
  6. For high-D: apply BH FDR <= 0.05 and report screened mediator count.
  7. For MR-based: verify conditional F > 10, Steiger filter, and pleiotropy diagnostics.
  8. Flag failure modes encountered (exposure-induced confounder, weak instruments, sparse outcomes).

Tips

Cohort Considerations

Large biobank cohorts have well-characterized strengths and weaknesses for mediation analysis: - UK Biobank: largest n, rich phenotyping, individual-level access via application. EWAS mediation feasible at ~50k subset with EPIC arrays. Survival outcomes via NHS linkage. - FinnGen: well-suited to MR-mediation (summary-stat releases) and time-to-event outcomes (universal-registry follow-up); individual-level mediator measurements limited. - ALSPAC (Avon): longitudinal mediator measurements ideal for time-varying mediation (g-formula, MSM); smaller n caps high-D screening power.