Causal mediation analysis is a formal method for decomposing a total causal effect into its direct effect (the treatment's impact on the outcome not through the mediator) and its indirect effect (the portion transmitted through the mediator). This requires specifying a causal model, often a Structural Causal Model (SCM) or causal graph, that defines the relationships between treatment, mediator, outcome, and potential confounders. The analysis moves beyond correlation to answer how a cause produces its effect.
Glossary
Causal Mediation Analysis

What is Causal Mediation Analysis?
Causal mediation analysis is a statistical method used to decompose a total treatment effect into direct and indirect effects, quantifying the extent to which the effect operates through a specific intermediate variable, or mediator.
The method relies on the counterfactual framework to define effects like the Natural Direct Effect (NDE) and Natural Indirect Effect (NIE), which sum to the Average Treatment Effect (ATE). Key assumptions include sequential ignorability (no unmeasured confounding of either the treatment-mediator or mediator-outcome relationships). It is distinct from traditional path analysis as it explicitly models interventions using the do-operator, enabling the estimation of effects that have a clear causal interpretation under the specified model.
Key Components of Mediation Analysis
Causal mediation analysis decomposes a total treatment effect into direct and indirect pathways. These components define the formal quantities, assumptions, and methods required to estimate how much of an effect operates through a specific intermediate variable.
Total Effect (TE)
The Total Effect (TE) is the overall causal effect of a treatment (X) on an outcome (Y), encompassing all possible pathways. It is the difference in the expected outcome when the treatment is present versus absent, formally: TE = E[Y | do(X=1)] - E[Y | do(X=0)]. In mediation, the TE is the sum of the direct and indirect effects.
Natural Direct Effect (NDE)
The Natural Direct Effect (NDE) quantifies the portion of the total effect that operates on the outcome through pathways not involving the specified mediator (M). It measures the change in Y when X changes, but the mediator is held at the value it would have naturally taken without the treatment. It answers: 'What is the effect of X on Y if we disable the path through M?'
Natural Indirect Effect (NIE)
The Natural Indirect Effect (NIE) quantifies the portion of the total effect that operates on the outcome through the specified mediator (M). It measures the change in Y when the treatment is fixed, but the mediator changes to the value it would have under treatment. Formally, it captures: TE = NDE + NIE. It answers: 'What is the effect of X on Y that is transmitted via M?'
Controlled Direct Effect (CDE)
The Controlled Direct Effect (CDE) is an alternative to the NDE. It measures the effect of the treatment on the outcome when the mediator is experimentally set to a specific, fixed value for the entire population (M = m). Unlike the NDE, it does not allow the mediator to vary naturally. The CDE is useful for policy questions about manipulating both X and M simultaneously.
Sequential Ignorability
Sequential Ignorability is the core set of assumptions required to identify natural direct and indirect effects from observational data. It consists of two main conditions:
- No Unmeasured Confounding of X->Y and X->M: All common causes of treatment and outcome/mediator are observed.
- No Unmeasured Confounding of M->Y: After conditioning on treatment and pre-treatment covariates, there are no unobserved common causes of the mediator and outcome. Violations of these assumptions, particularly the second, are a major source of bias.
Mediation Formulas
The Mediation Formulas provide the mathematical expressions to estimate NDE and NIE from observed data under the sequential ignorability assumptions. For a binary treatment, they integrate over the distribution of covariates (C) and the mediator:
- NDE = Σ_c Σ_m [E(Y | X=1, M=m, C=c) - E(Y | X=0, M=m, C=c)] * P(M=m | X=0, C=c) * P(C=c)
- NIE = Σ_c Σ_m E(Y | X=1, M=m, C=c) * [P(M=m | X=1, C=c) - P(M=m | X=0, C=c)] * P(C=c)
These formulas are implemented in software packages like
mediationin R.
How Causal Mediation Analysis Works
Causal mediation analysis is a statistical method used to decompose the total effect of a treatment or intervention into its constituent direct and indirect pathways, quantifying the role of an intermediate variable, or mediator.
Causal mediation analysis formally decomposes a total treatment effect into a direct effect and an indirect effect (or mediated effect). The direct effect is the impact of the treatment on the outcome that does not pass through the specified mediator variable. The indirect effect is the portion of the total effect that operates through the mediator, quantifying how much the treatment changes the mediator, which in turn changes the outcome. This decomposition relies on a causal graph and assumptions like sequential ignorability to identify these effects from data.
The analysis employs a counterfactual framework, comparing potential outcomes under different treatment and mediator states. Key estimands include the Natural Direct Effect (NDE) and Natural Indirect Effect (NIE), which sum to the Average Total Effect (ATE). This method is crucial for explainable AI and causal fairness, as it reveals the mechanisms behind an observed effect, distinguishing between direct discrimination and effects mediated by permissible factors. It requires careful control for post-treatment confounding to avoid bias.
Frequently Asked Questions
Causal mediation analysis is a statistical technique used to decompose the total effect of a treatment or intervention into its direct and indirect components, quantifying the role of intermediate variables. These FAQs address its core mechanisms, applications, and implementation for engineers and data scientists.
Causal mediation analysis is a method for quantifying the extent to which a treatment's effect on an outcome operates through a specific intermediate variable, known as a mediator. It works by decomposing the total treatment effect into two components: the direct effect (the effect of the treatment not passing through the mediator) and the indirect effect (the effect transmitted via the mediator). This is formalized using a counterfactual framework and structural causal models (SCMs), where potential outcomes are defined under different combinations of treatment and mediator values. The analysis requires strong assumptions, primarily sequential ignorability, which posits no unmeasured confounding of either the treatment-mediator or mediator-outcome relationships after conditioning on observed covariates.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Causal mediation analysis is a core technique within the broader field of causal inference. These related concepts define the mathematical and graphical tools required to decompose and quantify effects.
Structural Causal Model (SCM)
A Structural Causal Model (SCM) is the formal mathematical framework underpinning mediation analysis. It represents causal relationships as a system of structural equations, typically visualized as a causal graph. An SCM explicitly defines how each variable is generated from its direct causes and independent noise, enabling precise definitions of interventions (do-operator) and counterfactuals. Mediation analysis uses the SCM to formally define direct, indirect, and total effects.
Causal Graph (DAG)
A causal graph, or Directed Acyclic Graph (DAG), is the visual representation of an SCM. Nodes are variables, and directed edges represent assumed direct causal influences. For mediation analysis, the DAG explicitly shows the treatment (T), mediator (M), and outcome (Y), along with any confounders. Key paths include:
- Direct path: T → Y
- Indirect path: T → M → Y
- Backdoor paths: Non-causal associations, e.g., T ← C → Y, which must be blocked for identification. Understanding d-separation in the DAG is essential for identifying which covariates to control for.
Intervention & Do-Calculus
The intervention, denoted by the do-operator (e.g., do(T=1)), is the mathematical representation of forcibly setting a variable to a value, simulating a randomized experiment. Do-calculus is a set of three inference rules that allow researchers to translate expressions involving interventions (P(Y | do(T))) into observable statistical quantities, provided the causal graph is known. Mediation formulas, such as the Pearl's mediation formula for natural direct and indirect effects, are derived using do-calculus to express these effects in terms of estimable conditional probabilities from observational data.
Counterfactual
A counterfactual is a statement about what would have happened under a different, hypothetical condition. It represents the highest level on the causal hierarchy (ladder of causation). In mediation, effects are defined using counterfactual outcomes. For example, the natural indirect effect compares the outcome if the treatment were applied but the mediator took its value as if the treatment were not applied: Y(T=1, M(T=0)). This contrasts with the controlled direct effect, which holds the mediator fixed at a specific level. Counterfactual definitions provide the most rigorous grounding for mediation analysis.
Causal Identifiability
Causal identifiability is the property that a causal quantity (like a mediation effect) can be uniquely computed from the available data and the assumed causal model. For mediation, specific identifiability assumptions must hold:
- No unmeasured confounding of the T-Y, T-M, and M-Y relationships.
- No mediator-outcome confounder affected by treatment.
- Consistency and positivity. If these assumptions are violated, the direct and indirect effects may not be nonparametrically identifiable from observational data, requiring alternative designs (e.g., experiments) or sensitivity analyses.
Frontdoor Criterion
The frontdoor criterion is a graphical identification strategy used when a mediator variable provides a viable path to estimate a causal effect in the presence of unmeasured confounding between treatment and outcome. It is a complement to the backdoor criterion. The path must satisfy:
- The treatment affects the mediator.
- The mediator affects the outcome.
- All effect of the treatment on the outcome passes through the mediator.
- There is no unmeasured confounding of the mediator-outcome relationship. If these hold, the causal effect can be computed by summing over the mediator's values, even with confounding on the main T-Y path.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us