Skip to content
AI360XpertBeta

Causal Graphs

A causal graph draws arrows for what causes what, so you know which variables to adjust for and which to leave alone to get the true effect.

A DAG where soil quality confounds fertilizer and yield, so blocking the backdoor turns a 50 point raw gap into a 20 point causal effect
A DAG where soil quality confounds fertilizer and yield, so blocking the backdoor turns a 50 point raw gap into a 20 point causal effect

Why Does This Exist?

Regression tempts you to control for everything you measured. That kitchen sink reflex feels safe, yet it can manufacture bias from clean data.

Take fertilizer and yield. In the 100 plot example used on this page, treated plots show 80 percent high yield against 30 percent for untreated plots. The raw 50 point gap looks like a triumph. Most of it is soil. Good soil pushes farmers to fertilize and pushes plants to grow, so the treated and untreated groups never start level. Without a map of those arrows you cannot tell which part of the gap is cause and which part is background.

This page gives you that map. You will learn the node and arrow notation, the backdoor rule that picks the adjustment set, and the hand computed correction that shrinks the 50 point raw gap to a 20 point causal effect. Correlation vs causation explains why the raw gap misleads in the first place, confounding and colliders zooms into the two junctions you must treat in opposite ways, and A/B testing is the sequel for when no adjustment set can rescue the observational data.

Think of It Like This

Irrigation valves

You water two beds from one pump house. Valve T feeds fertilizer to the test bed, and bucket Y is the harvest you weigh at the end. A shared rain pipe feeds both the fertilizer tank and the soil, so wet weeks bring more fertilizing and heavier buckets even if the fertilizer did nothing. Downstream, both a fertilizer run and a heavy harvest make you snap a photo for the farm log.

The graph is the plumbing blueprint. Rain is the confounder, so you shut its valve by comparing wet weeks to wet weeks and dry weeks to dry weeks. The photo log is the collider, with two pipes pouring into it, so judging the pump from photo days only reopens a path you had closed. You leave that valve open.

Where it stops: pipes do not choose, hide, or misreport. Real arrows are claims about biology and behavior, and one missing pipe on your blueprint still ruins the estimate even when the valve logic is perfect.

How It Actually Works

A causal graph is a directed acyclic graph, called a DAG. Each node is a variable. Each arrow A→BA \rightarrow B says changing AA changes BB through that direct link. Acyclic means you can never follow arrows forward and return to where you started, because causes come before effects. Write TT for the treatment (fertilizer yes or no), YY for the outcome (high yield yes or no), ZZ for a third variable such as soil quality, CC for a downstream variable such as posting a farm photo, and do(T=t)do(T=t) for the intervention that forces treatment to value tt.

Correlation can travel against the arrows. The path T←Z→YT \leftarrow Z \rightarrow Y connects treatment and outcome through their shared cause even when TT does nothing to YY. That is a backdoor path, and it is why the raw contrast P(Y∣T=1)−P(Y∣T=0)P(Y \mid T=1) - P(Y \mid T=0) mixes causation with background imbalance.

The three junctions you must recognize

Every path is built from three junctions. A chain A→B→CA \rightarrow B \rightarrow C carries flow unless you condition on the middle BB. A fork A←B→CA \leftarrow B \rightarrow C carries flow unless you condition on the middle BB, which is the confounder case. A collider A→B←CA \rightarrow B \leftarrow C blocks flow by default, and conditioning on the middle BB opens it. That last line is the trap. Two independent causes look linked once you filter on their shared consequence. A path is d-separated, meaning blocked, when every junction on it is blocked under the rule above.

Worked example: 50 points raw, 20 points causal

Fix 100 plots with one confounder, soil quality. There are 50 good soil plots and 50 poor soil plots, so P(Z=good)=0.5P(Z=\text{good}) = 0.5.

Treatment follows soil:

  • Good soil: 40 treated, 10 control, so P(T=1∣Z=good)=0.8P(T=1 \mid Z=\text{good}) = 0.8.
  • Poor soil: 10 treated, 40 control, so P(T=1∣Z=poor)=0.2P(T=1 \mid Z=\text{poor}) = 0.2.

Yield follows both:

  • Good soil, treated: 36 of 40 high, so P(Y=1∣T=1,Z=good)=0.9P(Y=1 \mid T=1, Z=\text{good}) = 0.9.
  • Good soil, control: 7 of 10 high, so P(Y=1∣T=0,Z=good)=0.7P(Y=1 \mid T=0, Z=\text{good}) = 0.7.
  • Poor soil, treated: 4 of 10 high, so P(Y=1∣T=1,Z=poor)=0.4P(Y=1 \mid T=1, Z=\text{poor}) = 0.4.
  • Poor soil, control: 8 of 40 high, so P(Y=1∣T=0,Z=poor)=0.2P(Y=1 \mid T=0, Z=\text{poor}) = 0.2.

Pool everything and the confounder does the talking. Treated plots total 50 with 40 high, so:

P(Y=1∣T=1)=40/50=0.80P(Y=1 \mid T=1) = 40 / 50 = 0.80

