← BlogOpen Aqrab →

Mediation Analysis: When You Want the Mechanism, Not Just the Effect

📖 16 min read · Published Apr 8, 2026

Infographic: Mediation Analysis: When You Want the Mechanism, Not Just the Effect

Sometimes the treatment works, and that is not enough. You want to know how it works. Did the intervention reduce mortality because it improved blood pressure control? Did a policy increase screening because it changed physician behavior? That is the promise of mediation analysis. The problem is that most published mediation analyses still do the dumb version: regress the outcome on treatment and mediator, call the coefficient for treatment the “direct effect,” and move on. That is usually wrong.

Mediation analysis is not just “adjusting for a mediator.” It is a counterfactual framework for decomposing a total effect into a pathway that runs through the mediator and a pathway that does not. Done properly, it can answer mechanism questions with real scientific value. Done casually, it manufactures pseudo-mechanisms out of post-treatment bias.

The Core Question

Start with three variables:

  • A: the exposure or treatment
  • M: the mediator — a variable affected by treatment that may transmit some of its effect
  • Y: the outcome

The total causal effect of A on Y may operate partly through M and partly through other pathways. Mediation analysis asks whether the treatment changes the outcome because it changes the mediator.

Clinical example:

Suppose a hypertension management program lowers stroke risk. The obvious candidate mediator is blood pressure control at 3 months. If most of the program’s effect on stroke runs through improved blood pressure, that supports the biological and behavioral story. If not, maybe the program works through medication adherence, diet, or follow-up intensity instead.

Why the Usual Regression Trick Fails

The classic bad move is this: fit one model for Y ~ A, then a second model for Y ~ A + M, and declare the difference in coefficients to be the mediated effect. That only works under narrow linear-model conditions with no interaction, no non-collapsibility problems, and no mediator-outcome confounding affected by treatment. In real clinical data, those assumptions usually fail.

Why it breaks:

  • The mediator is post-treatment. Conditioning on it can induce collider bias.
  • Mediator-outcome confounders may themselves be affected by treatment.
  • Odds ratios and hazard ratios are not collapsible, so coefficient differences do not map cleanly to causal pathway effects.
  • Treatment–mediator interaction changes the decomposition entirely.

Translation: if your mediation analysis can be done by clicking “add mediator to regression,” it is probably too naive to trust.

The Counterfactual Decomposition

Modern mediation analysis defines effects using potential outcomes. The two quantities people usually care about are the natural direct effect (NDE) and the natural indirect effect (NIE).

Natural Direct Effect

The effect of changing treatment from 0 to 1 while holding the mediator fixed at whatever value it would have taken under treatment 0.

Natural Indirect Effect

The effect of changing the mediator from the value it would have under treatment 0 to the value it would have under treatment 1, while keeping treatment fixed.

Total Effect

The overall effect of treatment on outcome. In additive scales, Total Effect = NDE + NIE.

These are elegant definitions, but they are not free. Identifying them from observed data requires strong assumptions — stronger than standard confounding adjustment for the total effect.

The Assumptions You Cannot Hand-Wave

1. No unmeasured exposure-outcome confounding

Same as any causal effect estimate: conditional on measured covariates, treatment assignment must be exchangeable.

2. No unmeasured exposure-mediator confounding

You must be able to explain why treatment does or does not influence the mediator conditional on measured variables.

3. No unmeasured mediator-outcome confounding

After conditioning on measured covariates, the mediator should be as good as randomized with respect to the outcome.

4. No mediator-outcome confounders affected by treatment

This is the killer assumption. If treatment changes a variable that then affects both mediator and outcome, natural direct and indirect effects are generally not identified by standard methods.

5. Positivity and correct model specification

All relevant strata must contain support for the observed values, and your mediator/outcome models cannot be badly misspecified.

That fourth assumption is why mediation analysis blows up so often in longitudinal clinical settings. Once treatment changes later health status, and later health status influences both the mediator and outcome, simple natural effect estimation is no longer enough. You need more careful estimands — often interventional direct and indirect effects or full longitudinal g-methods.

A DAG-First Way to Think About It

