Causal diagrams

Epidemiology guide, part 4

A regression model adjusts for whatever variables it is given, and it cannot tell a confounder from a mediator or a collider. That knowledge comes from outside the data: what causes what, and in what order. A directed acyclic graph (DAG) writes it down, so that the choice of adjustment variables follows from explicit assumptions that others can check and dispute (Greenland et al. 1999; Shrier and Platt 2008; Hernán and Robins 2020).

Reading a DAG

  • Each node is a variable; each arrow is a direct causal effect, in the direction of time.
  • The absence of an arrow is the strong assumption: no direct effect.
  • Acyclic: no variable causes itself through a loop. A variable measured at several times appears as several nodes.
  • Every common cause of two variables in the diagram must be in it, measured or not. Unmeasured ones are drawn too (dashed here).
  • A path is any sequence of arrows, whatever their direction. A causal path from X to Y follows the arrows; a backdoor path starts with an arrow into X.
  • A collider on a path is a node where two arrowheads meet (→ C ←).

Associations travel along paths. A path is open (it transmits association) unless it contains a collider, or a non-collider that has been adjusted for. Adjusting for a collider opens the path through it.

The kinds of variables

variable what it is adjust for it to estimate the total effect of X?
Confounder a common cause of X and Y (or lies on a backdoor path) yes: it opens a backdoor path X ← C → Y
Mediator caused by X, causes Y no: it carries part of the effect; adjusting gives the direct effect, which is a different question (Mediation)
Collider caused by X and by Y (or by their causes) no: adjusting, stratifying or selecting on it creates an association
Instrument causes X, affects Y only through X no: it adds no protection and inflates the variance; with unmeasured confounding it amplifies the bias
Precision variable causes Y, unrelated to X optional: it narrows confidence intervals (linear models) and changes OR/HR to their conditional value
Descendant of Y caused by the outcome no: it acts as a collider
Effect modifier the effect of X differs across its levels a result to report by level, not something to adjust away; a DAG does not show it

The M-bias panel shows the subtle case. B is associated with both X and Y, so the old “associated with exposure and outcome” rule would make it a confounder. But B is a collider of two unmeasured causes, and adjusting for it opens the path X ← U1 → B ← U2 → Y. Only the diagram tells the two situations apart.

Each kind of variable, worked

Small studies, one per kind of variable (two for confounders), each simulated with a few lines of code so that the true effect is known exactly. The outcome is always a continuous measure analysed with linear regression, so the estimates are easy to compare: a coefficient is the change in the outcome per unit of the exposure. Each table gives the true effect, the crude estimate and the estimate adjusted for the third variable, with 95% confidence intervals.

1. Confounder: coffee and blood pressure, confounded by smoking

Smokers drink more coffee, and smoking raises blood pressure. Coffee itself has no effect.

Figure 2: Smoking opens the backdoor path coffee ← smoking → SBP; there is no arrow from coffee to SBP.
estimate (95% CI)
true effect 0.00
crude 1.57 (1.29 to 1.85)
adjusted for smoking -0.18 (-0.51 to 0.15)

What adjusting does: the crude analysis finds about 1.5 mmHg per cup, all of it borrowed from smoking. Adjusting for the confounder closes the backdoor path and the estimate falls to the truth, zero.

1b. Negative confounder: salt and blood pressure, masked by age

Confounding does not always create an effect; it can also hide one. Salt raises blood pressure (+2 mmHg per g/day), and so does age (+0.45 mmHg per year). But younger people eat more salt, so people with a high salt intake are younger and, for that reason alone, have lower blood pressure.

Figure 3: Age lowers salt intake and raises blood pressure: the backdoor path salt ← age → SBP carries an association of the opposite sign to the effect.
estimate (95% CI)
true effect 2.00
crude 0.00 (-0.17 to 0.17)
adjusted for age 2.22 (1.99 to 2.44)

What adjusting does: the crude analysis finds no effect of salt at all; adjusting for age reveals it. The direction of confounding bias is the product of the signs of the confounder’s two arrows: here (age → salt: −) × (age → blood pressure: +) = −, so the crude estimate is pulled down, towards zero or past it. Two positive or two negative arrows exaggerate an effect (as smoking did for coffee); opposite signs mask it. A null crude association is therefore no reason to drop an exposure before adjusting.

2. Mediator: exercise and blood pressure, mediated by body mass index

Exercise lowers blood pressure directly (−1 mmHg per hour a week) and by lowering BMI (−0.8 kg/m² per hour, each kg/m² adding 1.2 mmHg). Its total effect is −1 + (−0.8 × 1.2) = −1.96 mmHg per hour.

Figure 4: BMI is on the causal path from exercise to blood pressure.
estimate (95% CI)
true total effect -1.96
true direct effect -1.00
crude -1.80 (-2.04 to -1.57)
adjusted for BMI -0.97 (-1.22 to -0.72)

