Skip to content
AI360XpertBeta

Confounding and Colliders

A confounder feeds both treatment and outcome, so you must adjust for it. A collider is fed by both, so adjusting for it creates bias.

Twelve coffee drinkers show a 16.7 point crude gap that vanishes once smoking is fixed, while fame filtering turns independent talent and beauty negative
Twelve coffee drinkers show a 16.7 point crude gap that vanishes once smoking is fixed, while fame filtering turns independent talent and beauty negative

Why Does This Exist?

Your model aces the training split, then flops the moment you act on it. That gap is often not overfitting. It's the wrong adjustment: you left a shared cause out, or you let a shared consequence in.

Predictive models love extra columns. Causal questions punish them. Add a shared cause and you leave bias in. Add a shared consequence and you manufacture bias from clean data. On this page you'll see both directions with hand counted tables: a 16.7 point coffee gap that's all smoking, and an 8 person talent table where filtering on fame invents a 50 point beauty gap.

This page teaches the two junctions and the opposite fix for each. Causal graphs is the full map with the backdoor rule. Correlation vs causation explains why the raw contrast misleads in the first place. From here, propensity score methods show which list belongs in the adjustment, and randomized experiments show what to do when the needed cause was never measured.

Basics first: a causal graph draws one arrow for each direct effect, like smoking toward heart trouble. Treatment TT means the exposure you could change, outcome YY means the result you measure, third variable ZZ means any other cause that comes first, and CC means a downstream consequence both can cause. If you can read those four letters, the rest is bookkeeping.

Think of It Like This

Rainy Saturday and yearbook picks

You notice puddles and umbrella sightings move together on Saturdays. Rain drives both: it fills the puddles and it sends people out with umbrellas. Umbrellas do not cause puddles. Compare rainy days to rainy days and dry days to dry days and the link collapses. Rain is the confounder ZZ, pavement wetness is TT, umbrella sales are YY.

Now picture yearbook picks. Staff pick a student who has great grades or a great jump shot. Among picked kids, grades and jump shots look traded off. Meet a picked kid with average grades and you would bet they can shoot, since something got them picked. Neither causes the other. Filtering on the pick, the collider CC, manufactured the link. The fix is to stop filtering, not to adjust harder.

Where it stops: rain does not choose friends, hide income, or misreport habits. Real causes do all three. The valve logic still holds, but one missing arrow on your graph still ruins the estimate even when the comparison logic is perfect.

How It Actually Works

A causal graph is a directed acyclic graph, called a DAG. Each node is a variable and each arrow A→BA \rightarrow B says changing AA changes BB through that direct link. Acyclic means you can never follow arrows forward back to the start. P(Y∣T=t)P(Y \mid T=t) means the share of outcome among those observed with treatment tt, while P(Y∣do(T=t))P(Y \mid do(T=t)) means the share if you forced everyone to tt. You want the second, but the data hand you the first.

The fork that fakes an effect

A fork T←Z→YT \leftarrow Z \rightarrow Y stays open by default. Correlation travels against the arrows: TT and YY move together through their shared cause even when TT does nothing to YY. That open route is a backdoor path.

You close it by conditioning on ZZ, meaning compare treated and control within each level of ZZ, then average 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)

Here Z=zZ=z means one stratum such as smokers, P(Z=z)P(Z=z) means its population share, and the sum means the weighted average across strata. Leave ZZ out and the crude contrast mixes causation with background imbalance.

The collider that invents one

A collider T→C←YT \rightarrow C \leftarrow Y stays blocked by default. Two independent causes look unlinked until you filter on their shared consequence. Conditioning on CC opens it: learning T=0T=0 makes Y=1Y=1 likelier among the selected, since something had to cause selection.

So you leave CC alone. Don't add it to a regression, don't match on it, and don't filter the sample on it. Conditioning on a descendant of CC opens the path too, which is why post treatment surveys and opt in samples are dangerous.

Worked example: 12 coffee drinkers, gap 16.7 to zero

Take 12 people as a teaching table, not a trial. TT is daily coffee, YY is a heart flag, ZZ is smoking. Smokers drink more coffee and carry higher baseline risk, so ZZ drives both.

  • Non smokers, Z=0Z=0, 6 people. T=0T=0: 4 people, Y=1Y=1 in 0, so P(Y=1∣T=0,Z=0)=0/4=0P(Y=1 \mid T=0, Z=0) = 0/4 = 0. T=1T=1: 2 people, Y=1Y=1 in 0, so P(Y=1∣T=1,Z=0)=0/2=0P(Y=1 \mid T=1, Z=0) = 0/2 = 0. Stratum gap is 00.
  • Smokers, Z=1Z=1, 6 people. T=0T=0: 2 people, Y=1Y=1 in 1, so P(Y=1∣T=0,Z=1)=1/2=0.5P(Y=1 \mid T=0, Z=1) = 1/2 = 0.5. T=1T=1: 4 people, Y=1Y=1 in 2, so P(Y=1∣T=1,Z=1)=2/4=0.5P(Y=1 \mid T=1, Z=1) = 2/4 = 0.5. Stratum gap is 00.

