[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EBPM1983WFQZ1MRDKQZTE6":3,"skill-same:01M7EBPM1983WFQZ1MRDKQZTE6":74},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":14,"repositoryHtmlUrl":33,"repositoryHomepageUrl":33,"ownerHtmlUrl":34,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":35,"install":36,"resources":49},"01M7EBPM1983WFQZ1MRDKQZTE6","bio-causal-genomics-mediation-analysis",null,"Decompose total effects into direct and indirect paths through mediators using mediation, CMAverse 4-way, HIMA\u002FHIMA2 high-dimensional, BAMA, two-step \u002F MVMR mediation, or double-ML medDML. Use when testing whether a molecular phenotype (expression, methylation, protein) mediates a treatment-outcome relationship, decomposing exposure-mediator interaction via VanderWeele 4-way, screening high-dimensional EWAS mediators, or running MR-based mediation when sequential ignorability is implausible.","Mr-Nobody-Anonymous\u002FAll-skills","Mr-Nobody-Anonymous","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184253119?v=4","01M7AEXFJHKTYQW5R0ZCQQTWFV","anonymous","01M7C00M3GQR4QKP9GZA42GFAK",0,"MIT","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-causal-genomics-mediation-analysis\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: bio-causal-genomics-mediation-analysis\ndescription: Decompose total effects into direct and indirect paths through mediators using mediation, CMAverse 4-way, HIMA\u002FHIMA2 high-dimensional, BAMA, two-step \u002F MVMR mediation, or double-ML medDML. Use when testing whether a molecular phenotype (expression, methylation, protein) mediates a treatment-outcome relationship, decomposing exposure-mediator interaction via VanderWeele 4-way, screening high-dimensional EWAS mediators, or running MR-based mediation when sequential ignorability is implausible.\ntool_type: mixed\nprimary_tool: mediation\nsource: \"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills\"\nsource_repository: \"GPTomics\u002FbioSkills\"\nsource_path: \"causal-genomics\u002Fmediation-analysis\u002FSKILL.md\"\nlicense: \"MIT\"\nimported_at: \"2026-09-20\"\n---\n\n## Version Compatibility\n\nReference examples tested with: R 4.3+, mediation 4.5.0+, CMAverse 0.1.0+ (GitHub `BS1125\u002FCMAverse`), HIMA >= 2.3.0 (GitHub `YinanZheng\u002FHIMA`; archived from CRAN 2026-07), bama 1.3+, causalweight 1.0.5+ (medDML), MVMR 0.4+, TwoSampleMR 0.6+, EValue 4.1+, gesttools 1.3+, ipw 1.0.11+.\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- R: `packageVersion('\u003Cpkg>')` then `?function_name` to verify parameters\n- HIMA must be pinned at `>= 2.3.0` for the code patterns below; the formula interface `hima(formula, data.pheno, data.M, mediator.type, penalty, ...)` was introduced in 2.3.0. On HIMA 2.2.x the classic engine is the top-level `hima(X, Y, M, COV.XM=, COV.MY=, Y.family=, penalty=)` (positional order X, Y, M) with no formula interface; HIMA 2.2.x is NOT API-compatible with the examples here.\n- In 2.3+ the classic engine is `hima_classic(X, M, Y, COV.XM=, COV.MY=, Y.type=)` (positional order X, M, Y; outcome type via `Y.type`, not `Y.family`); use it only to reproduce the original 2016-2021 SIS+penalty pipelines.\n\nIf code throws an error, introspect the installed package (`?hima`, `args(cmest)`) and adapt the example to match the actual API rather than retrying.\n\n# Mediation Analysis\n\n**\"Does expression of GENE_X mediate the SNP-to-disease effect?\"** -> Decompose the total effect of a treatment (genotype, exposure) on an outcome into direct and indirect paths through one or more mediators, with explicit handling of exposure-mediator interaction, sensitivity to unmeasured confounding, and high-dimensional mediator screening.\n\n- R (single-mediator, observational, sequential-ignorability assumed): `mediation::mediate(med_model, out_model, treat='X', mediator='M', boot=TRUE, sims=5000)`\n- R (4-way decomposition with exposure-mediator interaction): `CMAverse::cmest(...EMint=TRUE, estimation='paramfunc', inference='bootstrap', nboot=1000)`\n- R (high-dimensional \u002F EWAS mediators): `HIMA::hima(Y ~ X + covariates, data.pheno, data.M, mediator.type='gaussian', penalty='DBlasso')` (modern v2.3+ formula interface)\n- R (MR-based mediation): two-step `TwoSampleMR` with independent instruments OR `MVMR::ivw_mvmr` for joint direct effect\n- R (doubly-robust double-ML): `causalweight::medDML(y, d, m, x)`\n\nSequential ignorability (no unmeasured confounder of treatment-mediator, mediator-outcome, treatment-outcome) is the single load-bearing assumption of observational mediation and is fundamentally untestable. Every report should include a sensitivity result (Imai's rho via `medsens()` or a mediational E-value).\n\n## Algorithmic Taxonomy\n\n| Method | Framework | Handles E-M interaction | High-D mediators | Min n | Fails when |\n|--------|-----------|--------------------------|------------------|-------|------------|\n| Baron-Kenny (1986) | Additive regression-based product\u002Fdifference | No | No | ~100 | Any non-linearity, interaction, or binary outcome; deprecated for causal inference |\n| Imai mediation R (Imai 2010 Psychol Methods) | Counterfactual ACME\u002FADE with bootstrap | Yes (via interaction term in outcome model) | No | ~200 | Sequential ignorability violated; exposure-induced M-Y confounder; rare binary outcome with logistic outcome model |\n| VanderWeele 4-way (VanderWeele 2014 Epidemiology 25:749; 2015 OUP) | CDE + PIE + INTref + INTmed decomposition | Native | No | ~300 | Without interaction term reduces to standard mediation; binary outcome needs rare-disease assumption |\n| CMAverse (Shi 2021 Epidemiology 32:e20) | 6 estimators: regression (`rb`), weighting (`wb`), IORW (`iorw`), natural effect models (`ne`), MSM (`msm`), g-formula (`gformula`) | Yes | No (single M, or M-vector) | ~300 | Estimator-specific; `wb` fails with rare exposure; `msm` needs censoring weights for survival |\n| HIMA1 \u002F hima_classic (Zhang 2016 Bioinformatics 32:3150) | SIS screen by beta (M->Y) + MCP penalty | No | Yes (up to ~10k) | ~150 + p>>n | Misses mediators with strong alpha and weak beta; screening-step false-negatives |\n| HIMA2 \u002F hima (Perera 2022 BMC Bioinformatics 23:296) | SIS screen by alpha*beta (indirect effect) + de-biased Lasso (DBlasso) | No (linear by default) | Yes | ~150 | Outcome family limited (gaussian\u002Fbinomial); HIMA-Cox for survival; HIMA-Pois for count |\n| HILAMA (Wang et al 2025) | High-D mediation with latent confounders | No | Yes (>= 100k) | ~500 | Newer; benchmarks evolving; requires latent-factor specification |\n| BAMA (Song 2020 Biometrics) | Bayesian high-D continuous shrinkage | No | Yes (~5k) | ~200 | Slow MCMC; prior sensitivity for very weak mediators |\n| Two-step MR \u002F network MR (Burgess 2015 IJE 44:484) | IV-based at each step with INDEPENDENT instruments | Implicit (no interaction modeling) | One mediator at a time | Large summary-stat samples | Same SNP used for E and M (violates exclusion); horizontal pleiotropy; Steiger reversal of M->E direction |\n| MVMR-mediation (Carter & Sanderson 2021 Eur J Epidemiol 36:465-478) | Total minus direct via MVMR | Implicit | Single mediator | Large GWAS samples for both E and M | Conditional F \u003C 10 for either exposure; correlated instruments |\n| medDML (Farbmacher 2022 Econometrics J 25:277) | Double-debiased ML, doubly-robust | Limited (depends on learner) | Moderate (sparsity-friendly) | ~500 | Severe overlap violations; cross-fitting variance with small n |\n\nMethodology evolves; verify against the current CMAverse vignette and the Steen \u002F Vansteelandt natural-effects-model literature before locking analytic choices. Difference-in-coefficients and product-of-coefficients give identical estimates in fully linear-Gaussian models but DIVERGE for any non-linear outcome model (logistic, Cox, Poisson); the counterfactual ACME from `mediation::mediate()` is the correct quantity for non-linear outcomes.\n\n## 4-Way Decomposition Framework\n\nVanderWeele 4-way explicitly separates effects from exposure-mediator interaction:\n\n```\nTotal Effect = CDE + INTref + INTmed + PIE\n```\n\n| Component | Meaning | Active when |\n|-----------|---------|-------------|\n| CDE | Controlled direct effect (with mediator fixed at reference level) | E directly affects Y |\n| INTref | Interaction-reference -- needs interaction AND exposure | E*M interaction with mediator at reference |\n| INTmed | Mediated interaction -- needs interaction AND exposure AND mediation | E shifts M which then interacts with E |\n| PIE | Pure indirect effect (older \"mediation\" quantity) | E shifts M which shifts Y additively |\n\nWithout an exposure-mediator interaction term, INTref = INTmed = 0 and the decomposition collapses to CDE + PIE (= ADE + ACME). With interaction present, traditional ACME mixes PIE and INTmed; the 4-way separation is the only framework that disentangles them. Most epidemiology applications include the interaction term and report all four components (Valeri & VanderWeele 2013 Psychol Methods).\n\n## Decision Tree by Scenario\n\n| Scenario | Recommended pipeline |\n|----------|---------------------|\n| Observational, single measured mediator, no plausible E-M interaction, continuous outcome | `mediation::mediate()` with `boot=TRUE, sims=5000`; always run `medsens()` |\n| Observational, single mediator, suspected E-M interaction, any outcome family | `CMAverse::cmest(..., EMint=TRUE)` -> read CDE, PIE, INTref, INTmed |\n| Observational, BINARY outcome, rare disease (\u003C 10%) | `cmest(yreg='logistic', EMint=TRUE, casecontrol=FALSE)` -- OR-based 4-way decomposition is valid under rare-disease |\n| Observational, survival outcome | `cmest(yreg='coxph')` OR `HIMA::hima_cox` for high-D; report HRs |\n| High-D mediators (EWAS, transcriptome-wide), continuous outcome | `HIMA::hima(formula, data.pheno, data.M, mediator.type='gaussian', penalty='DBlasso')`; report `sigcut` (FDR threshold, default 0.05) |\n| High-D mediators with latent confounding (very-high-D EWAS) | `HILAMA` (2025) |\n| High-D mediators with Bayesian shrinkage (small n, ~5k features) | `bama::bama()` |\n| Strong genetic IVs for exposure available, single mediator with own IVs | Two-step MR with independent instruments + Steiger filter on mediator |\n| Both E and M have IVs but instruments are weak \u002F correlated | MVMR-mediation with conditional F > 10 each |\n| Observational with rich confounder set, want doubly-robust estimate | `causalweight::medDML` (double-debiased ML) |\n| Longitudinal with time-varying confounding | g-formula via `CMAverse::cmest(estimation='gformula')` OR `gfoRmula` package |\n| Exposure-induced confounder of M-Y exists | Interventional indirect effects (Vansteelandt & Daniel 2017); `CMAverse::cmest(estimation='msm')` |\n\n## Sequential Ignorability and Why It Always Needs Sensitivity\n\nObservational mediation requires three no-unmeasured-confounding assumptions. The third (M-Y unmeasured confounder, after conditioning on E) is the most common violator in genomic mediation because biological confounders (cell composition, batch effects, technical mediators) frequently affect both M and Y.\n\n### Sequential ignorability untestable\n\n**Trigger:** Always, by design.\n\n**Mechanism:** No statistical test can detect an unmeasured confounder of M-Y. Bootstrap CIs assume the assumption holds; they do NOT propagate uncertainty about it.\n\n**Symptom:** Significant ACME with no sensitivity reported -> reviewer rejects.\n\n**Fix:** Report at least one of:\n- Imai's rho sensitivity: `medsens(med_result, rho.by=0.05, sims=1000)`; the critical rho where ACME crosses 0; |rho_crit| > 0.3 is \"reasonably robust\" (Imai 2010), |rho_crit| \u003C 0.1 is highly sensitive.\n- Mediational E-value (Smith & VanderWeele 2019 Epidemiology 30:835): minimum risk-ratio strength of an unmeasured confounder needed to nullify the observed indirect effect; computed via `EValue::evalues.OLS()` for linear outcomes or by-hand from ACME risk ratio bounds.\n- Reporting BOTH rho-based and E-value sensitivity is standard for high-stakes claims.\n\n### Methods-Section Defense of Sequential Ignorability\n\nTemplate sentence for the methods write-up: \"We assumed sequential ignorability conditional on {age, sex, ancestry PCs, cell composition, batch, smoking}. Robustness was assessed via Imai rho_crit at the ACME contrast (`medsens`, sims = 1000) and the mediational E-value on the risk-ratio scale (Smith & VanderWeele 2019 Epidemiology 30:835).\"\n\nQuantitative interpretation thresholds:\n- rho_crit: |rho_crit| > 0.3 robust; 0.1-0.3 moderately sensitive; \u003C 0.1 highly sensitive (Imai 2010).\n- E-value: E > 2 robust to plausible biological confounding; 1.5-2 moderate; \u003C 1.5 fragile (Smith & VanderWeele 2019).\n\nFor high-stakes claims (clinical, drug-target, regulatory submissions) report BOTH rho_crit and the mediational E-value; for exploratory work either alone suffices.\n\n### Exposure-induced M-Y confounder\n\n**Trigger:** A covariate L sits between E and Y, AND is affected by E, AND confounds M-Y.\n\n**Mechanism:** Standard regression-based mediation cannot adjust for L without blocking part of the indirect effect (collider stratification bias). Adjusting biases CDE; not adjusting biases ACME.\n\n**Symptom:** Sensitivity to confounder set; ACME flips sign when L is added vs removed.\n\n**Operational identification:** From the DAG, L is a covariate of M and Y that is also affected by E. VanderWeele TJ, Vansteelandt S & Robins JM 2014 (Epidemiology 25:300) give the criterion: if L is adjusted, part of the indirect E -> L -> M -> Y pathway is blocked; if L is not adjusted, L confounds the M-Y leg. Both are wrong under natural-effects; the natural indirect effect is simply not identified.\n\n**Fix:** Switch to **interventional indirect effects** (Vansteelandt & Daniel 2017 Epidemiology 28:258), NOT natural indirect effects. Use `CMAverse::cmest(estimation='msm')` with stabilized inverse-probability weights (yields the randomized-interventional analogue), `gfoRmula` (parametric g-formula), or randomized\u002Finterventional indirect effects (Lin SH & VanderWeele TJ 2017 J Causal Inference 5:20150027). The interventional indirect is identified under weaker assumptions than the natural indirect.\n\n### HIMA covariate or data.pheno error\n\n**Trigger:** `data.pheno` contains factor columns with NA, or formula references columns missing from `data.pheno`.\n\n**Mechanism:** HIMA v2.3+ uses a formula interface and constructs the design matrix internally from `data.pheno`; missing values or unparseable formulas surface as cryptic `glmnet` errors.\n\n**Symptom:** Pipeline fails inside `hima()` with a non-obvious `storage.mode` or `model.matrix` error.\n\n**Fix:** Pre-clean `data.pheno` (drop NA rows for the variables in the formula; convert factors with `factor()`; ensure all RHS variables exist as columns). Example:\n```r\ndat \u003C- na.omit(dat[, c('outcome', 'exposure', 'age', 'sex', 'batch', 'pc1', 'pc2')])\ndat$batch \u003C- factor(dat$batch)\nresult \u003C- hima(outcome ~ exposure + age + sex + batch + pc1 + pc2,\n               data.pheno=dat, data.M=M_matrix, mediator.type='gaussian')\n```\n\n### HIMA mediator-type vs outcome-type mismatch\n\n**Trigger:** Survival outcome (`Surv()` on LHS) with `mediator.type='compositional'` chosen against text mediator panel; or count mediators passed as `'gaussian'`.\n\n**Mechanism:** HIMA v2.3+ auto-detects outcome family from the LHS of `formula` (continuous, binary, survival, count); `mediator.type` is set for the mediator data only (`'gaussian'`, `'negbin'`, `'compositional'`). Mismatching mediator-type to the actual mediator distribution biases the screening step.\n\n**Symptom:** Hazard \u002F rate ratios for indirect effects look implausible; many \"significant\" mediators fail replication.\n\n**Fix:** Set `mediator.type='gaussian'` for continuous (e.g., methylation beta, log-CPM expression), `'negbin'` for raw count (RNA-seq), `'compositional'` for relative-abundance microbiome. Verify by `?hima` in the installed version since the catalogue of mediator types has expanded across releases.\n\n### Bootstrap iterations too low\n\n**Trigger:** `sims=100` or `sims=500` in early exploration left in for the final report.\n\n**Mechanism:** ACME CIs from bootstrap have Monte-Carlo error that scales as 1\u002Fsqrt(sims); at sims=500 the 95% CI bounds have ~5% MC noise, enough to flip the conclusion at the boundary.\n\n**Symptom:** Re-running `mediate()` with a different `set.seed()` gives substantially different CI bounds.\n\n**Fix:** `sims=1000` minimum for any reported result; `sims=5000` for publication; `sims=10000` if proximity to zero matters. BCa CIs (`boot.ci.type='bca'` in `mediate()`) are slightly more accurate than percentile CIs near zero but require more sims for stability.\n\n### Two-step MR instrument independence\n\n**Trigger:** Same set of SNPs used as instruments for E in step 1 and for M in step 2.\n\n**Mechanism:** If a SNP affects both E and M, the M-instrument violates exclusion restriction (the SNP-Y association is not exclusively through M). Estimates are biased toward the direct effect.\n\n**Symptom:** Two-step MR shows large indirect effect; replacing M-instruments with non-overlapping SNPs makes it vanish.\n\n**Fix:** Apply Steiger filter on the mediator: keep only SNPs where the SNP-M F-statistic exceeds SNP-E F-statistic (or where SNP explains more variance in M than E). For MVMR-mediation, require conditional F > 10 for each exposure independently (Sanderson 2019 IJE 48:713).\n\n### Difference vs product of coefficients diverge for non-linear outcomes\n\n**Trigger:** Binary or survival outcome modeled with logistic \u002F Cox.\n\n**Mechanism:** Difference = total - direct; product = alpha * beta. Equivalent under linear-Gaussian; diverge under any link function. Counterfactual ACME from `mediation::mediate()` is the correct quantity; hand-computed product-of-coefficients on logistic output is biased except under rare-disease.\n\n**Fix:** Report only counterfactual ACME (Imai or CMAverse). For OR-based 4-way decomposition on rare outcomes (\u003C= 10%), Valeri & VanderWeele 2013 formulas apply; for common outcomes use risk-ratio scale or marginal effects rather than ORs.\n\n### Required Reporting for Publication\n\n| Component | Required |\n|-----------|----------|\n| ACME estimate + 95% CI (BCa preferred) | Yes |\n| ADE + 95% CI | Yes |\n| Total effect | Yes |\n| Proportion mediated | Yes when total > effect-size threshold |\n| Bootstrap method + sims | percentile \u002F BCa; min 1000, recommend 5000 |\n| Sequential ignorability sensitivity | rho_crit (medsens) OR mediational E-value |\n| Exposure-mediator interaction test | Coefficient + p; 4-way decomposition if significant |\n| Confounder set justification | DAG description |\n| Mediator measurement reliability | Cite |\n| Sample size + missing-data handling | Yes |\n| Mediator \u002F exposure scale | Standardized? log? raw? |\n\nReference: AGReMA guideline (Lee H et al 2021 JAMA 326:1045) and MacKinnon 2008 Introduction to Statistical Mediation Analysis.\n\n## Reconciliation: Observational vs MR Mediation\n\n| Pattern | Likely cause | Action |\n|---------|--------------|--------|\n| Observational ACME significant; MR-mediation null | Unmeasured M-Y confounding inflated observational estimate; OR weak IVs in MR | Re-run observational with `medsens()`; if rho_crit \u003C 0.1, trust MR null |\n| Observational ACME null; MR-mediation significant | Measurement error in M attenuated observational estimate | Trust MR (regression-dilution-free) IF instruments pass Steiger and pleiotropy tests (MR-Egger intercept, MR-PRESSO) |\n| Both significant with same sign | Convergent evidence | High-confidence mediation; report effect size from the more-conservative estimate |\n| Both significant with opposite signs | At least one is biased; revisit confounder structure and IV assumptions | Do not pool; investigate via cross-method sensitivity |\n\n**Operational rule for high-stakes claims (clinical \u002F drug-target mediation):** Require (1) significant observational ACME, (2) Imai rho_crit > 0.2 OR mediational E-value > 1.5, (3) directionally consistent MR-mediation result OR documented absence of valid instruments. Single-method mediation claims should be reported as exploratory.\n\n## Anticipated Reviewer Pushback\n\n| Pushback | Standard response |\n|----------|-------------------|\n| \"Sequential ignorability?\" | Imai rho_crit reported via `medsens`; mediational E-value reported on the risk-ratio scale |\n| \"Exposure-induced confounder of M-Y?\" | DAG drawn; if L present, switch to `CMAverse::cmest(estimation='msm')` for interventional indirect effect (Vansteelandt & Daniel 2017) |\n| \"Why this bootstrap method?\" | BCa with sims=5000 for publication; percentile fallback when BCa fails to converge (acceleration estimate unstable at boundary) |\n| \"Why was MR-mediation not done?\" | If valid IVs for E and M exist: two-step MR or MVMR-mediation done (see code below); if not, documented absence of trans-instruments |\n| \"Mediator measured with error?\" | Regression calibration (Carroll 2006 Measurement Error in Nonlinear Models) OR sensitivity analysis assuming reliability r = 0.7 (Valeri & VanderWeele 2014) |\n| \"Why HIMA2 not BAMA?\" | HIMA2 = frequentist + FDR control + faster; BAMA = Bayesian when prior information is available; sample-size justification given against simulation rule-of-thumb |\n| \"Proportion mediated unstable?\" | When |total| \u003C 2*SE(total), proportion-mediated CI is unreliable (denominator near zero); report indirect effect alone with absolute effect size |\n\n## Quantitative Thresholds\n\n| Quantity | Threshold | Source \u002F Rationale |\n|----------|-----------|--------------------|\n| `sims` (bootstrap iterations) | >= 1000 exploratory, >= 5000 publication | Imai 2010; MC error scales 1\u002Fsqrt(sims) |\n| Proportion mediated -- meaningful | > 0.2 | Convention; weak guideline only -- effect size in absolute terms matters more (MacKinnon 2008) |\n| Proportion mediated -- \"most of the effect\" | > 0.5-0.8 | Convention |\n| Imai rho_crit -- robust | > 0.3 | Imai 2010 Psychol Methods 15:309 |\n| Imai rho_crit -- sensitive | \u003C 0.1 | Same |\n| Mediational E-value -- robust | > 2.0 (working convention; the original Smith & VanderWeele 2019 E-value framework does not prescribe a specific cutoff -- magnitude is context-dependent) | Smith & VanderWeele 2019 Epidemiology 30:835 |\n| HIMA FDR cutoff | BH FDR \u003C 0.05 | Default; report q-values not raw p |\n| MVMR conditional F per exposure | > 10 each | Sanderson 2019 IJE 48:713 |\n| Two-step MR -- F for both stages | > 10 each | Burgess weak-instrument convention |\n| Sample size -- single-mediator (Imai) | >= 200 for stable bootstrap | Simulation rule-of-thumb |\n| Sample size -- HIMA EWAS | >= 150 with p_mediators up to ~10k | Zhang 2016 simulations |\n| Rare-outcome cutoff for OR-based 4-way | outcome prevalence \u003C= 10% | Valeri & VanderWeele 2013 |\n\n## Working Code Patterns\n\n### Single-Mediator Observational with Sensitivity\n\n**Goal:** Decompose a genotype-disease effect via measured molecular mediator with explicit sensitivity to unmeasured M-Y confounding.\n\n**Approach:** Fit mediator and outcome models, bootstrap ACME\u002FADE, run `medsens()` for Imai rho-based sensitivity.\n\n```r\nlibrary(mediation)\n\nmed_model \u003C- lm(expression ~ genotype + age + sex + pc1 + pc2 + pc3, data=dat)\nout_model \u003C- glm(disease ~ genotype + expression + age + sex + pc1 + pc2 + pc3,\n                 data=dat, family=binomial)\n\nmed_result \u003C- mediate(med_model, out_model,\n                      treat='genotype', mediator='expression',\n                      boot=TRUE, sims=5000, boot.ci.type='bca')\nsummary(med_result)\n\nsens \u003C- medsens(med_result, rho.by=0.05, effect.type='indirect', sims=1000)\nsummary(sens)\n```\n\n`d0`, `z0`, `n0`, `tau.coef` slots return ACME, ADE, proportion mediated, total effect.\n\n### 4-Way Decomposition with Exposure-Mediator Interaction\n\n**Goal:** Separate CDE, PIE, INTref, INTmed when exposure-mediator interaction is biologically plausible (e.g., gene-environment interaction modifying mediator effect).\n\n**Approach:** Use CMAverse regression-based estimator with `EMint=TRUE`; bootstrap CIs.\n\n```r\nlibrary(CMAverse)\n\nresult_4way \u003C- cmest(\n  data=dat, model='rb',\n  outcome='disease', exposure='genotype', mediator='expression',\n  basec=c('age','sex','pc1','pc2'),\n  EMint=TRUE,\n  mreg=list('linear'), yreg='logistic',\n  astar=0, a=1, mval=list(0),\n  estimation='paramfunc', inference='bootstrap', nboot=1000\n)\nsummary(result_4way)\n```\n\nCMAverse reports the 4-way decomposition (Vanderweele 2014): for continuous outcomes the components are `cde`, `intref`, `intmed`, `pnie` (or `pie`), `te`, `pm`; for non-continuous outcomes (logistic \u002F Cox \u002F Poisson) the ratio versions `Rcde`, `Rpnde`, `Rtnde`, `Rpnie`, `Rtnie` are reported. When `EMint=TRUE`, additional proportion-attributable-to-interaction terms (`int`, `pe`) are included. Verify column names with `summary(result)$results` in the installed CMAverse version, since naming has evolved.\n\n### High-Dimensional EWAS Mediation (HIMA2)\n\n**Goal:** Among thousands of candidate CpG mediators, identify those mediating an exposure-outcome effect with FDR control.\n\n**Approach:** HIMA v2.3+ uses a formula interface and auto-detects outcome family (Gaussian \u002F binomial \u002F Cox \u002F Poisson). Screening + MCP\u002FDBlasso penalisation + joint significance with BH; the `sigcut` argument controls the FDR threshold (default 0.05).\n\n```r\nlibrary(HIMA)\n\ndat \u003C- na.omit(dat[, c('outcome', 'exposure', 'age', 'sex', 'cell_pc1', 'cell_pc2')])\nM_matrix \u003C- as.matrix(beta_values)\n\nresult \u003C- hima(\n  outcome ~ exposure + age + sex + cell_pc1 + cell_pc2,\n  data.pheno=dat,\n  data.M=M_matrix,\n  mediator.type='gaussian',          # 'negbin' for count, 'compositional' for microbiome\n  penalty='DBlasso',                  # default; alternatives 'MCP', 'SCAD', 'lasso'\n  scale=TRUE,\n  sigcut=0.05,\n  parallel=TRUE, ncore=8, verbose=TRUE\n)\n# result is a data.frame of significant mediators below sigcut\n```\n\nFor survival outcomes wrap the LHS as `Surv(time, status)`; HIMA auto-routes to Cox. The old `hima_classic()` (Zhang 2016 original) is still exported but screens by beta only and misses mediators with strong alpha + weak beta -- prefer the wrapper `hima()` unless reproducing a 2016-2021 paper.\n\nFor highly-correlated mediators (CpG-island clusters, gene-module co-expression): HIMA uses joint significance with BH-FDR on max(p_alpha, p_beta) and handles correlation only weakly. Within `hima()`, set `penalty='MCP'` for stronger correlation handling; alternatively pre-reduce the mediator panel by principal components or by clustering correlated mediators and screening the cluster centroid (VanderWeele & Vansteelandt 2014 Epidemiol Methods 2:95).\n\n### Time-Varying Mediation Methods\n\nWhen the mediator is measured at multiple timepoints (or exposure varies over time), natural-effects estimands are not identified; switch to one of:\n\n- g-formula (parametric or Monte Carlo): `gfoRmula::gformula_continuous_eof()`; `CMAverse::cmest(estimation='gformula')`\n- g-estimation of a structural nested mean model: `gesttools::gestSingle()` \u002F `gestMultiple()`\n- Marginal structural model with stabilized IPTW: `ipw::ipwtm()` followed by `glm(..., weights=sw)`\n- Sequential mediation for K timepoints: VanderWeele & Tchetgen Tchetgen 2017 JRSSB 79:917\n\nChoose based on the experimental structure:\n- >= 3 timepoints required for g-methods to identify time-varying indirect effects\n- Longitudinal mediator measurement at EACH timepoint is required (not just baseline)\n- MSM is preferred when treatment is binary and time-varying; g-formula when continuous\n- Sequential mediation when the causal ordering of multiple mediators is known and stable across time\n\n### MR-Mediation: Two-Step vs MVMR-Mediation\n\nDecision tree:\n- Independent instrument sets available for E and M -> two-step MR (Burgess 2015 IJE 44:484)\n- E and M share instruments (common in cis-eQTL \u002F cis-pQTL mediator cases) -> MVMR-mediation (Carter & Sanderson 2021 Eur J Epidemiol 36:465)\n- Both feasible -> report both (triangulation)\n\nTwo-step code sketch:\n\n```r\nlibrary(TwoSampleMR)\nexp_E \u003C- extract_instruments('ieu-a-2', clump=TRUE)\nm_E \u003C- extract_outcome_data(exp_E$SNP, 'ieu-b-30')\ndat_EM \u003C- harmonise_data(exp_E, m_E)\nmr_EM \u003C- mr(dat_EM)\n\nexp_M \u003C- extract_instruments('ieu-b-30', clump=TRUE)\nexp_M_indep \u003C- exp_M[!exp_M$SNP %in% exp_E$SNP, ]\nexp_M_indep \u003C- steiger_filtering(exp_M_indep)\nout_M \u003C- extract_outcome_data(exp_M_indep$SNP, 'ieu-a-7')\ndat_MY \u003C- harmonise_data(exp_M_indep, out_M)\nmr_MY \u003C- mr(dat_MY)\n```\n\nIndirect effect = beta_EM * beta_MY (product of coefficients). CI via delta method or parametric bootstrap of the joint (beta_EM, beta_MY) distribution. Steiger filter on M-instruments is mandatory to ensure the M -> Y direction (not Y -> M).\n\n### MR-Mediation: Total Minus Direct via MVMR\n\n**Goal:** Estimate the proportion of a genetic-instrument-identified causal effect that flows through a mediator, using independent IVs for E and (E + M).\n\n**Approach:** Univariable MR for total E->Y; MVMR for direct E->Y conditional on M; indirect = total - direct via delta-method CI.\n\n```r\nlibrary(TwoSampleMR); library(MVMR)\n\ntotal \u003C- mr_ivw(beta_E, beta_Y, se_E, se_Y)\nmvmr_dat \u003C- format_mvmr(BXGs=cbind(beta_E, beta_M),\n                        BYG=beta_Y, seBXGs=cbind(se_E, se_M), seBYG=se_Y, RSID=snps)\nfstat \u003C- strength_mvmr(mvmr_dat, gencov=0)\nmvmr_fit \u003C- ivw_mvmr(mvmr_dat)\ndirect \u003C- mvmr_fit[1, 'Estimate']\ndirect_se \u003C- mvmr_fit[1, 'Std. Error']\n\nindirect \u003C- total$b - direct\nindirect_se \u003C- sqrt(total$se^2 + direct_se^2)\nindirect_ci \u003C- indirect + c(-1.96, 1.96) * indirect_se\n```\n\nRequire `fstat` conditional F > 10 for both E and M independently. If `fstat \u003C 10`, use Q-statistic-adjusted IVW (`qhet_mvmr`) or report the result as weak-instrument-limited.\n\n### Double-ML Doubly-Robust Mediation\n\n**Goal:** Avoid model misspecification of both mediator and outcome models via cross-fitted ML nuisance estimators.\n\n**Approach:** `causalweight::medDML` uses random forests (or other learners) with sample splitting to estimate nuisance parameters; final estimator is doubly robust.\n\n```r\nlibrary(causalweight)\n\nresult_dml \u003C- medDML(\n  y=dat$outcome, d=dat$treatment, m=dat$mediator,\n  x=as.matrix(dat[, covariates]),\n  trim=0.05, order=1\n)\n```\n\nReports direct, indirect (via mediator), and total effects with influence-function-based standard errors. Robust to non-linearity and interactions; assumes sequential ignorability still.\n\n### Mediational E-Value for Sensitivity\n\n**Goal:** Report the minimum strength of an unmeasured M-Y confounder required to nullify the observed indirect effect.\n\n**Approach:** Convert ACME and its CI to a risk-ratio scale, then apply VanderWeele E-value formula.\n\n```r\nlibrary(EValue)\n\nacme_rr \u003C- exp(med_result$d0)\nacme_lower_rr \u003C- exp(med_result$d0.ci[1])\nevalues.RR(acme_rr, lo=acme_lower_rr, hi=NULL)\n```\n\nFor binary outcomes, convert ACME on probability scale to RR; for continuous, use `evalues.OLS()` with the standardized indirect effect. E-value > 2 indicates a confounder would need >2-fold associations with both M and Y to nullify the indirect effect (Smith & VanderWeele 2019).\n\n## Tool Install Notes\n\n| Package | Source | Notes |\n|---------|--------|-------|\n| mediation | CRAN | `install.packages('mediation')`; actively maintained (Imai group) |\n| CMAverse | GitHub | `remotes::install_github('BS1125\u002FCMAverse')`; NOT on CRAN; 6 estimators in one interface |\n| HIMA | GitHub | `remotes::install_github('YinanZheng\u002FHIMA')`; archived from CRAN 2026-07 (needs archived `scalreg`); v2.x renamed `hima()` to HIMA2 -- verify with `?hima` |\n| bama | CRAN | `install.packages('bama')`; Bayesian; slow MCMC |\n| causalweight | CRAN | `install.packages('causalweight')`; medDML for double-ML mediation |\n| EValue | CRAN | `install.packages('EValue')`; for mediational E-values |\n| TwoSampleMR | r-universe | See causal-genomics\u002Fmendelian-randomization for setup |\n| MVMR | r-universe | `remotes::install_github('WSpiller\u002FMVMR')`; for MVMR-mediation |\n| gfoRmula | CRAN | For longitudinal \u002F time-varying confounders |\n\n## Common Errors\n\n| Error \u002F symptom | Cause | Solution |\n|-----------------|-------|----------|\n| `Error in storage.mode(x) \u003C- \"double\"` inside `hima()` | NA in `data.pheno` columns referenced by formula, or unconverted factors | `na.omit(data.pheno)` first; ensure all RHS vars in formula are numeric or factor |\n| ACME significant, ADE significant, total NOT significant | Suppression \u002F inconsistent mediation | Report transparently; effect partitioning can exceed total in suppression |\n| `medsens()` errors on glm outcome | `medsens` requires linear OR probit (not logit) outcome | Refit outcome as `glm(..., family=binomial(link='probit'))` |\n| `mediate()` runs forever with binary outcome | `sims=5000` with bootstrap and small n | Use `sims=1000` exploratory; verify model converges first; consider parallel via `parallel='multicore'` |\n| CMAverse `cmest()` reports NaN for `pm` | Total effect crosses zero -> proportion ill-defined | Report ACME and TE separately; pm is unstable when |TE| is small |\n| Different ACME between `mediation` and CMAverse `rb` | Default `astar\u002Fa` levels differ; binary mediator handled differently | Set `astar=0, a=1` explicitly; for binary mediator pass `mval=list(0)` |\n| HIMA returns zero significant mediators | Screening too aggressive; or no true mediators | Try `topN=2*sqrt(n)` instead of default; verify with permutation null |\n| Two-step MR shows indirect > total | Steiger reversal: M actually causes E; or pleiotropic SNPs | Run MR-Steiger filter; use MR-PRESSO for pleiotropy |\n| `medDML` trim removes most data | Severe positivity violation -- few units with overlapping treatment\u002Fmediator distributions | Tighten covariate set; check propensity score distributions |\n\n## References\n\n- Baron RM, Kenny DA 1986 J Pers Soc Psychol 51:1173 (original product-of-coefficients)\n- Imai K, Keele L, Tingley D 2010 Psychol Methods 15:309 (counterfactual mediation, sequential ignorability)\n- VanderWeele TJ 2014 Epidemiology 25:749 (4-way decomposition)\n- VanderWeele TJ 2015 Explanation in Causal Inference (OUP) -- canonical textbook\n- Valeri L, VanderWeele TJ 2013 Psychol Methods 18:137 (binary outcomes; rare-disease 4-way)\n- Vansteelandt S, Daniel RM 2017 Epidemiology 28:258 (interventional \u002F randomized indirect effects)\n- Shi B et al 2021 Epidemiology 32:e20 (CMAverse package; 6 estimators)\n- Zhang H et al 2016 Bioinformatics 32:3150 (HIMA original)\n- Perera C et al 2022 BMC Bioinformatics 23:296 (HIMA2 alpha-beta screening)\n- Song Y et al 2020 Biometrics 76:700 (BAMA Bayesian high-D mediation)\n- Burgess S et al 2015 IJE 44:484 (network \u002F two-step MR)\n- Sanderson E et al 2019 IJE 48:713 (MVMR conditional F-statistic)\n- Carter AR & Sanderson E 2021 Eur J Epidemiol 36:465 (MVMR-mediation)\n- Farbmacher H et al 2022 Econometrics J 25:277 (medDML \u002F double-ML mediation)\n- Smith LH, VanderWeele TJ 2019 Epidemiology 30:835 (mediational E-value)\n\n## Related Skills\n\n- causal-genomics\u002Fmendelian-randomization - IV-based causal inference; foundation for MR-mediation\n- causal-genomics\u002Fpleiotropy-detection - MR-mediation instrument validity hinges on pleiotropy diagnostics (MR-Egger intercept, MR-PRESSO)\n- causal-genomics\u002Fcolocalization-analysis - Confirm shared causal variant before causal mediation\n- causal-genomics\u002Ffine-mapping - Identify the causal variant driving the exposure\n- methylation-analysis\u002Fdifferential-cpg-testing - Per-CpG inputs for HIMA EWAS mediation\n- differential-expression\u002Fdeseq2-basics - Expression inputs for eQTL mediation\n- multi-omics-integration\u002Fmofa-integration - Multi-layer mediator construction\n- population-genetics\u002Fassociation-testing - GWAS summary statistics for MR-mediation\n- clinical-biostatistics\u002Feffect-measures - Risk-ratio \u002F odds-ratio scales for binary outcomes\n- machine-learning\u002Fmodel-validation - Cross-fitting and sample splitting for medDML\n","## Version Compatibility\n\nReference examples tested with: R 4.3+, mediation 4.5.0+, CMAverse 0.1.0+ (GitHub `BS1125\u002FCMAverse`), HIMA >= 2.3.0 (GitHub `YinanZheng\u002FHIMA`; archived from CRAN 2026-07), bama 1.3+, causalweight 1.0.5+ (medDML), MVMR 0.4+, TwoSampleMR 0.6+, EValue 4.1+, gesttools 1.3+, ipw 1.0.11+.\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- R: `packageVersion('\u003Cpkg>')` then `?function_name` to verify parameters\n- HIMA must be pinned at `>= 2.3.0` for the code patterns below; the formula interface `hima(formula, data.pheno, data.M, mediator.type, penalty, ...)` was introduced in 2.3.0. On HIMA 2.2.x the classic engine is the top-level `hima(X, Y, M, COV.XM=, COV.MY=, Y.family=, penalty=)` (positional order X, Y, M) with no formula interface; HIMA 2.2.x is NOT API-compatible with the examples here.\n- In 2.3+ the classic engine is `hima_classic(X, M, Y, COV.XM=, COV.MY=, Y.type=)` (positional order X, M, Y; outcome type via `Y.type`, not `Y.family`); use it only to reproduce the original 2016-2021 SIS+penalty pipelines.\n\nIf code throws an error, introspect the installed package (`?hima`, `args(cmest)`) and adapt the example to match the actual API rather than retrying.\n\n# Mediation Analysis\n\n**\"Does expression of GENE_X mediate the SNP-to-disease effect?\"** -> Decompose the total effect of a treatment (genotype, exposure) on an outcome into direct and indirect paths through one or more mediators, with explicit handling of exposure-mediator interaction, sensitivity to unmeasured confounding, and high-dimensional mediator screening.\n\n- R (single-mediator, observational, sequential-ignorability assumed): `mediation::mediate(med_model, out_model, treat='X', mediator='M', boot=TRUE, sims=5000)`\n- R (4-way decomposition with exposure-mediator interaction): `CMAverse::cmest(...EMint=TRUE, estimation='paramfunc', inference='bootstrap', nboot=1000)`\n- R (high-dimensional \u002F EWAS mediators): `HIMA::hima(Y ~ X + covariates, data.pheno, data.M, mediator.type='gaussian', penalty='DBlasso')` (modern v2.3+ formula interface)\n- R (MR-based mediation): two-step `TwoSampleMR` with independent instruments OR `MVMR::ivw_mvmr` for joint direct effect\n- R (doubly-robust double-ML): `causalweight::medDML(y, d, m, x)`\n\nSequential ignorability (no unmeasured confounder of treatment-mediator, mediator-outcome, treatment-outcome) is the single load-bearing assumption of observational mediation and is fundamentally untestable. Every report should include a sensitivity result (Imai's rho via `medsens()` or a mediational E-value).\n\n## Algorithmic Taxonomy\n\n| Method | Framework | Handles E-M interaction | High-D mediators | Min n | Fails when |\n|--------|-----------|--------------------------|------------------|-------|------------|\n| Baron-Kenny (1986) | Additive regression-based product\u002Fdifference | No | No | ~100 | Any non-linearity, interaction, or binary outcome; deprecated for causal inference |\n| Imai mediation R (Imai 2010 Psychol Methods) | Counterfactual ACME\u002FADE with bootstrap | Yes (via interaction term in outcome model) | No | ~200 | Sequential ignorability violated; exposure-induced M-Y confounder; rare binary outcome with logistic outcome model |\n| VanderWeele 4-way (VanderWeele 2014 Epidemiology 25:749; 2015 OUP) | CDE + PIE + INTref + INTmed decomposition | Native | No | ~300 | Without interaction term reduces to standard mediation; binary outcome needs rare-disease assumption |\n| CMAverse (Shi 2021 Epidemiology 32:e20) | 6 estimators: regression (`rb`), weighting (`wb`), IORW (`iorw`), natural effect models (`ne`), MSM (`msm`), g-formula (`gformula`) | Yes | No (single M, or M-vector) | ~300 | Estimator-specific; `wb` fails with rare exposure; `msm` needs censoring weights for survival |\n| HIMA1 \u002F hima_classic (Zhang 2016 Bioinformatics 32:3150) | SIS screen by beta (M->Y) + MCP penalty | No | Yes (up to ~10k) | ~150 + p>>n | Misses mediators with strong alpha and weak beta; screening-step false-negatives |\n| HIMA2 \u002F hima (Perera 2022 BMC Bioinformatics 23:296) | SIS screen by alpha*beta (indirect effect) + de-biased Lasso (DBlasso) | No (linear by default) | Yes | ~150 | Outcome family limited (gaussian\u002Fbinomial); HIMA-Cox for survival; HIMA-Pois for count |\n| HILAMA (Wang et al 2025) | High-D mediation with latent confounders | No | Yes (>= 100k) | ~500 | Newer; benchmarks evolving; requires latent-factor specification |\n| BAMA (Song 2020 Biometrics) | Bayesian high-D continuous shrinkage | No | Yes (~5k) | ~200 | Slow MCMC; prior sensitivity for very weak mediators |\n| Two-step MR \u002F network MR (Burgess 2015 IJE 44:484) | IV-based at each step with INDEPENDENT instruments | Implicit (no interaction modeling) | One mediator at a time | Large summary-stat samples | Same SNP used for E and M (violates exclusion); horizontal pleiotropy; Steiger reversal of M->E direction |\n| MVMR-mediation (Carter & Sanderson 2021 Eur J Epidemiol 36:465-478) | Total minus direct via MVMR | Implicit | Single mediator | Large GWAS samples for both E and M | Conditional F \u003C 10 for either exposure; correlated instruments |\n| medDML (Farbmacher 2022 Econometrics J 25:277) | Double-debiased ML, doubly-robust | Limited (depends on learner) | Moderate (sparsity-friendly) | ~500 | Severe overlap violations; cross-fitting variance with small n |\n\nMethodology evolves; verify against the current CMAverse vignette and the Steen \u002F Vansteelandt natural-effects-model literature before locking analytic choices. Difference-in-coefficients and product-of-coefficients give identical estimates in fully linear-Gaussian models but DIVERGE for any non-linear outcome model (logistic, Cox, Poisson); the counterfactual ACME from `mediation::mediate()` is the correct quantity for non-linear outcomes.\n\n## 4-Way Decomposition Framework\n\nVanderWeele 4-way explicitly separates effects from exposure-mediator interaction:\n\n```\nTotal Effect = CDE + INTref + INTmed + PIE\n```\n\n| Component | Meaning | Active when |\n|-----------|---------|-------------|\n| CDE | Controlled direct effect (with mediator fixed at reference level) | E directly affects Y |\n| INTref | Interaction-reference -- needs interaction AND exposure | E*M interaction with mediator at reference |\n| INTmed | Mediated interaction -- needs interaction AND exposure AND mediation | E shifts M which then interacts with E |\n| PIE | Pure indirect effect (older \"mediation\" quantity) | E shifts M which shifts Y additively |\n\nWithout an exposure-mediator interaction term, INTref = INTmed = 0 and the decomposition collapses to CDE + PIE (= ADE + ACME). With interaction present, traditional ACME mixes PIE and INTmed; the 4-way separation is the only framework that disentangles them. Most epidemiology applications include the interaction term and report all four components (Valeri & VanderWeele 2013 Psychol Methods).\n\n## Decision Tree by Scenario\n\n| Scenario | Recommended pipeline |\n|----------|---------------------|\n| Observational, single measured mediator, no plausible E-M interaction, continuous outcome | `mediation::mediate()` with `boot=TRUE, sims=5000`; always run `medsens()` |\n| Observational, single mediator, suspected E-M interaction, any outcome family | `CMAverse::cmest(..., EMint=TRUE)` -> read CDE, PIE, INTref, INTmed |\n| Observational, BINARY outcome, rare disease (\u003C 10%) | `cmest(yreg='logistic', EMint=TRUE, casecontrol=FALSE)` -- OR-based 4-way decomposition is valid under rare-disease |\n| Observational, survival outcome | `cmest(yreg='coxph')` OR `HIMA::hima_cox` for high-D; report HRs |\n| High-D mediators (EWAS, transcriptome-wide), continuous outcome | `HIMA::hima(formula, data.pheno, data.M, mediator.type='gaussian', penalty='DBlasso')`; report `sigcut` (FDR threshold, default 0.05) |\n| High-D mediators with latent confounding (very-high-D EWAS) | `HILAMA` (2025) |\n| High-D mediators with Bayesian shrinkage (small n, ~5k features) | `bama::bama()` |\n| Strong genetic IVs for exposure available, single mediator with own IVs | Two-step MR with independent instruments + Steiger filter on mediator |\n| Both E and M have IVs but instruments are weak \u002F correlated | MVMR-mediation with conditional F > 10 each |\n| Observational with rich confounder set, want doubly-robust estimate | `causalweight::medDML` (double-debiased ML) |\n| Longitudinal with time-varying confounding | g-formula via `CMAverse::cmest(estimation='gformula')` OR `gfoRmula` package |\n| Exposure-induced confounder of M-Y exists | Interventional indirect effects (Vansteelandt & Daniel 2017); `CMAverse::cmest(estimation='msm')` |\n\n## Sequential Ignorability and Why It Always Needs Sensitivity\n\nObservational mediation requires three no-unmeasured-confounding assumptions. The third (M-Y unmeasured confounder, after conditioning on E) is the most common violator in genomic mediation because biological confounders (cell composition, batch effects, technical mediators) frequently affect both M and Y.\n\n### Sequential ignorability untestable\n\n**Trigger:** Always, by design.\n\n**Mechanism:** No statistical test can detect an unmeasured confounder of M-Y. Bootstrap CIs assume the assumption holds; they do NOT propagate uncertainty about it.\n\n**Symptom:** Significant ACME with no sensitivity reported -> reviewer rejects.\n\n**Fix:** Report at least one of:\n- Imai's rho sensitivity: `medsens(med_result, rho.by=0.05, sims=1000)`; the critical rho where ACME crosses 0; |rho_crit| > 0.3 is \"reasonably robust\" (Imai 2010), |rho_crit| \u003C 0.1 is highly sensitive.\n- Mediational E-value (Smith & VanderWeele 2019 Epidemiology 30:835): minimum risk-ratio strength of an unmeasured confounder needed to nullify the observed indirect effect; computed via `EValue::evalues.OLS()` for linear outcomes or by-hand from ACME risk ratio bounds.\n- Reporting BOTH rho-based and E-value sensitivity is standard for high-stakes claims.\n\n### Methods-Section Defense of Sequential Ignorability\n\nTemplate sentence for the methods write-up: \"We assumed sequential ignorability conditional on {age, sex, ancestry PCs, cell composition, batch, smoking}. Robustness was assessed via Imai rho_crit at the ACME contrast (`medsens`, sims = 1000) and the mediational E-value on the risk-ratio scale (Smith & VanderWeele 2019 Epidemiology 30:835).\"\n\nQuantitative interpretation thresholds:\n- rho_crit: |rho_crit| > 0.3 robust; 0.1-0.3 moderately sensitive; \u003C 0.1 highly sensitive (Imai 2010).\n- E-value: E > 2 robust to plausible biological confounding; 1.5-2 moderate; \u003C 1.5 fragile (Smith & VanderWeele 2019).\n\nFor high-stakes claims (clinical, drug-target, regulatory submissions) report BOTH rho_crit and the mediational E-value; for exploratory work either alone suffices.\n\n### Exposure-induced M-Y confounder\n\n**Trigger:** A covariate L sits between E and Y, AND is affected by E, AND confounds M-Y.\n\n**Mechanism:** Standard regression-based mediation cannot adjust for L without blocking part of the indirect effect (collider stratification bias). Adjusting biases CDE; not adjusting biases ACME.\n\n**Symptom:** Sensitivity to confounder set; ACME flips sign when L is added vs removed.\n\n**Operational identification:** From the DAG, L is a covariate of M and Y that is also affected by E. VanderWeele TJ, Vansteelandt S & Robins JM 2014 (Epidemiology 25:300) give the criterion: if L is adjusted, part of the indirect E -> L -> M -> Y pathway is blocked; if L is not adjusted, L confounds the M-Y leg. Both are wrong under natural-effects; the natural indirect effect is simply not identified.\n\n**Fix:** Switch to **interventional indirect effects** (Vansteelandt & Daniel 2017 Epidemiology 28:258), NOT natural indirect effects. Use `CMAverse::cmest(estimation='msm')` with stabilized inverse-probability weights (yields the randomized-interventional analogue), `gfoRmula` (parametric g-formula), or randomized\u002Finterventional indirect effects (Lin SH & VanderWeele TJ 2017 J Causal Inference 5:20150027). The interventional indirect is identified under weaker assumptions than the natural indirect.\n\n### HIMA covariate or data.pheno error\n\n**Trigger:** `data.pheno` contains factor columns with NA, or formula references columns missing from `data.pheno`.\n\n**Mechanism:** HIMA v2.3+ uses a formula interface and constructs the design matrix internally from `data.pheno`; missing values or unparseable formulas surface as cryptic `glmnet` errors.\n\n**Symptom:** Pipeline fails inside `hima()` with a non-obvious `storage.mode` or `model.matrix` error.\n\n**Fix:** Pre-clean `data.pheno` (drop NA rows for the variables in the formula; convert factors with `factor()`; ensure all RHS variables exist as columns). Example:\n```r\ndat \u003C- na.omit(dat[, c('outcome', 'exposure', 'age', 'sex', 'batch', 'pc1', 'pc2')])\ndat$batch \u003C- factor(dat$batch)\nresult \u003C- hima(outcome ~ exposure + age + sex + batch + pc1 + pc2,\n               data.pheno=dat, data.M=M_matrix, mediator.type='gaussian')\n```\n\n### HIMA mediator-type vs outcome-type mismatch\n\n**Trigger:** Survival outcome (`Surv()` on LHS) with `mediator.type='compositional'` chosen against text mediator panel; or count mediators passed as `'gaussian'`.\n\n**Mechanism:** HIMA v2.3+ auto-detects outcome family from the LHS of `formula` (continuous, binary, survival, count); `mediator.type` is set for the mediator data only (`'gaussian'`, `'negbin'`, `'compositional'`). Mismatching mediator-type to the actual mediator distribution biases the screening step.\n\n**Symptom:** Hazard \u002F rate ratios for indirect effects look implausible; many \"significant\" mediators fail replication.\n\n**Fix:** Set `mediator.type='gaussian'` for continuous (e.g., methylation beta, log-CPM expression), `'negbin'` for raw count (RNA-seq), `'compositional'` for relative-abundance microbiome. Verify by `?hima` in the installed version since the catalogue of mediator types has expanded across releases.\n\n### Bootstrap iterations too low\n\n**Trigger:** `sims=100` or `sims=500` in early exploration left in for the final report.\n\n**Mechanism:** ACME CIs from bootstrap have Monte-Carlo error that scales as 1\u002Fsqrt(sims); at sims=500 the 95% CI bounds have ~5% MC noise, enough to flip the conclusion at the boundary.\n\n**Symptom:** Re-running `mediate()` with a different `set.seed()` gives substantially different CI bounds.\n\n**Fix:** `sims=1000` minimum for any reported result; `sims=5000` for publication; `sims=10000` if proximity to zero matters. BCa CIs (`boot.ci.type='bca'` in `mediate()`) are slightly more accurate than percentile CIs near zero but require more sims for stability.\n\n### Two-step MR instrument independence\n\n**Trigger:** Same set of SNPs used as instruments for E in step 1 and for M in step 2.\n\n**Mechanism:** If a SNP affects both E and M, the M-instrument violates exclusion restriction (the SNP-Y association is not exclusively through M). Estimates are biased toward the direct effect.\n\n**Symptom:** Two-step MR shows large indirect effect; replacing M-instruments with non-overlapping SNPs makes it vanish.\n\n**Fix:** Apply Steiger filter on the mediator: keep only SNPs where the SNP-M F-statistic exceeds SNP-E F-statistic (or where SNP explains more variance in M than E). For MVMR-mediation, require conditional F > 10 for each exposure independently (Sanderson 2019 IJE 48:713).\n\n### Difference vs product of coefficients diverge for non-linear outcomes\n\n**Trigger:** Binary or survival outcome modeled with logistic \u002F Cox.\n\n**Mechanism:** Difference = total - direct; product = alpha * beta. Equivalent under linear-Gaussian; diverge under any link function. Counterfactual ACME from `mediation::mediate()` is the correct quantity; hand-computed product-of-coefficients on logistic output is biased except under rare-disease.\n\n**Fix:** Report only counterfactual ACME (Imai or CMAverse). For OR-based 4-way decomposition on rare outcomes (\u003C= 10%), Valeri & VanderWeele 2013 formulas apply; for common outcomes use risk-ratio scale or marginal effects rather than ORs.\n\n### Required Reporting for Publication\n\n| Component | Required |\n|-----------|----------|\n| ACME estimate + 95% CI (BCa preferred) | Yes |\n| ADE + 95% CI | Yes |\n| Total effect | Yes |\n| Proportion mediated | Yes when total > effect-size threshold |\n| Bootstrap method + sims | percentile \u002F BCa; min 1000, recommend 5000 |\n| Sequential ignorability sensitivity | rho_crit (medsens) OR mediational E-value |\n| Exposure-mediator interaction test | Coefficient + p; 4-way decomposition if significant |\n| Confounder set justification | DAG description |\n| Mediator measurement reliability | Cite |\n| Sample size + missing-data handling | Yes |\n| Mediator \u002F exposure scale | Standardized? log? raw? |\n\nReference: AGReMA guideline (Lee H et al 2021 JAMA 326:1045) and MacKinnon 2008 Introduction to Statistical Mediation Analysis.\n\n## Reconciliation: Observational vs MR Mediation\n\n| Pattern | Likely cause | Action |\n|---------|--------------|--------|\n| Observational ACME significant; MR-mediation null | Unmeasured M-Y confounding inflated observational estimate; OR weak IVs in MR | Re-run observational with `medsens()`; if rho_crit \u003C 0.1, trust MR null |\n| Observational ACME null; MR-mediation significant | Measurement error in M attenuated observational estimate | Trust MR (regression-dilution-free) IF instruments pass Steiger and pleiotropy tests (MR-Egger intercept, MR-PRESSO) |\n| Both significant with same sign | Convergent evidence | High-confidence mediation; report effect size from the more-conservative estimate |\n| Both significant with opposite signs | At least one is biased; revisit confounder structure and IV assumptions | Do not pool; investigate via cross-method sensitivity |\n\n**Operational rule for high-stakes claims (clinical \u002F drug-target mediation):** Require (1) significant observational ACME, (2) Imai rho_crit > 0.2 OR mediational E-value > 1.5, (3) directionally consistent MR-mediation result OR documented absence of valid instruments. Single-method mediation claims should be reported as exploratory.\n\n## Anticipated Reviewer Pushback\n\n| Pushback | Standard response |\n|----------|-------------------|\n| \"Sequential ignorability?\" | Imai rho_crit reported via `medsens`; mediational E-value reported on the risk-ratio scale |\n| \"Exposure-induced confounder of M-Y?\" | DAG drawn; if L present, switch to `CMAverse::cmest(estimation='msm')` for interventional indirect effect (Vansteelandt & Daniel 2017) |\n| \"Why this bootstrap method?\" | BCa with sims=5000 for publication; percentile fallback when BCa fails to converge (acceleration estimate unstable at boundary) |\n| \"Why was MR-mediation not done?\" | If valid IVs for E and M exist: two-step MR or MVMR-mediation done (see code below); if not, documented absence of trans-instruments |\n| \"Mediator measured with error?\" | Regression calibration (Carroll 2006 Measurement Error in Nonlinear Models) OR sensitivity analysis assuming reliability r = 0.7 (Valeri & VanderWeele 2014) |\n| \"Why HIMA2 not BAMA?\" | HIMA2 = frequentist + FDR control + faster; BAMA = Bayesian when prior information is available; sample-size justification given against simulation rule-of-thumb |\n| \"Proportion mediated unstable?\" | When |total| \u003C 2*SE(total), proportion-mediated CI is unreliable (denominator near zero); report indirect effect alone with absolute effect size |\n\n## Quantitative Thresholds\n\n| Quantity | Threshold | Source \u002F Rationale |\n|----------|-----------|--------------------|\n| `sims` (bootstrap iterations) | >= 1000 exploratory, >= 5000 publication | Imai 2010; MC error scales 1\u002Fsqrt(sims) |\n| Proportion mediated -- meaningful | > 0.2 | Convention; weak guideline only -- effect size in absolute terms matters more (MacKinnon 2008) |\n| Proportion mediated -- \"most of the effect\" | > 0.5-0.8 | Convention |\n| Imai rho_crit -- robust | > 0.3 | Imai 2010 Psychol Methods 15:309 |\n| Imai rho_crit -- sensitive | \u003C 0.1 | Same |\n| Mediational E-value -- robust | > 2.0 (working convention; the original Smith & VanderWeele 2019 E-value framework does not prescribe a specific cutoff -- magnitude is context-dependent) | Smith & VanderWeele 2019 Epidemiology 30:835 |\n| HIMA FDR cutoff | BH FDR \u003C 0.05 | Default; report q-values not raw p |\n| MVMR conditional F per exposure | > 10 each | Sanderson 2019 IJE 48:713 |\n| Two-step MR -- F for both stages | > 10 each | Burgess weak-instrument convention |\n| Sample size -- single-mediator (Imai) | >= 200 for stable bootstrap | Simulation rule-of-thumb |\n| Sample size -- HIMA EWAS | >= 150 with p_mediators up to ~10k | Zhang 2016 simulations |\n| Rare-outcome cutoff for OR-based 4-way | outcome prevalence \u003C= 10% | Valeri & VanderWeele 2013 |\n\n## Working Code Patterns\n\n### Single-Mediator Observational with Sensitivity\n\n**Goal:** Decompose a genotype-disease effect via measured molecular mediator with explicit sensitivity to unmeasured M-Y confounding.\n\n**Approach:** Fit mediator and outcome models, bootstrap ACME\u002FADE, run `medsens()` for Imai rho-based sensitivity.\n\n```r\nlibrary(mediation)\n\nmed_model \u003C- lm(expression ~ genotype + age + sex + pc1 + pc2 + pc3, data=dat)\nout_model \u003C- glm(disease ~ genotype + expression + age + sex + pc1 + pc2 + pc3,\n                 data=dat, family=binomial)\n\nmed_result \u003C- mediate(med_model, out_model,\n                      treat='genotype', mediator='expression',\n                      boot=TRUE, sims=5000, boot.ci.type='bca')\nsummary(med_result)\n\nsens \u003C- medsens(med_result, rho.by=0.05, effect.type='indirect', sims=1000)\nsummary(sens)\n```\n\n`d0`, `z0`, `n0`, `tau.coef` slots return ACME, ADE, proportion mediated, total effect.\n\n### 4-Way Decomposition with Exposure-Mediator Interaction\n\n**Goal:** Separate CDE, PIE, INTref, INTmed when exposure-mediator interaction is biologically plausible (e.g., gene-environment interaction modifying mediator effect).\n\n**Approach:** Use CMAverse regression-based estimator with `EMint=TRUE`; bootstrap CIs.\n\n```r\nlibrary(CMAverse)\n\nresult_4way \u003C- cmest(\n  data=dat, model='rb',\n  outcome='disease', exposure='genotype', mediator='expression',\n  basec=c('age','sex','pc1','pc2'),\n  EMint=TRUE,\n  mreg=list('linear'), yreg='logistic',\n  astar=0, a=1, mval=list(0),\n  estimation='paramfunc', inference='bootstrap', nboot=1000\n)\nsummary(result_4way)\n```\n\nCMAverse reports the 4-way decomposition (Vanderweele 2014): for continuous outcomes the components are `cde`, `intref`, `intmed`, `pnie` (or `pie`), `te`, `pm`; for non-continuous outcomes (logistic \u002F Cox \u002F Poisson) the ratio versions `Rcde`, `Rpnde`, `Rtnde`, `Rpnie`, `Rtnie` are reported. When `EMint=TRUE`, additional proportion-attributable-to-interaction terms (`int`, `pe`) are included. Verify column names with `summary(result)$results` in the installed CMAverse version, since naming has evolved.\n\n### High-Dimensional EWAS Mediation (HIMA2)\n\n**Goal:** Among thousands of candidate CpG mediators, identify those mediating an exposure-outcome effect with FDR control.\n\n**Approach:** HIMA v2.3+ uses a formula interface and auto-detects outcome family (Gaussian \u002F binomial \u002F Cox \u002F Poisson). Screening + MCP\u002FDBlasso penalisation + joint significance with BH; the `sigcut` argument controls the FDR threshold (default 0.05).\n\n```r\nlibrary(HIMA)\n\ndat \u003C- na.omit(dat[, c('outcome', 'exposure', 'age', 'sex', 'cell_pc1', 'cell_pc2')])\nM_matrix \u003C- as.matrix(beta_values)\n\nresult \u003C- hima(\n  outcome ~ exposure + age + sex + cell_pc1 + cell_pc2,\n  data.pheno=dat,\n  data.M=M_matrix,\n  mediator.type='gaussian',          # 'negbin' for count, 'compositional' for microbiome\n  penalty='DBlasso',                  # default; alternatives 'MCP', 'SCAD', 'lasso'\n  scale=TRUE,\n  sigcut=0.05,\n  parallel=TRUE, ncore=8, verbose=TRUE\n)\n# result is a data.frame of significant mediators below sigcut\n```\n\nFor survival outcomes wrap the LHS as `Surv(time, status)`; HIMA auto-routes to Cox. The old `hima_classic()` (Zhang 2016 original) is still exported but screens by beta only and misses mediators with strong alpha + weak beta -- prefer the wrapper `hima()` unless reproducing a 2016-2021 paper.\n\nFor highly-correlated mediators (CpG-island clusters, gene-module co-expression): HIMA uses joint significance with BH-FDR on max(p_alpha, p_beta) and handles correlation only weakly. Within `hima()`, set `penalty='MCP'` for stronger correlation handling; alternatively pre-reduce the mediator panel by principal components or by clustering correlated mediators and screening the cluster centroid (VanderWeele & Vansteelandt 2014 Epidemiol Methods 2:95).\n\n### Time-Varying Mediation Methods\n\nWhen the mediator is measured at multiple timepoints (or exposure varies over time), natural-effects estimands are not identified; switch to one of:\n\n- g-formula (parametric or Monte Carlo): `gfoRmula::gformula_continuous_eof()`; `CMAverse::cmest(estimation='gformula')`\n- g-estimation of a structural nested mean model: `gesttools::gestSingle()` \u002F `gestMultiple()`\n- Marginal structural model with stabilized IPTW: `ipw::ipwtm()` followed by `glm(..., weights=sw)`\n- Sequential mediation for K timepoints: VanderWeele & Tchetgen Tchetgen 2017 JRSSB 79:917\n\nChoose based on the experimental structure:\n- >= 3 timepoints required for g-methods to identify time-varying indirect effects\n- Longitudinal mediator measurement at EACH timepoint is required (not just baseline)\n- MSM is preferred when treatment is binary and time-varying; g-formula when continuous\n- Sequential mediation when the causal ordering of multiple mediators is known and stable across time\n\n### MR-Mediation: Two-Step vs MVMR-Mediation\n\nDecision tree:\n- Independent instrument sets available for E and M -> two-step MR (Burgess 2015 IJE 44:484)\n- E and M share instruments (common in cis-eQTL \u002F cis-pQTL mediator cases) -> MVMR-mediation (Carter & Sanderson 2021 Eur J Epidemiol 36:465)\n- Both feasible -> report both (triangulation)\n\nTwo-step code sketch:\n\n```r\nlibrary(TwoSampleMR)\nexp_E \u003C- extract_instruments('ieu-a-2', clump=TRUE)\nm_E \u003C- extract_outcome_data(exp_E$SNP, 'ieu-b-30')\ndat_EM \u003C- harmonise_data(exp_E, m_E)\nmr_EM \u003C- mr(dat_EM)\n\nexp_M \u003C- extract_instruments('ieu-b-30', clump=TRUE)\nexp_M_indep \u003C- exp_M[!exp_M$SNP %in% exp_E$SNP, ]\nexp_M_indep \u003C- steiger_filtering(exp_M_indep)\nout_M \u003C- extract_outcome_data(exp_M_indep$SNP, 'ieu-a-7')\ndat_MY \u003C- harmonise_data(exp_M_indep, out_M)\nmr_MY \u003C- mr(dat_MY)\n```\n\nIndirect effect = beta_EM * beta_MY (product of coefficients). CI via delta method or parametric bootstrap of the joint (beta_EM, beta_MY) distribution. Steiger filter on M-instruments is mandatory to ensure the M -> Y direction (not Y -> M).\n\n### MR-Mediation: Total Minus Direct via MVMR\n\n**Goal:** Estimate the proportion of a genetic-instrument-identified causal effect that flows through a mediator, using independent IVs for E and (E + M).\n\n**Approach:** Univariable MR for total E->Y; MVMR for direct E->Y conditional on M; indirect = total - direct via delta-method CI.\n\n```r\nlibrary(TwoSampleMR); library(MVMR)\n\ntotal \u003C- mr_ivw(beta_E, beta_Y, se_E, se_Y)\nmvmr_dat \u003C- format_mvmr(BXGs=cbind(beta_E, beta_M),\n                        BYG=beta_Y, seBXGs=cbind(se_E, se_M), seBYG=se_Y, RSID=snps)\nfstat \u003C- strength_mvmr(mvmr_dat, gencov=0)\nmvmr_fit \u003C- ivw_mvmr(mvmr_dat)\ndirect \u003C- mvmr_fit[1, 'Estimate']\ndirect_se \u003C- mvmr_fit[1, 'Std. Error']\n\nindirect \u003C- total$b - direct\nindirect_se \u003C- sqrt(total$se^2 + direct_se^2)\nindirect_ci \u003C- indirect + c(-1.96, 1.96) * indirect_se\n```\n\nRequire `fstat` conditional F > 10 for both E and M independently. If `fstat \u003C 10`, use Q-statistic-adjusted IVW (`qhet_mvmr`) or report the result as weak-instrument-limited.\n\n### Double-ML Doubly-Robust Mediation\n\n**Goal:** Avoid model misspecification of both mediator and outcome models via cross-fitted ML nuisance estimators.\n\n**Approach:** `causalweight::medDML` uses random forests (or other learners) with sample splitting to estimate nuisance parameters; final estimator is doubly robust.\n\n```r\nlibrary(causalweight)\n\nresult_dml \u003C- medDML(\n  y=dat$outcome, d=dat$treatment, m=dat$mediator,\n  x=as.matrix(dat[, covariates]),\n  trim=0.05, order=1\n)\n```\n\nReports direct, indirect (via mediator), and total effects with influence-function-based standard errors. Robust to non-linearity and interactions; assumes sequential ignorability still.\n\n### Mediational E-Value for Sensitivity\n\n**Goal:** Report the minimum strength of an unmeasured M-Y confounder required to nullify the observed indirect effect.\n\n**Approach:** Convert ACME and its CI to a risk-ratio scale, then apply VanderWeele E-value formula.\n\n```r\nlibrary(EValue)\n\nacme_rr \u003C- exp(med_result$d0)\nacme_lower_rr \u003C- exp(med_result$d0.ci[1])\nevalues.RR(acme_rr, lo=acme_lower_rr, hi=NULL)\n```\n\nFor binary outcomes, convert ACME on probability scale to RR; for continuous, use `evalues.OLS()` with the standardized indirect effect. E-value > 2 indicates a confounder would need >2-fold associations with both M and Y to nullify the indirect effect (Smith & VanderWeele 2019).\n\n## Tool Install Notes\n\n| Package | Source | Notes |\n|---------|--------|-------|\n| mediation | CRAN | `install.packages('mediation')`; actively maintained (Imai group) |\n| CMAverse | GitHub | `remotes::install_github('BS1125\u002FCMAverse')`; NOT on CRAN; 6 estimators in one interface |\n| HIMA | GitHub | `remotes::install_github('YinanZheng\u002FHIMA')`; archived from CRAN 2026-07 (needs archived `scalreg`); v2.x renamed `hima()` to HIMA2 -- verify with `?hima` |\n| bama | CRAN | `install.packages('bama')`; Bayesian; slow MCMC |\n| causalweight | CRAN | `install.packages('causalweight')`; medDML for double-ML mediation |\n| EValue | CRAN | `install.packages('EValue')`; for mediational E-values |\n| TwoSampleMR | r-universe | See causal-genomics\u002Fmendelian-randomization for setup |\n| MVMR | r-universe | `remotes::install_github('WSpiller\u002FMVMR')`; for MVMR-mediation |\n| gfoRmula | CRAN | For longitudinal \u002F time-varying confounders |\n\n## Common Errors\n\n| Error \u002F symptom | Cause | Solution |\n|-----------------|-------|----------|\n| `Error in storage.mode(x) \u003C- \"double\"` inside `hima()` | NA in `data.pheno` columns referenced by formula, or unconverted factors | `na.omit(data.pheno)` first; ensure all RHS vars in formula are numeric or factor |\n| ACME significant, ADE significant, total NOT significant | Suppression \u002F inconsistent mediation | Report transparently; effect partitioning can exceed total in suppression |\n| `medsens()` errors on glm outcome | `medsens` requires linear OR probit (not logit) outcome | Refit outcome as `glm(..., family=binomial(link='probit'))` |\n| `mediate()` runs forever with binary outcome | `sims=5000` with bootstrap and small n | Use `sims=1000` exploratory; verify model converges first; consider parallel via `parallel='multicore'` |\n| CMAverse `cmest()` reports NaN for `pm` | Total effect crosses zero -> proportion ill-defined | Report ACME and TE separately; pm is unstable when |TE| is small |\n| Different ACME between `mediation` and CMAverse `rb` | Default `astar\u002Fa` levels differ; binary mediator handled differently | Set `astar=0, a=1` explicitly; for binary mediator pass `mval=list(0)` |\n| HIMA returns zero significant mediators | Screening too aggressive; or no true mediators | Try `topN=2*sqrt(n)` instead of default; verify with permutation null |\n| Two-step MR shows indirect > total | Steiger reversal: M actually causes E; or pleiotropic SNPs | Run MR-Steiger filter; use MR-PRESSO for pleiotropy |\n| `medDML` trim removes most data | Severe positivity violation -- few units with overlapping treatment\u002Fmediator distributions | Tighten covariate set; check propensity score distributions |\n\n## References\n\n- Baron RM, Kenny DA 1986 J Pers Soc Psychol 51:1173 (original product-of-coefficients)\n- Imai K, Keele L, Tingley D 2010 Psychol Methods 15:309 (counterfactual mediation, sequential ignorability)\n- VanderWeele TJ 2014 Epidemiology 25:749 (4-way decomposition)\n- VanderWeele TJ 2015 Explanation in Causal Inference (OUP) -- canonical textbook\n- Valeri L, VanderWeele TJ 2013 Psychol Methods 18:137 (binary outcomes; rare-disease 4-way)\n- Vansteelandt S, Daniel RM 2017 Epidemiology 28:258 (interventional \u002F randomized indirect effects)\n- Shi B et al 2021 Epidemiology 32:e20 (CMAverse package; 6 estimators)\n- Zhang H et al 2016 Bioinformatics 32:3150 (HIMA original)\n- Perera C et al 2022 BMC Bioinformatics 23:296 (HIMA2 alpha-beta screening)\n- Song Y et al 2020 Biometrics 76:700 (BAMA Bayesian high-D mediation)\n- Burgess S et al 2015 IJE 44:484 (network \u002F two-step MR)\n- Sanderson E et al 2019 IJE 48:713 (MVMR conditional F-statistic)\n- Carter AR & Sanderson E 2021 Eur J Epidemiol 36:465 (MVMR-mediation)\n- Farbmacher H et al 2022 Econometrics J 25:277 (medDML \u002F double-ML mediation)\n- Smith LH, VanderWeele TJ 2019 Epidemiology 30:835 (mediational E-value)\n\n## Related Skills\n\n- causal-genomics\u002Fmendelian-randomization - IV-based causal inference; foundation for MR-mediation\n- causal-genomics\u002Fpleiotropy-detection - MR-mediation instrument validity hinges on pleiotropy diagnostics (MR-Egger intercept, MR-PRESSO)\n- causal-genomics\u002Fcolocalization-analysis - Confirm shared causal variant before causal mediation\n- causal-genomics\u002Ffine-mapping - Identify the causal variant driving the exposure\n- methylation-analysis\u002Fdifferential-cpg-testing - Per-CpG inputs for HIMA EWAS mediation\n- differential-expression\u002Fdeseq2-basics - Expression inputs for eQTL mediation\n- multi-omics-integration\u002Fmofa-integration - Multi-layer mediator construction\n- population-genetics\u002Fassociation-testing - GWAS summary statistics for MR-mediation\n- clinical-biostatistics\u002Feffect-measures - Risk-ratio \u002F odds-ratio scales for binary outcomes\n- machine-learning\u002Fmodel-validation - Cross-fitting and sample splitting for medDML\n",{"name":5,"source":24,"license":15,"tool_type":25,"description":7,"imported_at":26,"source_path":27,"primary_tool":28,"source_repository":29},"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills","mixed","2026-09-20","causal-genomics\u002Fmediation-analysis\u002FSKILL.md","mediation","GPTomics\u002FbioSkills","main","2d1750717747097b602acf30bd09a7cbd4b4c6ea","awesome_skills\u002Fbiology\u002Fbio-causal-genomics-mediation-analysis","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous","2026-11-09 11:45:36",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-causal-genomics-mediation-analysis",{"tool":42,"command":43},"bunx","bunx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-causal-genomics-mediation-analysis",{"tool":45,"command":46},"pnpm","pnpm dlx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-causal-genomics-mediation-analysis","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-causal-genomics-mediation-analysis\u002FSKILL.md",true,[50,56,60,64,68],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"examples\u002Fcmaverse_4way.R","OTHER","其他",4989,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-causal-genomics-mediation-analysis\u002Fexamples\u002Fcmaverse_4way.R",{"path":57,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":58,"sourceHtmlUrl":59},"examples\u002Feqtl_mediation.R",3304,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-causal-genomics-mediation-analysis\u002Fexamples\u002Feqtl_mediation.R",{"path":61,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":62,"sourceHtmlUrl":63},"examples\u002Fmvmr_mediation.R",4792,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-causal-genomics-mediation-analysis\u002Fexamples\u002Fmvmr_mediation.R",{"path":65,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":66,"sourceHtmlUrl":67},"examples\u002Fsensitivity_analysis.R",2802,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-causal-genomics-mediation-analysis\u002Fexamples\u002Fsensitivity_analysis.R",{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},"usage-guide.md","REFERENCE","参考文档",9961,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-causal-genomics-mediation-analysis\u002Fusage-guide.md",[75,83,90,97,104,111],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":82},"01M7FFFZPC2025JQQHPHDX154J","dei-assessment","Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-assessment\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":82},"01M7FFFWN8H4WA7A6Y398QKB6J","dei-action-plan","Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-action-plan\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":82},"01M7FFFSHTM0QZRVZ2NRJTJ0PY","culture-fit-assessment","Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fculture-fit-assessment\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":82},"01M7FFFMA12RKEQA38KHJSXXPS","cowork-to-code-bridge","Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcowork-to-code-bridge\u002FSKILL.md",[],[],{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":82},"01M7FFFH1F6M8YRGW5V487GH1K","counter-offer-response","Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcounter-offer-response\u002FSKILL.md",[],[],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":82},"01M7FFFDGEHV8Y7J9N40HZXW52","continuous-feedback-system","Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcontinuous-feedback-system\u002FSKILL.md",[],[]]