What adjusting does: the crude estimate is the total effect. Adjusting for BMI removes the part that goes through it and leaves the direct effect. Both are correct answers to different questions; if the question is “how much does exercise lower blood pressure?”, do not adjust for BMI.

3. Collider: alcohol and depression, with hospital admission as collider

Alcohol intake and depression are unrelated here, but both make admission to hospital more likely. A study of inpatients, or a model that includes admission, conditions on the collider.

Figure 5: Admission is caused by both. Restricting to, or adjusting for, admitted patients (double border) links the two.
estimate (95% CI)
true effect 0.00
crude, everybody 0.03 (-0.05 to 0.10)
adjusted for admission -0.19 (-0.27 to -0.12)
only admitted patients -0.17 (-0.26 to -0.08)

Estimates per 10 g/day of alcohol. What adjusting does: in everybody there is no association. Among the admitted, a patient who drinks little must have been admitted for something else, depression for instance, so alcohol and depression appear negatively related. Adjusting for the collider creates bias where there was none (Berkson’s bias).

4. Instrument: walking and blood pressure, with dog ownership as instrument

Owning a dog makes people walk more and has no other effect on blood pressure (an instrument). Health consciousness, unmeasured, makes people walk more and lowers their blood pressure (an unmeasured confounder). Each 1,000 daily steps lowers systolic pressure by 1 mmHg.

Figure 6: The dog affects blood pressure only through walking; the confounder (dashed) is not measured.
estimate (95% CI)
true effect -1.00
crude -2.44 (-2.62 to -2.27)
adjusted for dog ownership -3.18 (-3.39 to -2.97)

What adjusting does: the crude estimate is confounded by health consciousness. Adjusting for the instrument makes it worse: it removes the part of walking explained by the dog, the part that was unconfounded, so the remaining variation in walking is more confounded (bias amplification), and the interval is wider. An instrument is not a confounder; it is useful in a different analysis (instrumental variable estimation), not as a covariate.

5. Precision variable: a drug and blood pressure, with entry blood pressure as precision variable

A randomised trial of an antihypertensive in 200 patients: the drug lowers pressure by 8 mmHg, and pressure at entry strongly predicts pressure at the end. Randomisation means entry pressure is not associated with the drug.

Figure 7: Entry blood pressure affects the outcome only: it cannot confound, but it explains much of the outcome’s variation.
estimate (95% CI)
true effect -8.00
crude (t-test) -7.02 (-10.97 to -3.07)
adjusted for entry BP (ANCOVA) -6.96 (-9.48 to -4.43)

What adjusting does: both estimates are unbiased; the adjusted one has a confidence interval about a third narrower, as if the trial were more than twice as large. Adjusting for strong predictors of the outcome is free precision, in trials and in observational studies. (With logistic or Cox models it also moves the odds or hazard ratio from marginal to conditional; see Measures and models.)

6. M-bias: physical activity and blood pressure, with supplement use as collider of two unmeasured causes

Physical activity lowers blood pressure (−1 mmHg per hour a week). Health awareness (unmeasured) increases activity and supplement use; a family history of hypertension (unmeasured) raises blood pressure and also leads to taking supplements. Supplement use is associated with activity and with blood pressure, but it is a collider of two causes that are otherwise unrelated.

Figure 8: Supplement use is associated with activity (through awareness) and with blood pressure (through family history), but it lies on no backdoor path: it is a collider.
estimate (95% CI)
true effect -1.00
crude -1.14 (-1.40 to -0.89)
adjusted for supplements -3.49 (-3.74 to -3.24)

What adjusting does: the crude estimate is right, because there is no backdoor path. Adjusting for supplement use opens the path activity ← awareness → supplements ← family history → blood pressure, and the estimate becomes more than three times the true effect. The rule “adjust for whatever is associated with exposure and outcome” fails here; only the diagram tells this case from confounding.

The six side by side

Figure 9: Crude and adjusted estimates (95% CI) in the six examples; the dashed line is the true effect (for the mediator, the total effect). Adjusting helps only for the confounders (bias removed, whether it exaggerated or masked the effect) and the precision variable (interval narrowed); for the mediator it changes the question, and for the collider, the instrument and M-bias it creates or worsens bias.

The same structures in studysim scenarios

Three of the structures again, now in the module’s own scenarios, with the answer key’s expected estimates.

Confounding (Coronary heart disease incidence, cohort): coffee has no effect, but smokers drink more coffee. The crude hazard ratio of coffee is above 1; adjusting for smoking removes it.