Before fitting anything, draw the DAG. If you cannot defend the causal ordering on paper, you have no business decomposing mechanisms in software.

  • Does treatment cause the mediator?
  • Does the mediator occur before the outcome?
  • What common causes of mediator and outcome exist?
  • Did treatment change any of those common causes?
  • Are there competing mediators that make your chosen mediator a bad summary of the mechanism?

Mediation is incredibly sensitive to timing. If your mediator and outcome are measured in the same visit window, you may not know which came first. If so, stop. You do not have a mediation dataset. You have a vague temporal mess with a regression problem.

Clinical Example: Statin Program → LDL Reduction → Cardiovascular Events

Imagine a clinic-wide statin adherence program. Exposure is participation in the program. Mediator is LDL at 6 months. Outcome is major adverse cardiovascular events at 2 years.

The scientific question is not only whether the program works, but whether it works through lipid lowering. That is a legitimate mediation question because the mechanism matters for intervention design. If the benefit is mostly through LDL reduction, then tighter lipid monitoring and medication optimization are central. If the direct pathway dominates, the intervention may be improving other behaviors too.

But now imagine the program also increases clinic attendance. More clinic visits change both LDL measurement and downstream event detection. Clinic attendance becomes a post-treatment variable that may confound the mediator-outcome relationship. If you ignore that, your “indirect effect through LDL” becomes a Frankenstein estimate mixing biology, surveillance, and healthcare utilization.

Which Estimand Should You Use?

EstimandUse whenMain problem
Natural direct / indirect effectsCross-sectional or simple settings with strong assumptions that are plausibleRequires no treatment-induced mediator-outcome confounders
Controlled direct effectYou want the effect of treatment if the mediator were fixed at a chosen levelOften less mechanistic and may involve unrealistic mediator interventions
Interventional direct / indirect effectsMore realistic decomposition when natural effects are too brittleInterpretation is subtler, implementation more technical
Longitudinal g-method mediationMediator and confounding evolve over timeHeavy data and modeling burden

Most researchers should stop reflexively aiming for natural effects. If treatment-induced confounding is plausible — and in medicine it often is — interventional effects are usually the more defensible target.

How Estimation Usually Works

In practice, mediation analysis is usually estimated through one of three strategies:

  1. Parametric regression / g-formula: model the mediator given treatment and covariates, then model the outcome given treatment, mediator, and covariates, and combine them to compute counterfactual contrasts.
  2. Weighting-based approaches: use inverse probability weights to balance treatment and mediator models, especially when decomposing interventional effects.
  3. Simulation / Monte Carlo standardization: draw mediator values and outcomes under hypothetical interventions and average the results.

The core workflow is always the same: specify the causal question, define the estimand, model the relevant conditional distributions, compute the counterfactual contrasts, and then bootstrap the hell out of it for uncertainty.

Treatment–Mediator Interaction Changes Everything

If the effect of the mediator on the outcome depends on treatment status, you have treatment–mediator interaction. This is common and important. For example, a rehabilitation program may improve functional recovery partly through exercise adherence, but the clinical impact of adherence may be larger within the program because coaching amplifies the benefit of each exercise session.

When that interaction exists, you cannot summarize mediation with a single percentage mediated and call it a day. The direct and indirect effects depend on the exposure level being referenced. That is not a nuisance. That is the science.

Rule of thumb:

Never report only “percent mediated.” It is unstable, scale-dependent, and often misleading. Report the total effect, direct effect, indirect effect, the effect scale, and whether exposure–mediator interaction was allowed.

Common Failure Modes

❌ Treating any post-treatment variable as a mediator

Just because something happens after treatment does not make it a meaningful mechanism. Some post-treatment variables are colliders, proxies, or measurement artifacts.

❌ Ignoring mediator-outcome confounding

This is the most common fatal flaw. If severity, care intensity, behavior, or adherence influence both mediator and outcome, you must address them or the decomposition is garbage.

❌ No temporal separation

Mediator and outcome measured simultaneously means no credible mechanism story. Timing is not decoration. It is identification.

❌ Reporting only indirect-effect p-values

The point estimate, scale, confidence interval, and substantive interpretation matter more than whether a bootstrap CI excludes zero.