Pool everything and smoking does the talking:

P(Y=1∣T=0)=1/6≈0.167,P(Y=1∣T=1)=2/6≈0.333P(Y=1 \mid T=0) = 1/6 \approx 0.167, \quad P(Y=1 \mid T=1) = 2/6 \approx 0.333

Crude gap is 0.333−0.167=0.1670.333 - 0.167 = 0.167, a 16.7 point gap with a true effect of zero. The bias is the full 16.7 points.

Fix it with population weights P(Z=0)=6/12=0.5P(Z=0) = 6/12 = 0.5 and P(Z=1)=0.5P(Z=1) = 0.5:

P(Y=1∣do(T=1))=0×0.5+0.5×0.5=0.25P(Y=1 \mid do(T=1)) = 0 \times 0.5 + 0.5 \times 0.5 = 0.25 P(Y=1∣do(T=0))=0×0.5+0.5×0.5=0.25P(Y=1 \mid do(T=0)) = 0 \times 0.5 + 0.5 \times 0.5 = 0.25

Adjusted gap is 00. The diagram draws this pair as the crude bars collapsing after smoking is fixed. Adjustment works here only because smoking was measured and the graph has no other backdoor path.

Worked example: 8 faces, independence turned negative

Take 8 people, 2 in each combo, as a teaching table. TT is high talent, YY is high beauty, C=1C=1 means famous when T=1T=1 or Y=1Y=1. Talent and beauty start independent.

Population, all 8: P(Y=1∣T=1)=2/4=0.5P(Y=1 \mid T=1) = 2/4 = 0.5 and P(Y=1∣T=0)=2/4=0.5P(Y=1 \mid T=0) = 2/4 = 0.5. Gap is 00.

Famous, C=1C=1, 6 people after dropping the 2 with neither trait: P(Y=1∣T=1)=2/4=0.5P(Y=1 \mid T=1) = 2/4 = 0.5 but P(Y=1∣T=0)=2/2=1.0P(Y=1 \mid T=0) = 2/2 = 1.0. Gap is 0.5−1.0=−0.50.5 - 1.0 = -0.5, a 50 point negative link that never existed. Knowing a famous person lacks talent tells you they likely bring beauty, since something earned the fame. The diagram draws 50 against 50 turning into 50 against 100 once fame filters the sample.

Code

The point is the check: rebuild both teaching tables from counts and confirm the hand gaps.

crude_control: float = 1 / 6crude_treated: float = 2 / 6gap_crude: float = crude_treated - crude_control
strat_gap: float = 0.5 - 0.5
pop_talent: float = 2 / 4pop_no_talent: float = 2 / 4gap_pop: float = pop_talent - pop_no_talent
famous_talent: float = 2 / 4famous_no_talent: float = 2 / 2gap_famous: float = famous_talent - famous_no_talent
print(f"{crude_control:.3f} {crude_treated:.3f} {gap_crude:.3f}")  # -> 0.167 0.333 0.167print(f"{strat_gap:.3f}")  # -> 0.000print(f"{gap_pop:.2f} {gap_famous:.2f}")  # -> 0.00 -0.50

The printout matches the hand computation: crude 0.167 against 0.333 for the 16.7 point bias with a zero stratified gap, then 0.00 population gap against a minus 0.50 famous gap.

Watch Out For

The healthy user who faked a heart benefit

Symptom: an observational file says a therapy protects the heart, yet a randomized trial disagrees. The prescribed group was healthier, wealthier, and better cared for, so care and habits played the role of ZZ. Fix: draw socioeconomic status and baseline care before modeling, adjust for those shared causes, and never trust the unadjusted contrast. When the key cause was never measured, admit it and run A/B testing instead of adding more columns.

The hospital file that linked two unrelated diseases

Symptom: among admitted patients, two independent conditions look negatively linked. Admission favors having at least one, so it plays the role of CC. Learning one condition is absent raises the odds of the other, since something drove admission. Fix: don't condition on admission, don't train only on the selected sample, and model the selection itself when you must work with it.

The Quick Version

  • A fork T←Z→YT \leftarrow Z \rightarrow Y stays open and fakes an effect, so you must condition on the shared cause ZZ.
  • In the 12 person coffee table the crude heart rates are 1 of 6 against 2 of 6, a 16.7 point gap, while both smoking strata have gaps of zero.
  • A collider T→C←YT \rightarrow C \leftarrow Y stays blocked until touched, so you must leave the shared consequence CC alone.
  • In the 8 person talent table the beauty rates are 50 percent in both talent groups, but among the 6 famous the rates are 50 percent against 100 percent.
  • Stratifying on a shared cause removes confounding, while filtering on a shared consequence manufactures selection bias.
  • When the needed shared cause was never measured, no adjustment rescues the estimate and randomization is the fix.