Variable Contrast True direct total Crude Adjusted (all) Adjusted (DAG) Estimate
age per 1 years HR 1.05 1.07 1.07 1.07 1.07 HR
sex male vs female HR 1.60 1.76 1.77 1.79 1.79 HR
smoking former vs never HR 1.20 1.21 1.21 1.20 1.21 HR
smoking current vs never HR 1.60 1.81 1.76 1.75 1.78 HR
coffee per 1 cups/day HR 1.00 1.00 1.08 1.01 1.01 HR

Mediation: sex acts on coronary disease partly through HDL. Adjusting for HDL gives the direct effect (1.60). Leaving it out gives the total effect (1.76). Neither is wrong; they answer different questions.

Collider (Lung cancer and smoking, case-control, Biases ▸ Add a variable caused by outcome and exposure): admitted is caused by lung cancer and by smoking. A model that includes it (Adjusted (all)) underestimates the effect of smoking; the diagram’s set leaves it out (Adjusted (DAG)).

Variable Contrast True direct total Crude Adjusted (all) Adjusted (DAG) Estimate
age per 1 years HR 1.09 1.09 1.09 1.09 1.09 OR
sex male vs female HR 1.20 2.46 2.70 1.25 2.72 OR
smoking former vs never HR 4.00 4.00 4.06 3.20 3.87 OR
smoking 1-14 vs never HR 7.70 7.70 8.09 6.20 7.63 OR
smoking 15-24 vs never HR 13.70 13.70 14.73 11.09 13.44 OR
smoking 25+ vs never HR 24.50 24.50 28.28 20.98 25.15 OR

Building a DAG for a study, step by step

The question: what is the effect of body mass index on the 10-year risk of coronary heart disease?

  1. Define the exposure, the outcome and time zero: BMI at entry, a coronary event in 10 years, follow-up from entry.
  2. Add the causes of the outcome you know of, measured or not: age, sex, blood pressure, cholesterol, HDL, diabetes, smoking.
  3. Add the causes of the exposure: age, physical activity; and the causes of those, such as education, which also affects smoking.
  4. Add every common cause of two variables already in the diagram, measured or not. A missing common cause is the most common error.
  5. Order by time, left to right, and decide for each arrow whether it can exist. BMI raises blood pressure, lowers HDL and causes diabetes: those three come after BMI and are mediators of its effect.
  6. Add how people got into the study and how variables were measured, when these could depend on exposure or outcome (selection, missing data, misclassification).
  7. Find the backdoor paths from BMI to coronary disease and a set of measured variables that blocks all of them without containing a descendant of BMI (the backdoor criterion). Software does this: dagitty.net or the R package dagitty (Textor et al. 2016).
  8. Check what you assumed: draw the alternative diagrams that colleagues would defend, and see whether the adjustment set changes.

Figure 10: The causal diagram of Coronary heart disease incidence built step by step for the effect of BMI. Blood pressure, HDL and diabetes are mediators. Age is a confounder, and physical activity (or education) blocks the backdoor path BMI ← activity ← education → smoking → CHD. Sex and cholesterol only affect the outcome (precision variables); coffee is irrelevant.

The backdoor paths from BMI are BMI ← age → … → CHD and BMI ← activity ← education → smoking → CHD. Adjusting for {age, activity} blocks both, and so does {age, education}. Adding sex and cholesterol is harmless. Adding blood pressure, HDL or diabetes is not: they are on the causal path, so the model would estimate only the part of BMI’s effect that does not go through them.

adjusted for HR per 5 kg/m2
none (crude) 1.42
age, physical activity (minimal set) 1.34
age, education (minimal set) 1.34
every variable BMI does not cause 1.35
everything, mediators included 1.12

In a simulated cohort of 60,000, every valid set gives about the true total effect, a hazard ratio of 1.33 per 5 kg/m². Adjusting for the mediators gives the direct effect, 1.1, which leaves out the part of BMI’s harm that works by raising blood pressure, lowering HDL and causing diabetes. The crude estimate is confounded.

The Table 2 fallacy

Papers often show one multivariable model with a coefficient for every variable (“Table 2”) and interpret each as that variable’s effect. Each coefficient is adjusted for all the others, including that variable’s mediators, and its confounders may be missing. Only the coefficient of the exposure the model was built for has the meaning intended (Westreich and Greenland 2013). In the CHD model with every variable, age’s coefficient is its direct effect (net of blood pressure, cholesterol and diabetes), and education seems to do nothing. In fact education acts through smoking and activity. studysim’s answer key shows both columns:

