DAGs and Confounding
Directed acyclic graphs, backdoor criterion, collider bias
You observe that coffee drinkers have higher lung cancer rates. Should coffee drinkers stop? Probably not — because smoking confounds the relationship. Smokers both drink more coffee and have higher cancer rates. The Coffee → Cancer association is a spurious path through the confounder Smoking. Without a way to represent this structure, you would add "coffee drinker" as a control variable in a cancer regression and be satisfied. But whether that controls for the right thing, blocks the wrong thing, or introduces new bias depends entirely on the causal structure — and the regression output will not tell you which case you are in.
Directed Acyclic Graphs (DAGs) make that structure explicit. Nodes are variables. Directed arrows are direct causal claims. Three path types determine which variables to condition on. A confounding path runs Smoking → Coffee AND Smoking → Cancer: the backdoor path Treatment ← Confounder → Outcome. It must be blocked — condition on the confounder. A mediation path runs Treatment → Mediator → Outcome: the indirect causal channel. Conditioning on the mediator blocks the path you want to measure, isolating only the direct effect. Example: suppose a training program (T) raises quiz scores (Y) partly by increasing study hours (M) — a total effect of +12 points made up of a +9-point direct effect and a +3-point effect that runs through study hours. Control for study hours and the regression recovers only the +9-point direct effect, silently dropping the +3 points that ran through the mediator — a 25% understatement of the true total effect. That understatement only happens when the direct and mediated pieces share the same sign, as they do here; if they have opposite signs (suppression — say the program hurts scores directly but raises study hours enough to help overall), conditioning on the mediator can overestimate the total effect or flip its sign instead, because you have kept the piece that opposes the total rather than the whole picture. Either way, if the total effect is what you are measuring, leave the mediator out. A collider is caused by two otherwise-unconnected variables: A → Collider ← B. Conditioning on the collider opens a spurious path between A and B that was never causally present. Classic collider bias: conditioning on hospitalization (collider of disease severity and treatment choice) creates spurious correlation between diseases and treatments within the hospitalized sample.
The backdoor criterion formalizes this. If you can find a set Z that blocks all backdoor paths (confounding paths from Treatment to Outcome) without blocking any frontdoor paths and without containing any descendant of Treatment, you can identify the causal effect by conditioning on Z.
Sometimes you cannot block the backdoor path at all because the confounder is unmeasured. The frontdoor criterion handles that narrower case: if every Treatment → Outcome path routes through a single mediator M, and that mediator is itself unreachable from the unmeasured confounder, you can identify the effect by chaining two adjustments through M instead of one adjustment on the confounder. The canonical case is smoking, tar deposits, and lung cancer: an unmeasured genetic confounder might affect both smoking and cancer directly, so you cannot block that backdoor path with observed data — but if smoking's entire effect on cancer runs through tar deposits in the lungs, and the confounder does not reach tar directly, you can still identify the smoking effect by combining P(tar | smoking) with P(cancer | tar). This requires the mediator to carry the whole treatment effect and to sit outside the confounder's reach — a narrower condition than the backdoor criterion's, which is why frontdoor adjustment is rare in practice but valuable exactly when the confounder cannot be measured.
What this is not: "control for everything." Controlling for a collider creates bias where none existed before. Controlling for a mediator blocks the path you want to measure. Controlling for a post-treatment variable that is a descendant of Treatment can do both. You need the DAG to know which variables to condition on and which to leave out. A "control for everything" strategy without a DAG is a systematic way to introduce collider bias while believing you removed confounding.
Key points
- Draw the DAG before selecting control variables in any regression. Identify the backdoor paths (confounding) and frontdoor paths (mediation). Control for variables that block backdoor paths. Do not control for mediators or colliders. A 10-minute DAG review prevents hours of debugging spurious results — the regression will run and return a coefficient regardless of whether the conditioning set was correct.
- Trap: conditioning on a descendant of treatment (post-treatment variable). A variable caused by the treatment is either a mediator or a collider of treatment and a confounder. Including it as a control blocks the causal path you want (mediator) or opens a spurious path you do not want (collider). Always verify whether each control variable was determined before or after treatment assignment, and trace its arrows in the DAG before including it.
- Diagnostic: if adding a control variable changes your effect estimate by more than 50%, either you have added a strong confounder (expected, good) or introduced collider bias (bad). Draw the DAG and determine which case applies. If the variable has arrows coming in from both Treatment and Outcome, it is a collider — removing it from the control set is the correct response, not refining the model further. Worked example: a naive coffee-cancer regression gives a coffee coefficient of 0.40 log-odds; adding smoking as a control drops it to 0.09 log-odds, a (0.40 − 0.09) / 0.40 ≈ 78% shift — consistent with smoking being the confounder that was inflating the naive estimate. Contrast that with adding hospitalisation status to a drug-mortality regression: the drug coefficient swinging from −0.05 to +0.35 log-odds after conditioning on a variable caused by both drug use and outcome severity clears the same "more than 50%" bar, but there it is the collider-bias pattern, not a newly found confounder — the DAG, not the size of the shift alone, tells you which case you are in.
Which variables you control for is a causal decision, not a statistical one — the regression cannot tell you whether your conditioning set was right, only what coefficient it produces given that set.
Recap
- DAGs make causal structure explicit: nodes are variables, directed arrows are direct causal claims — and which variables you condition on is a *causal* decision the regression output can never tell you, because it returns a coefficient regardless of whether your conditioning set was right.
- Confounder (e.g. Smoking → Coffee and Smoking → Cancer): creates a backdoor path Treatment ← Confounder → Outcome that produces a *spurious* association — you must *block* it by conditioning on the confounder.
- Mediator (T → M → Y): sits on the causal path you're trying to measure, so conditioning on it *blocks* that path and isolates only the direct effect — this *underestimates* the total effect when the direct and mediated pieces share a sign (the usual case, e.g. the +9/+3-point study-hours example above), but can *overestimate* it or flip its sign under suppression (opposite signs) — either way, the opposite of what you want if the total effect is your target.
- Collider (A → C ← B, caused by both): conditioning on it *opens* a spurious path between A and B that was never causally there — e.g. conditioning on hospitalisation (a collider of disease severity and treatment) manufactures correlations within the hospitalised sample.
- Backdoor criterion: you identify the effect by conditioning on a set Z that blocks all backdoor (confounding) paths, blocks no frontdoor (mediating) paths, and contains no descendant of the treatment.
- Frontdoor criterion (narrower, for when the confounder is unmeasured): if a mediator M carries the *entire* Treatment → Outcome effect and sits outside the confounder's reach, you can identify the effect by chaining P(M | Treatment) with P(Outcome | M) instead of adjusting for the confounder directly — the smoking → tar → cancer case is the canonical example.
- "Control for everything" is a mistake, not a safe default: it systematically opens collider bias and blocks mediators while you believe you're removing confounding — you need the DAG to know which variables to include and which to leave out.
- Diagnostic: if adding a control shifts the estimate by more than ~50%, it's either a real confounder (good — expected) or a collider you just opened (bad) — draw the DAG to tell which. Arrows coming *into* it from both T and Y = collider, remove it. (See the worked coffee/hospitalisation example above: a genuine ~78% shift toward a smoking confounder looks very different from a sign-flipping collider swing.)
Check your understanding
Q1. You want to estimate the effect of exercise (T) on heart disease (Y). You have data on body weight (W). Select the two true statements about how to handle W.
- A) If W is a confounder — say W→T and W→Y both hold — you must control for W to block that backdoor path, otherwise the exercise-heart disease estimate stays biased by body weight
- B) If W instead sits on the causal path as a mediator, T→W→Y, then controlling for W blocks the indirect channel and yields only the direct effect — omit W if the total effect is what you actually want
- C) W should never be controlled for in either DAG, because body weight always functions as a collider between exercise and heart disease and conditioning on it opens a spurious backdoor path
- D) The correct approach is to control for W only when its regression coefficient clears statistical significance at the 0.05 level, and to drop it from the model whenever it does not
Q2. A researcher conditions on 'hospitalisation status' when studying the effect of a drug on mortality. Why might this create collider bias?
- A) Conditioning on hospitalisation is always valid because it guarantees comparability — patients admitted to the same hospital are assumed to share identical unmeasured severity confounders purely by construction of the admission process
- B) Hospitalisation actually functions as a confounder rather than a collider here: it causes both drug use and mortality directly, so failing to condition on it is what creates the bias in the first place
- C) Hospitalisation status introduces classic measurement error, since non-hospitalised patients have missing mortality records, which biases the estimated drug effect downward toward zero
- D) Hospitalisation is caused by illness severity and drug decision, making it a collider — conditioning on it opens a spurious negative path, making the drug look more harmful than it is, as in COVID studies restricted to hospitalised patients
Q3. What is the difference between the backdoor criterion and the frontdoor criterion, and when would you use the frontdoor criterion?
- A) Backdoor adjusts for common causes of T and Y directly. Frontdoor applies when a mediator M exists where all T→Y paths route through M — smoking→tar→cancer is the classic example, rare but powerful
- B) The backdoor criterion applies only to DAGs containing exactly one confounder, and the frontdoor criterion generalizes it to handle multiple confounders at once, so frontdoor should always be the preferred safer default choice
- C) The frontdoor criterion is invoked whenever there are simply too many confounders to feasibly measure in a study, and it works by conditioning directly on the outcome variable itself to isolate the treatment's direct effect
- D) The two criteria are mathematically equivalent to one another — frontdoor is nothing more than a computational shortcut for applying ordinary backdoor adjustment once the required adjustment set becomes too large to estimate reliably
Q4. A researcher wants to know whether years of experience affects performance rating, so they regress performance rating on experience while using salary as a control variable. They find a strong negative coefficient on experience — more experienced employees appear to have systematically lower performance ratings once salary is held fixed. Should they trust this?
- A) Yes — the model is well-specified, since including any variable correlated with both the predictor and outcome always tightens the estimate
- B) No — salary is a collider here (Experience → Salary ← Performance, since both experience and performance cause salary), so holding salary fixed as a control while relating experience to performance opens a spurious path between them and can manufacture a negative association even if experience and performance are unrelated or genuinely positively related
- C) No — the regression direction is simply backwards; performance should be predicting experience, not the other way around, so the coefficient's sign is meaningless
- D) Yes — the negative coefficient is expected because senior employees face regression to the mean in performance ratings, a statistical artifact unrelated to the choice of controls
Try it interactively
ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.
Open ML Systems Lab →