Draw a causal DAG, spot confounders, mediators and colliders, and choose what to adjust for.
Why this matters
The whole point of randomised experiments is that they support causal conclusions: the treatment caused the difference. But many questions cannot be randomised. You cannot assign smoking, a customer's region, or which supplier a plant chose ten years ago. Analysts still have to say something about cause and effect from observational data, and most of the famous statistical blunders come from doing it carelessly. Causal inference gives you a disciplined way to state your assumptions and decide which variables to adjust for. The main tool is a simple picture: the directed acyclic graph (DAG).
Potential outcomes in one paragraph
For each unit, imagine two outcomes: Y(1) if treated and Y(0) if not. The causal effect is the difference, but you only ever see one of them; the other is a counterfactual. Randomisation solves this on average: treated and untreated groups are comparable, so the difference in group means estimates the average treatment effect. Without randomisation, the groups may differ in other ways, and those differences, not the treatment, may explain the outcome.
DAGs
A DAG is a diagram with an arrow from each cause to its effects, and no loops. You draw it from subject-matter knowledge before looking at the results.
Age
/ \
v v
Exercise --> Blood pressure
Three basic structures cover almost everything:
- Fork (confounder):
X <- Z -> Y. Z causes both. Example: age affects both exercise and blood pressure. The association between X and Y is partly spurious. Adjust for Z (include it in the model, stratify, or match on it). - Chain (mediator):
X -> M -> Y. The effect of X flows through M. Example: a training programme raises skill, which raises output. If you want the total effect of X, do not adjust for M; adjusting removes the part of the effect you care about. - Collider:
X -> C <- Y. C is caused by both. Example: a journal publishes papers that are either very novel or very rigorous. Among published papers (conditioning on C), novelty and rigour look negatively related even if they are unrelated in general. Do not adjust for C; doing so creates a spurious association (collider bias, also called selection bias).
The backdoor criterion
A backdoor path is any path from X to Y that starts with an arrow into X. These paths carry non-causal association. To estimate the effect of X on Y, adjust for a set of variables that:
- blocks every backdoor path, and
- contains no descendant of X (no mediators, no consequences of treatment).
A path is blocked by adjusting for a fork or chain variable on it, and it is blocked without adjustment if it passes through a collider that you leave alone.
Worked example
A materials lab finds that specimens annealed longer have lower hardness, and wonders whether annealing time should be cut. The DAG drawn with the process engineer:
Alloy grade --> Anneal time
Alloy grade --> Hardness
Anneal time --> Grain size --> Hardness
Anneal time --> Hardness
Hardness --> Passed QC
Anneal time --> Passed QC
- Alloy grade is a confounder: softer grades are annealed longer by procedure. Adjust for it.
- Grain size is a mediator. For the total effect of annealing time, leave it out. (Include it only if you want the direct effect not through grain size, which needs extra assumptions.)
- Passed QC is a collider (caused by both hardness and time). Analysing only specimens that passed QC would bias the result. Use all specimens.
The adjustment model is hardness ~ anneal_time + C(alloy_grade), not hardness ~ anneal_time + grain_size + ... on the QC-passed subset.
Simpson's paradox
A trend can reverse when you split by a confounder. Classic case: a treatment looks worse overall but better within every severity group, because the sickest patients were more likely to receive it. The DAG tells you which answer is right: if severity causes both treatment choice and outcome, the stratified (adjusted) comparison answers the causal question. If the splitting variable were a collider or mediator, the overall comparison would be the right one. Data alone cannot decide; the causal structure does.
Tools beyond adjustment
- Randomised experiments remain the gold standard when possible, including A/B tests.
- Matching and propensity scores balance measured confounders between groups.
- Difference-in-differences, regression discontinuity and instrumental variables use features of how treatment was assigned to handle some unmeasured confounding, under their own assumptions.
- Software: DAGitty (dagitty.net, free, in the browser) finds adjustment sets from a drawn DAG; in Python,
DoWhyimplements the same workflow.
All of these rely on assumptions you cannot fully test. State them, and do a sensitivity analysis: how strong would an unmeasured confounder need to be to explain away the result?
Common mistakes
- "Adjust for everything." Adding mediators or colliders introduces bias rather than removing it.
- Choosing covariates by p-value or by which ones change the estimate the most.
- Drawing the DAG after seeing the results to justify a preferred model.
- Using causal language ("increases", "leads to") for an analysis that only supports association, without stating the assumptions.
Quick recap
- Causal effects compare potential outcomes; randomisation makes groups comparable.
- DAGs encode assumptions: forks (adjust), chains (do not adjust for total effects), colliders (never adjust).
- Block all backdoor paths, avoid descendants of the treatment, and test sensitivity to unmeasured confounding.
Try it
This lesson's Do tab is a quiz: you will read small DAGs and pick the right adjustment set.