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).
# 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.
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]"
"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."
"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."
"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."
"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."
"Run g-formula mediation via CMAverse for treatment exposure with time-varying confounders measured at three timepoints."
"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."
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.hima_classic) screens by beta only and reverses the screening regime relative to HIMA2; HIMA2 (hima) screens by alpha-beta -- HIMA2 is more powerful for mediators with strong exposure-effect (alpha) but weak outcome-effect (beta). Pin HIMA >= 2.3.0 for the formula interface used in this skill's examples; on 2.2.x the classic engine is the positional hima(X, Y, M, ...) call (there is no hima_classic() until 2.3+) and the formula interface is unavailable.hima(); survival needs hima_cox, count needs hima_pois.boot.ci.type='bca' (lowercase) NOT 'BCa'; BCa requires more sims than percentile (recommend >= 5000) and can fail to converge when the acceleration estimate is unstable near boundary cases. Fall back to percentile CIs in that case and document.mediate() or CMAverse, not the hand-computed product.CMAverse::cmest(estimation='msm') or gfoRmula.medsens() requires linear or probit outcome models -- refit with family=binomial(link='probit') for sensitivity on binary outcomes.COV.XM and COV.MY.acme_rr = exp(ACME) on the log scale for continuous, or via VanderWeele's marginal RR for binary), then E = RR + sqrt(RR * (RR - 1)); the corresponding lower-bound RR gives the E-value for the CI. EValue::evalues.OLS() automates this for linear outcomes.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.