Tutorials › Causal Inference › Worked Binary-Mediator Mediation Analysis

Mediation and Path-Specific Effects · Tutorial 785 of 972

Worked Binary-Mediator Mediation Analysis

Learn to calculate natural effects from joint distributions of binary treatment, mediator, and outcome, and to interpret the results on the risk-difference scale.

Advanced 10 min read

What You'll Learn

  • Extract mediator probabilities and outcome risks from a joint distribution of binary variables
  • Apply the mediation formula to calculate counterfactual risks
  • Calculate natural direct, indirect, and total effects on the risk-difference scale
  • Check how changing the reference mediator distribution changes a decomposition
  • State the assumptions required to interpret standardized risks as natural effects

From a Joint Distribution to Natural Effects

When treatment, mediator, and outcome are binary, the observed data can be summarized by the joint distribution of mediator and outcome within each treatment group. The challenge is to turn those observed probabilities into counterfactual risks that answer questions such as: what would the outcome risk be under treatment if the mediator instead followed the distribution it would have under no treatment?

This tutorial works through that calculation step by step. The outcome is binary, so its expected value is its risk. Effects will be expressed as differences in risk, measured in percentage points when converted to percentages. These are population quantities; the hypothetical distributions below are treated as known exactly, so the examples do not calculate sampling uncertainty.