❌ Using odds-ratio decompositions without caution

Non-collapsibility makes logistic decomposition treacherous. Be explicit about scale and do not recycle linear-model intuition in nonlinear settings.

❌ Saying “mechanism proven”

Mediation analysis supports a mechanistic explanation under assumptions. It does not prove biology. Leave some oxygen in the room for humility.

A Practical Workflow

1

State the mechanism question explicitly

Not “is there mediation?” but “how much of the treatment effect on Y operates through M on the chosen scale?”

2

Draw the DAG and define timing

List baseline confounders, mediator-outcome confounders, and any treatment-induced confounders.

3

Choose the estimand before the model

Natural, controlled, or interventional effects are not interchangeable. Pick the one your design can identify.

4

Fit mediator and outcome models carefully

Allow nonlinearity and treatment–mediator interaction when scientifically plausible.

5

Estimate effects on a meaningful scale

Risk differences are often easier to interpret than odds ratios for decomposition.

6

Run sensitivity analyses

Stress-test mediator-outcome confounding, alternate model forms, and measurement timing assumptions.

Reporting Checklist

  • Clear definition of exposure, mediator, outcome, and temporal ordering
  • DAG or equivalent causal justification for the mediation structure
  • Explicit estimand: natural direct/indirect, controlled direct, or interventional effects
  • Confounders used for exposure-mediator, exposure-outcome, and mediator-outcome control
  • Statement about treatment-induced mediator-outcome confounding and how it was handled
  • Outcome scale used for decomposition and why that scale was chosen
  • Allowance for treatment–mediator interaction if plausible
  • Uncertainty estimation method, usually bootstrap
  • Sensitivity analysis for mediator-outcome confounding or alternative estimands
  • Interpretation that avoids claiming mechanism has been “proved”

Software Options

You do not need custom code for every mediation problem, but you do need to know what your package is actually estimating.

LanguageCommon toolsUse with caution
Rmediation, CMAverse, regmedint, tmle3Check estimand and assumptions; package defaults are not your study design
Stataparamed, med4way, gformula workflowsUnderstand scale and interaction handling
PythonMostly custom workflows with statsmodels, econml-adjacent tooling, or simulationFew high-level mediation APIs are mature enough for serious clinical work

When Mediation Analysis Is Worth It

  • Intervention refinement: you want to know which component or pathway is carrying the benefit
  • Biological explanation: the mechanistic story has scientific importance, not just storytelling value
  • Policy design: understanding whether an intervention works through access, adherence, clinician behavior, or surveillance intensity changes what you build next
  • The DAG is defensible: you can actually justify the assumptions with design knowledge

When You Should Not Bother

  • The total effect is not even credible yet
  • Mediator timing is sloppy or ambiguous
  • Key mediator-outcome confounders are missing
  • Treatment-induced confounding is obvious but ignored
  • You only want a pretty path diagram for the discussion section

Here’s the blunt version: if your study cannot support the assumptions, a failed mediation analysis is not a missed opportunity. It is methodological restraint. That is a virtue.

Key References

  • Robins JM, Greenland S. Identifiability and Exchangeability for Direct and Indirect Effects. Epidemiology. 1992;3(2):143-155.
  • Pearl J. Direct and Indirect Effects. In: Proceedings of the Seventeenth Conference on Uncertainty in Artificial Intelligence. 2001:411-420.
  • VanderWeele TJ. Mediation Analysis: A Practitioner’s Guide. Annu Rev Public Health. 2016;37:17-32.
  • VanderWeele TJ. Explanation in Causal Inference: Methods for Mediation and Interaction. Oxford University Press; 2015.
  • Vansteelandt S, Daniel RM. Interventional Effects for Mediation Analysis with Multiple Mediators. Epidemiology. 2017;28(2):258-265.
  • Nguyen QC, Schmid I, Stuart EA. Clarifying Causal Mediation Analysis for the Applied Researcher. Am J Epidemiol. 2021;190(10):2206-2218.

Need help deciding whether your mediator analysis is actually identifiable?

Aqrab can map your DAG, pressure-test the assumptions, and tell you whether mediation is justified or just decorative.

Try Aqrab Free →