DAGs, Mediation & the Structural Causal Model
Python · from scratch + networkx · R · dagitty, ggdag, mediation · simulations with known effects
Which Variables Belong in the Model
Every page in this arc so far chose an estimator — matching, instrumental variables, a discontinuity, a policy date. None of them answered the question that comes first: which variables belong in the adjustment set at all? That question has a formal answer, and it is graphical.
A structural causal model is one equation per variable, each writing that variable as a function of its direct causes plus noise. Its directed acyclic graph draws an arrow from each cause to each effect. Pearl's do-operator, , is the distribution of under an intervention that sets — surgically deleting the arrows into — as against merely observing . The whole enterprise is to write the first using only quantities you can compute from the second.
The back-door criterion is the first rule: to identify the effect of on , adjust for a set that blocks every path from to beginning with an arrow into , without opening new ones. On a simulated fork — causing both and , with a true effect of 2 — the naive regression returns 3.48 and the adjusted one returns 2.00. That is not a new technique. It is unconfoundedness, the assumption the entire selection-on-observables group rests on, restated as a property of a picture.
The Control That Creates the Bias
Then the rule that runs the other way, and it is the reason this page exists. A collider is a common effect of two variables: . Along a path a collider is naturally blocked. Conditioning on it opens the path, manufacturing an association with no causal content whatever.
| regression | estimate | true effect | verdict |
|---|---|---|---|
Y ~ X | 1.98 | 2 | correct — the collider path is blocked |
Y ~ X + C | 0.50 | 2 | conditioning opened it |
The algebra gives exactly 0.5 for this design, so the miss is structural, not sampling noise.
Simulated with a true effect of 2, the correct regression gives 1.98 and adding the collider as a “control” gives 0.50 — a quarter of the truth, and the algebra says exactly 0.5, so this is structural rather than unlucky. Nothing about the output looks wrong. The coefficient is precise, the model fits better, and the estimate is off by a factor of four.
This is not a curiosity about a third variable. Selection into a sample is conditioning on a collider. Surviving to be surveyed, being admitted to hospital, remaining in a panel, appearing in an administrative file — each is a common effect of the things being studied, and each induces the same spurious association silently, in data that looks complete. The instinct that more controls are safer is not merely imperfect here; it is backwards, and no amount of care with standard errors detects it.
Identification Through a Mediator
Sometimes the back door cannot be closed at all. If an unobserved causes both and , no set of measured variables blocks the path. Pearl's front-door criterion recovers identification anyway, provided a mediator carries the whole effect, is not itself affected by , and has its own effect on unconfounded given . The effect is then chained through two identified pieces:
The motivating story is smoking → tar → cancer with an unobserved genetic confounder: the gene cannot be adjusted away, and the effect can still be identified through tar. Simulated with a true effect of , the naive regression gives 2.24 and the front-door estimate gives 1.246.
One note on what is actually computed. The displayed formula is a sum over ; the notebook evaluates the product . Those coincide in the linear-Gaussian case and only there — with a binary or nonlinear mediator the sum is what must be evaluated, and the product quietly stops being the same quantity.
And then the condition the criterion actually turns on. Front door requires that does not affect . That is a claim about an unobserved variable, so it cannot be checked — which makes its price worth knowing. Varying the arrow upward from zero:
| U → M strength | front-door estimate | error | naive Y ~ X |
|---|---|---|---|
| 0.0 criterion holds | 1.21 | +1% | 2.20 |
| 0.3 | 1.71 | +43% | 2.46 |
| 0.6 | 2.18 | +82% | 2.63 |
| 1.0 | 2.81 | +134% | 2.97 |
True effect 1.2 throughout. The estimator returns a number in every row.
A violation the size of the path itself puts the estimate 134% above the truth, and the direction matters: it slides back toward the naive value it was brought in to escape, reaching 2.81 against a naive 2.97. The estimator returns a number in every row and nothing in the data indicates which row you are in. The front door does not remove an untestable assumption; it exchanges one for another — often a more defensible one, which is a real gain, but a trade rather than an escape.
Through What Mechanism — and What the Experiment Does Not Buy
The last rule asks a different question: not whether affects but through what. Causal mediation splits the total effect into an indirect part running through the mediator — the ACME — and a direct part that does not. In the linear case the indirect effect is the product of the and paths. Simulated with a true direct effect of 0.50 and indirect of , the decomposition recovers 0.50 and 0.88, summing exactly to the total.
The decomposition rests on more than the experiment does, and this is the sharpest finding on the page. Randomizing identifies the total effect. It does not identify the split, which additionally requires no unobserved confounding of the mediator–outcome relationship — sequential ignorability. Adding a confounder of and while leaving randomized exactly as before:
| confounder strength | total | direct (ADE) | indirect (ACME) | M → Y coefficient |
|---|---|---|---|---|
| 0.0 assumption holds | 1.32 | 0.52 | 0.80 | 1.23 |
| 0.5 | 1.43 | 0.40 | 1.03 | 1.38 |
| 1.0 | 1.30 | 0.12 | 1.18 | 1.68 |
| 1.5 | 1.42 | 0.06 | 1.36 | 1.89 |
| truth | 1.34 | 0.50 | 0.84 | 1.20 |
X stays randomized in every row. Only the mediator–outcome relationship is confounded.
Read the total column first. It never moves more than 0.09 from the true 1.34, because was randomized and nothing about the confounder touches that. The experiment is fine. The mechanism story is not: the coefficient absorbs the confounder, climbing from 1.23 to 1.89, so the indirect effect inflates and the direct effect is pushed down to compensate — reaching 0.06 against a true 0.50, which is 87% of it gone.
At that point the output reads almost entirely mediated, and it is wrong: 37% of the true effect never passes through the mediator at all. This is the most transferable version of a pattern the arc keeps producing. A randomized experiment buys the total effect and nothing else. Every mechanism claim layered on top of it is observational, rests on an assumption the randomization did not purchase, and is printed in the same table with the same standard errors.
Two Languages, One Problem
Which makes the closing point of the whole arc available. DAGs and potential outcomes are two languages for one problem. The do-operator corresponds to the potential outcome ; d-separation in the graph corresponds to conditional independence in the data; and the back-door criterion is ignorability. They are not competing frameworks and the choice between them is not ideological. Graphs are better at encoding assumptions transparently and deriving what is identified from them; potential outcomes are better at defining estimands and estimators precisely. Back-door adjustment, instrumental variables and the front door are three graphically distinct identification strategies, and seeing that they are distinct is the thing that separates causal reasoning from tool use.
Where this sits
The back-door criterion formalises the assumption behind matching, and the collider warning explains why the variable-selection step for a propensity model must include confounders while excluding colliders and mediators — a distinction no fit statistic can make. The front door is a third identification route alongside instrumental variables and regression discontinuity, used when the back door is closed. And the next page inverts this one: here the graph was given and identification read off it; there the graph itself is learned from data.
Notebooks
References
- Pearl, J. (1995). Causal diagrams for empirical research. Biometrika 82(4), 702–710. — causal diagrams and the back-door criterion
- Greenland, S., Pearl, J. & Robins, J. M. (1999). Causal Diagrams for Epidemiologic Research. Epidemiology 10(1), 37–48. — the same, for applied work
- Imai, K., Keele, L. & Tingley, D. (2010). A general approach to causal mediation analysis. Psychological Methods 15(4), 309–334. — mediation, identified from the graph
- Baron, R. M. & Kenny, D. A. (1986). The moderator–mediator variable distinction in social psychological research: Conceptual, strategic, and statistical considerations. Journal of Personality and Social Psychology 51(6), 1173–1182. — the mediation method this replaces