Control plots total 50 with 15 high, so:

P(Y=1∣T=0)=15/50=0.30P(Y=1 \mid T=0) = 15 / 50 = 0.30

The raw gap is 0.80−0.30=0.500.80 - 0.30 = 0.50, a 50 point gap. The diagram draws this pair as the unadjusted bars.

The backdoor fix stratifies, then averages with population weights:

P(Y=1∣do(T=t))=∑zP(Y=1∣T=t,Z=z)P(Z=z)P(Y=1 \mid do(T=t)) = \sum_z P(Y=1 \mid T=t, Z=z) P(Z=z)

Forcing fertilizer on everyone gives:

P(Y=1∣do(T=1))=0.9×0.5+0.4×0.5=0.45+0.20=0.65P(Y=1 \mid do(T=1)) = 0.9 \times 0.5 + 0.4 \times 0.5 = 0.45 + 0.20 = 0.65

Forcing no fertilizer gives:

P(Y=1∣do(T=0))=0.7×0.5+0.2×0.5=0.35+0.10=0.45P(Y=1 \mid do(T=0)) = 0.7 \times 0.5 + 0.2 \times 0.5 = 0.35 + 0.10 = 0.45

The causal effect is 0.65−0.45=0.200.65 - 0.45 = 0.20, a 20 point lift. Same plants, same fertilizer, honest comparison. The 30 missing points were soil imbalance riding along the backdoor path T←Z→YT \leftarrow Z \rightarrow Y.

The backdoor rule that licenses the math

A set ZZ earns adjustment when it meets two checks. No member of ZZ is caused by TT, so you never adjust for mediators or colliders downstream of treatment. And ZZ blocks every backdoor path into TT, so no spurious route stays open. Here soil quality passes both: it precedes fertilizer and it sits on the one backdoor path. The photo log fails the first check because fertilizer and yield both cause it, and adjusting for it would reopen T→C←YT \rightarrow C \leftarrow Y. When no observed set passes both checks, the effect is not identified by adjustment, and that is the signal to run an experiment instead.

Code

The point is the check: rebuild the 100 plot table, confirm the 80 versus 30 raw split, then confirm the 65 versus 45 adjusted split and the 20 point effect.

good_n: int = 50poor_n: int = 50
good_treated: int = 40good_control: int = 10poor_treated: int = 10poor_control: int = 40
good_treated_high: int = 36good_control_high: int = 7poor_treated_high: int = 4poor_control_high: int = 8
treated_high: int = good_treated_high + poor_treated_highcontrol_high: int = good_control_high + poor_control_hightreated_n: int = good_treated + poor_treatedcontrol_n: int = good_control + poor_control
raw_treated: float = treated_high / treated_nraw_control: float = control_high / control_nraw_gap: float = raw_treated - raw_control
p_z_good: float = good_n / (good_n + poor_n)adj_treated: float = 0.9 * p_z_good + 0.4 * (1.0 - p_z_good)adj_control: float = 0.7 * p_z_good + 0.2 * (1.0 - p_z_good)causal_gap: float = adj_treated - adj_control
print(f"{treated_high}/{treated_n} {control_high}/{control_n}")  # -> 40/50 15/50print(f"{raw_treated:.2f} {raw_control:.2f} {raw_gap:.2f}")  # -> 0.80 0.30 0.50print(f"{adj_treated:.2f} {adj_control:.2f} {causal_gap:.2f}")  # -> 0.65 0.45 0.20

The printout matches the hand computation: 40 of 50 treated high and 15 of 50 control high for the 50 point raw gap, then 0.65 against 0.45 for the 20 point causal effect.

Watch Out For

Kitchen sink adjustment reopens blocked paths

Symptom: you add every column to the regression, including a post treatment survey flag or a photo log like CC, and the estimated lift swings or flips sign while prediction accuracy improves. Fix: draw each candidate before adding it, adjust only for pre treatment shared causes such as ZZ, and never condition on a collider or a mediator when you want the total effect.

The needed confounder was never measured

Symptom: the graph says soil quality blocks the backdoor path, but your table has no soil column, so treated and control plots stay unbalanced however you slice the observed features. Fix: admit the effect is not identified by adjustment, collect the missing cause, or switch to randomization in A/B testing instead of trusting the biased contrast.

The Quick Version

  • A causal graph is a DAG where each arrow A→BA \rightarrow B claims that changing AA changes BB.
  • Backdoor paths such as T←Z→YT \leftarrow Z \rightarrow Y create correlation without causation and must be blocked.
  • Chains and forks stay open until you condition on the middle, while colliders such as T→C←YT \rightarrow C \leftarrow Y stay blocked until you condition on the middle.
  • In the 100 plot example the raw split is 40 of 50 against 15 of 50, a 50 point gap that overstates the effect.
  • Backdoor adjustment reweights by soil mix to 0.65 against 0.45, a 20 point causal effect for forcing fertilizer.
  • Never adjust for a downstream collider or mediator when you want the total effect, and randomize when the blocking variable was never measured.