Causal Inference and Counterfactual Reasoning
Causal Graphs and Confounding · 15 min
Judea Pearl's 2009 survey "Causal Inference in Statistics: An Overview" frames the central idea of causal graphs plainly: in such a diagram, "arrows are drawn from (perceived) causes to their (perceived) effects, and more importantly, the absence of an arrow makes the empirical claim that Nature assigns values to one variable irrespective of another". Formally these are directed acyclic graphs (DAGs): each node is a variable, each directed edge represents a claim of direct causal influence, and the graph structure encodes a set of assumptions about which variables affect which others — assumptions that go beyond anything observed correlations alone could establish. The Stanford Encyclopedia of Philosophy's entry on causal models notes that the graph's structure connects to statistical independence through the Markov Condition and the related notion of d-separation, linking the purely causal claims encoded by the arrows to testable patterns of (conditional) independence in observed data.
A classic worked example shows why the graph matters, not just the raw correlation. Suppose a variable Z (season) causally influences both X (ice cream sales) and Y (drowning incidents) — hot weather drives both — while X does not causally influence Y at all. Observationally, X and Y will still be strongly correlated, because both rise and fall together with Z, even though buying ice cream does not cause anyone to drown. Z here is a confounder: a common cause of both the purported "treatment" and the "outcome" that creates a spurious association if ignored. Pearl's back-door criterion gives a graph-based rule for identifying which variables must be statistically adjusted for (in this case, Z) to strip out confounding and isolate whatever causal effect X may or may not actually have on Y.
This distinction is not academic hair-splitting for AI systems: any model trained on purely observational data — a hospital record, a clickstream log, a loan-approval history — risks learning confounded associations rather than genuine causal relationships, and will make systematically wrong recommendations whenever it is used to guide an intervention (recommending a treatment, a product, or a policy) rather than merely to predict an outcome that would have happened anyway regardless of the recommendation. Recognizing that "correlation is not causation" is a well-worn slogan; causal graphs are what let that slogan be turned into a precise, checkable diagram of exactly which variables must be controlled for, and why, rather than leaving the analyst to guess at which confounders might be lurking in the data. A model that merely predicts well on observational data can still be a poor guide to action, which is precisely the gap causal inference is designed to close.
Interventions and Counterfactual Reasoning · 15 min
Pearl's framework distinguishes sharply between observing a variable and intervening on it. The Stanford Encyclopedia of Philosophy's entry on causal models explains that "when intervening on a variable, one 'breaks the arrows' pointing into it," overriding whatever process normally determines that variable's value and forcing it to a chosen value instead — formalized through Pearl's do-operator, so that P(Y | do(X=x)) denotes the distribution of Y that would result from actively setting X to x, which is generally different from the merely observational P(Y | X=x). In the ice-cream/drowning example from Lesson 1, P(drownings | ice cream sales = high) is elevated because high sales are correlated with hot weather, but P(drownings | do(ice cream sales = high)) — the effect of an outside agent forcing ice cream sales up regardless of season — would show essentially no change, since forcing X does not touch the confounder Z or the causal pathway to Y.
This intervention concept underlies the average treatment effect (ATE), defined as E[Y | do(X=1)] − E[Y | do(X=0)]: the expected outcome difference from actively intervening to set treatment to "on" versus "off" for the same population, not the naive difference in observed outcomes between whoever happened to receive treatment and whoever did not. A small worked illustration: suppose four patients have treatment status and recovery scores (1=drug, score 0–10): patient 1 (treated, score 8), patient 2 (treated, score 6), patient 3 (untreated, score 4), patient 4 (untreated, score 5). The naive observed difference is 7.0 − 4.5 = 2.5, but if sicker patients were more likely to be given the drug in the first place (a confounder — severity — driving both treatment assignment and outcome), this naive gap conflates the drug's real causal effect with the fact that whoever received it differed systematically from whoever didn't, which is exactly why estimating ATE properly requires adjusting for such confounders rather than simply comparing group averages.
Counterfactual reasoning pushes one step further, asking not just about populations but about a specific individual: Pearl defines a unit-level structural counterfactual as "the value of Y in unit u, had X been x" — what would have happened to this particular patient, this particular loan applicant, had one fact about their situation been different, holding everything else about that unit fixed. The Stanford Encyclopedia entry notes that these structural counterfactuals differ from the Lewis-Stalnaker counterfactuals developed in philosophy by disallowing "backtracking" — reasoning from a changed effect back to a changed cause — since a structural counterfactual only ever propagates forward along the causal graph's arrows. This exact formalism now underlies "counterfactual explanation" methods in explainable AI, which answer a loan applicant's question "what would have to change about my application for it to be approved?" by computing precisely this kind of structural counterfactual.
Causal Graph at a Glance
Z (season) confounds the observed X–Y correlation by causing both ice cream sales and drownings, even with no direct causal arrow from X to Y.
- In a causal DAG, the absence of an arrow is itself a claim — that one variable does not directly cause the other.
- A confounder is a common cause of both the 'treatment' and the 'outcome,' and it can produce a strong correlation with zero true causal effect.
- Structural counterfactuals only propagate forward along the graph's arrows, unlike some philosophical accounts of counterfactuals that allow backtracking from effect to cause.
Recall Practice
Glossary
- Causal DAG
- A directed acyclic graph in which each edge represents a claim of direct causal influence, and absence of an edge claims no direct causal effect.
- Confounder
- A variable that is a common cause of both a purported treatment and outcome, capable of producing a spurious correlation between them.
- Back-Door Criterion
- Pearl's graph-based rule for identifying which variables must be statistically adjusted for to remove confounding bias when estimating a causal effect.
- do-operator
- Notation, do(X=x), representing an active intervention that sets X to x by 'breaking' the arrows into X, as opposed to merely observing X=x.
- Average Treatment Effect (ATE)
- E[Y | do(X=1)] − E[Y | do(X=0)], the expected outcome difference from actively intervening to set treatment on versus off.
- Structural Counterfactual
- The value an outcome would have taken for a specific unit had one variable been different, propagated forward along the causal graph without backtracking.
Tracing Confounding on a Supplied Causal DAG
This is a virtual, paper-based reasoning exercise using a small supplied causal DAG (three or four nodes and arrows, given as a diagram — not real patient or user data). Learners identify which variable is the confounder, state which variable(s) must be adjusted for using the back-door criterion, and reason through the difference between the observational and interventional (do-operator) queries on the supplied graph.
Ready to test yourself?
5 questions on this module.