Variable Contrast True direct total Crude Adjusted (all) Adjusted (DAG) Estimate
age per 1 years HR 1.05 1.07 1.07 1.05 1.07 HR
sex male vs female HR 1.60 1.76 1.77 1.61 1.80 HR
education secondary vs primary HR 1.00 0.94 0.90 0.96 0.90 HR
education university vs primary HR 1.00 0.90 0.89 1.00 0.88 HR
physical_activity per 1 MET-h/week HR 1.00 0.99 0.99 1.00 0.99 HR
smoking former vs never HR 1.20 1.21 1.21 1.20 1.20 HR
smoking current vs never HR 1.60 1.81 1.76 1.79 1.79 HR
bmi per 1 kg/m2 HR 1.02 1.06 1.07 1.02 1.06 HR
sbp per 10 mmHg HR 1.18 1.18 1.34 1.17 1.17 HR
hdl per 1 mmol/L HR 0.60 0.60 0.41 0.60 0.60 HR
diabetes yes vs no HR 1.80 1.80 2.94 1.89 1.89 HR

Each exposure needs its own adjustment set, and often its own model.

Selection bias is conditioning on a collider

Figure 11: Selection as a collider (double border: the analysis is restricted to S). Left: hospital patients are admitted for the disease or for other conditions caused by smoking. Right: frail patients drop out more often when treated, and analysing only those followed links treatment and frailty.

Restricting a study to a group of people is conditioning on whatever put them in it. When getting in depends on the exposure and on the outcome (or its causes), the selection node is a collider, and the study finds an association that does not exist in the population (Hernán et al. 2004). The same structure explains biased hospital controls, informative losses to follow-up and analyses of complete cases. studysim builds these on purpose (Biases). Two more problems are diagrammed the same way: measurement error, a measured X* caused by X, and immortal time, a treatment that can only start among those who survive.

Choosing the adjustment set in practice

When the full diagram is uncertain, a practical rule (VanderWeele 2019):

  1. Adjust for every measured variable that causes the exposure, the outcome or both (pre-exposure).
  2. Leave out variables known to be instruments (they cause the exposure only).
  3. Add good proxies of unmeasured common causes.
  4. Never adjust for something caused by the exposure (a mediator) when the question is the total effect, nor for consequences of the outcome.

Then check: with how many events per parameter will the model be fitted? A large adjustment set in a small study is unstable (Measures and models). Prefer the smallest valid set, plus strong predictors of the outcome.

Figure 12: A rough path to an adjustment set for a total effect: variables that precede the exposure and cause it or the outcome are adjusted for, except pure instruments; variables caused by the exposure or by the outcome are not.

Effect modification is not in the diagram

A DAG shows which variables cause which, not how their effects combine. Two variables with arrows into Y may act additively, multiplicatively or only together, and the diagram looks the same. Effect modification is a feature of the effect of X, reported within levels of the modifier (Measures and models).

Exercises with studysim

  1. Coronary heart disease incidence, cohort, all variables measured. Fit the Cox model for BMI with {age, physical activity}, then with every variable. Compare with True (total), Adjusted (DAG) and Direct (conditional).
  2. Untick physical activity and education: which backdoor path is left open? How large is the residual confounding?
  3. Lung cancer and smoking, case-control, tick smoking under Exposure and add the collider. Draw the DAG with admitted and explain why adjusting for it underestimates the effect.
  4. Draw the DAG of a scenario from the catalogue from its teaching note, then switch on Causal diagram and compare.

References

Greenland, Sander, Judea Pearl, and James M. Robins. 1999. “Causal Diagrams for Epidemiologic Research.” Epidemiology 10 (1): 37–48. https://doi.org/10.1097/00001648-199901000-00008.
Hernán, Miguel A., Sonia Hernández-Díaz, and James M. Robins. 2004. “A Structural Approach to Selection Bias.” Epidemiology 15 (5): 615–25. https://doi.org/10.1097/01.ede.0000135174.63482.43.
Hernán, Miguel A., and James M. Robins. 2020. Causal Inference: What If. Chapman & Hall/CRC. https://miguelhernan.org/whatifbook.
Shrier, Ian, and Robert W Platt. 2008. “Reducing Bias Through Directed Acyclic Graphs.” BMC Medical Research Methodology 8 (1). https://doi.org/10.1186/1471-2288-8-70.
Textor, Johannes, Benito van der Zander, Mark S. Gilthorpe, Maciej Liśkiewicz, and George T. H. Ellison. 2016. “Robust Causal Inference Using Directed Acyclic Graphs: The r Package ‘Dagitty’.” International Journal of Epidemiology, January, dyw341. https://doi.org/10.1093/ije/dyw341.
VanderWeele, Tyler J. 2019. “Principles of Confounder Selection.” European Journal of Epidemiology 34 (3): 211–19. https://doi.org/10.1007/s10654-019-00494-6.
Westreich, D., and S. Greenland. 2013. “The Table 2 Fallacy: Presenting and Interpreting Confounder and Modifier Coefficients.” American Journal of Epidemiology 177 (4): 292–98. https://doi.org/10.1093/aje/kws412.