Definition: Let \(A\) denote binary treatment, \(M\) a binary mediator, and \(Y\) a binary outcome, with values 0 and 1. Let \(M_a\) be the mediator value that would occur under treatment \(a\), and let \(Y_{a,m}\) be the outcome that would occur under treatment \(a\) if the mediator were set to \(m\). The natural counterfactual outcome \(Y_{a,M_{a'}}\) combines treatment \(a\) with the mediator value that would naturally occur under treatment \(a'\). Its mean is a natural-effect risk.

For a chosen reference value \(a'\), the natural direct effect compares \(E[Y_{1,M_{a'}}]\) with \(E[Y_{0,M_{a'}}]\): treatment changes while the mediator follows its natural value under \(a'\). The corresponding natural indirect effect at treatment value \(a\) compares \(E[Y_{a,M_1}]\) with \(E[Y_{a,M_0}]\): the treatment setting is held fixed while the mediator’s natural distribution changes. A common additive decomposition is

$$ \begin{aligned} \text{NDE}(0) &= E[Y_{1,M_0}]-E[Y_{0,M_0}],\\ \text{NIE}(1) &= E[Y_{1,M_1}]-E[Y_{1,M_0}],\\ \text{TE} &= E[Y_{1,M_1}]-E[Y_{0,M_0}]. \end{aligned} $$

Here \(\text{NDE}(0)\) is the natural direct effect using the untreated mediator as the reference, and \(\text{NIE}(1)\) is the natural indirect effect with treatment set to 1. The total effect (TE) is the contrast between the two natural treatment regimes. These quantities add on the risk-difference scale; a different effect scale need not have the same additive decomposition.

Identification and the Standardization Formula

The observed joint distribution identifies these counterfactual risks only under causal assumptions. In the following formulas there are no baseline covariates; in applications with covariates, the relevant conditional risks and mediator probabilities must also be standardized over the covariate distribution.

Identification assumptions: Consistency means that a person receiving \(A=a\) has observed mediator \(M=M_a\), and a person with \(A=a\) and \(M=m\) has observed outcome \(Y=Y_{a,m}\). Treatment must be unconfounded for the mediator and outcome counterfactuals: \((M_a,Y_{a,m})\) is independent of \(A\). Within each treatment level, there must be no unmeasured mediator-outcome confounding: \(Y_{a,m}\) is independent of \(M\) conditional on \(A=a\). Identification of natural effects also requires the cross-world condition that \(Y_{a,m}\) is independent of \(M_{a'}\) for the relevant values of \(a,a'\), and \(m\). Finally, treatment and mediator positivity require positive probability of each treatment level and positive probability of each mediator value within each treatment level. These assumptions are not established merely by observing the joint distribution.

Write \(q_a(m)=P(M=m\mid A=a)\) for the observed mediator distribution under treatment \(a\), and \(r_{am}=P(Y=1\mid A=a,M=m)\) for the observed outcome risk in treatment-mediator group \((a,m)\). Under the assumptions above, the mediation formula gives

$$ E[Y_{a,M_{a'}}] = \sum_{m=0}^{1} P(Y=1\mid A=a,M=m)P(M=m\mid A=a') = \sum_{m=0}^{1} r_{am}q_{a'}(m). $$

The standardization is over the mediator distribution for \(a'\), while the outcome risks are taken from treatment group \(a\). That distinction is essential: changing which distribution is used for the weights changes the counterfactual risk being calculated.

A Short Justification

Because \(M_{a'}\) is binary, the natural counterfactual outcome can be partitioned according to whether \(M_{a'}=0\) or \(M_{a'}=1\). Taking expectations gives

$$ E[Y_{a,M_{a'}}] = \sum_{m=0}^{1} E[Y_{a,m}\,I(M_{a'}=m)], $$

where \(I(\cdot)\) equals 1 when its condition holds and 0 otherwise. The cross-world condition lets each term factor as \(E[Y_{a,m}]P(M_{a'}=m)\). Treatment exchangeability and consistency identify \(P(M_{a'}=m)\) as \(P(M=m\mid A=a')\). Mediator exchangeability and consistency identify \(E[Y_{a,m}]\) as \(E[Y\mid A=a,M=m]\). Since \(Y\) is binary, this conditional expectation is \(r_{am}\), yielding the standardization formula.

The additive decomposition follows by adding and subtracting the same intermediate counterfactual risk:

$$ E[Y_{1,M_1}]-E[Y_{0,M_0}] = \bigl(E[Y_{1,M_1}]-E[Y_{1,M_0}]\bigr) + \bigl(E[Y_{1,M_0}]-E[Y_{0,M_0}]\bigr). $$

The first bracket is \(\text{NIE}(1)\), and the second is \(\text{NDE}(0)\). The equality is arithmetic on the risk-difference scale, not a claim that effects must add on every scale.

Worked Example: Calculate All Three Effects From Joint Probabilities

Suppose a hypothetical population has the following conditional joint probabilities. Each cell is \(P(M=m,Y=y\mid A=a)\); thus, the four cells in either treatment column sum to 1.

Mediator \(M\)Outcome \(Y\)\(A=0\)\(A=1\)
000.360.15
010.040.15
100.360.175
110.240.525

First obtain the mediator probabilities by summing over outcome values. Under \(A=0\), \(q_0(0)=0.36+0.04=0.40\) and \(q_0(1)=0.36+0.24=0.60\). Under \(A=1\), \(q_1(0)=0.15+0.15=0.30\) and \(q_1(1)=0.175+0.525=0.70\).

Next calculate the outcome risks within each treatment-mediator group by dividing the \(Y=1\) cell by the mediator probability:

$$ \begin{aligned} r_{00}&=0.04/0.40=0.10, & r_{01}&=0.24/0.60=0.40,\\ r_{10}&=0.15/0.30=0.50, & r_{11}&=0.525/0.70=0.75. \end{aligned} $$

Standardize the treatment-1 outcome risks over the untreated mediator distribution to find \(E[Y_{1,M_0}]\):

$$ E[Y_{1,M_0}] =(0.50)(0.40)+(0.75)(0.60) =0.20+0.45=0.65. $$

The untreated natural risk is \(E[Y_{0,M_0}]=(0.10)(0.40)+(0.40)(0.60)=0.04+0.24=0.28\). The treated natural risk is \(E[Y_{1,M_1}]=(0.50)(0.30)+(0.75)(0.70)=0.15+0.525=0.675\). Therefore,

$$ \begin{aligned} \text{NDE}(0)&=0.65-0.28=0.37,\\ \text{NIE}(1)&=0.675-0.65=0.025,\\ \text{TE}&=0.675-0.28=0.395=0.37+0.025. \end{aligned} $$

Under the identifying assumptions, the natural direct effect is an increase of 37 percentage points in outcome risk when treatment changes from 0 to 1 while the mediator follows its untreated natural value. The natural indirect effect is an increase of 2.5 percentage points when the mediator distribution changes from its untreated to treated natural distribution while treatment is held at 1. The total natural-effect contrast is an increase of 39.5 percentage points. These are causal interpretations only if the assumptions hold.

Worked Example: Use the Other Reference Distribution

Using the same hypothetical joint distribution, calculate the alternative additive decomposition that uses the treated mediator distribution as the reference for the direct effect. The additional standardized risk is

$$ E[Y_{0,M_1}] =(0.10)(0.30)+(0.40)(0.70) =0.03+0.28=0.31. $$

The direct effect at the treated mediator distribution is \(E[Y_{1,M_1}]-E[Y_{0,M_1}]=0.675-0.31=0.365\), or 36.5 percentage points. The indirect effect at treatment 0 is \(E[Y_{0,M_1}]-E[Y_{0,M_0}]=0.31-0.28=0.03\), or 3 percentage points. Together they give \(0.365+0.03=0.395\), the same total effect as before.

The two decompositions use different intermediate risks: one holds the mediator to its untreated natural distribution when calculating the direct effect, and the other uses its treated natural distribution. The total contrast is unchanged, but the direct and indirect components need not be. Here they differ only slightly from the first decomposition; that is a feature of these hypothetical risks, not a general rule.

Worked Example: A Larger Indirect Risk Difference

Consider a second hypothetical population with this conditional joint distribution:

Mediator \(M\)Outcome \(Y\)\(A=0\)\(A=1\)
000.630.24
010.070.06
100.150.14
110.150.56

For \(A=0\), the mediator probabilities are \(q_0(0)=0.63+0.07=0.70\) and \(q_0(1)=0.15+0.15=0.30\). The outcome risks are \(r_{00}=0.07/0.70=0.10\) and \(r_{01}=0.15/0.30=0.50\). For \(A=1\), \(q_1(0)=0.24+0.06=0.30\), \(q_1(1)=0.14+0.56=0.70\), \(r_{10}=0.06/0.30=0.20\), and \(r_{11}=0.56/0.70=0.80\).

The standardized risks are

$$ \begin{aligned} E[Y_{0,M_0}]&=(0.10)(0.70)+(0.50)(0.30)=0.22,\\ E[Y_{1,M_0}]&=(0.20)(0.70)+(0.80)(0.30)=0.38,\\ E[Y_{1,M_1}]&=(0.20)(0.30)+(0.80)(0.70)=0.62. \end{aligned} $$

Thus \(\text{NDE}(0)=0.38-0.22=0.16\), \(\text{NIE}(1)=0.62-0.38=0.24\), and \(\text{TE}=0.62-0.22=0.40=0.16+0.24\). On the risk-difference scale, the natural direct and indirect effects are increases of 16 and 24 percentage points, respectively. The larger indirect component here reflects both a treatment-related shift in the mediator distribution and a difference in outcome risks across mediator values; the calculation itself does not establish that the assumptions are true.

Checks Before Interpreting the Results

A joint table is enough to calculate the standardized risks, but not enough to establish a causal interpretation. Before reporting natural effects, check that the data support all treatment and mediator groups used in the formula, and assess whether the no-unmeasured-confounding and cross-world assumptions are scientifically defensible. Positivity can be checked in observed data; the other causal assumptions generally require design knowledge and substantive argument.

Keep the two ingredients of each standardized risk separate. The outcome risk \(r_{am}\) comes from treatment level \(a\); the mediator weight \(q_{a'}(m)\) comes from the reference level \(a'\). For example, \(E[Y_{1,M_0}]\) uses treated outcome risks and untreated mediator probabilities. Substituting \(q_1(m)\) instead would calculate \(E[Y_{1,M_1}]\), not \(E[Y_{1,M_0}]\).

  • Using an observed group risk as a natural risk. The observed risk \(P(Y=1\mid A=a)\) averages over the mediator distribution observed at \(a\). It equals the corresponding natural risk \(E[Y_{a,M_a}]\) under consistency and treatment exchangeability, but it does not by itself provide a cross-treatment standardized risk such as \(E[Y_{1,M_0}]\).
  • Reversing the weights. In \(E[Y_{a,M_{a'}}]\), use outcome risks from \(A=a\) and mediator probabilities from \(A=a'\).
  • Forgetting the effect scale. The displayed additive decomposition holds for risk differences. Do not assume the direct and indirect risk differences add to a risk ratio or odds ratio.
  • Treating assumptions as verified by the table. A complete joint distribution permits arithmetic, but it cannot rule out unmeasured confounding or establish the cross-world condition.
Key takeaway: For a binary mediator and outcome, calculate each natural risk by weighting the outcome risks within treatment-mediator groups by the mediator distribution at the specified reference treatment. Contrasts of those risks give natural direct, indirect, and total effects, with causal interpretation dependent on the identification assumptions.

Check Your Understanding

Use the standardization formula and state which mediator distribution supplies the weights in each answer.

  1. If \(q_0(0)=0.25\), \(q_0(1)=0.75\), \(r_{10}=0.20\), and \(r_{11}=0.60\), calculate \(E[Y_{1,M_0}]\).
  2. In the first worked example, why is \(E[Y_{1,M_0}]\) not calculated using \(q_1(0)\) and \(q_1(1)\)?
  3. Using the first example, verify that \(\text{NDE}(0)+\text{NIE}(1)=\text{TE}\).
  4. Name one assumption needed to identify natural effects that cannot be confirmed merely by checking whether every cell in the observed joint distribution is positive.
  5. In words, distinguish the mediator distribution used for \(E[Y_{0,M_1}]\) from the treatment group used to obtain its outcome risks.
Clinical Biostats