Skip to content
AI360XpertBeta

Correlation vs Causation

When two things move together, one might cause the other, or a hidden third factor might be driving both. ML optimizes correlation; intervention requires causation.

Eight beach days correlate at 0.96 pooled but 0.00 within each temperature group, so heat drives the 14 tub gap
Eight beach days correlate at 0.96 pooled but 0.00 within each temperature group, so heat drives the 14 tub gap

Why Does This Exist?

Your model can predict well and still recommend the wrong action. That gap is why this distinction matters.

Take eight beach days. Shark sightings and ice cream tubs move together with correlation 0.96, so a model that predicts tubs from sharks looks brilliant offline. Ban swimming and tubs will not budge, because heat drives both. You called the future right and still picked a lever that does nothing.

Basics first, briefly: correlation is the linear co-movement number between minus one and one, defined in correlation coefficient. Causation is what happens when you force a change. This page shows how the first number can hit 0.96 with zero push from sharks, how to spot the hidden driver, and what to do instead. Causal graphs give you the arrow map for choosing adjustments, confounding and colliders zooms into the two junctions you must treat in opposite ways, and randomized experiments show the fix when you can randomize.

Think of It Like This

The rooster that takes credit for dawn

You hear the rooster crow, then the sun rises. Every dawn follows a crow, so the crow predicts sunrise perfectly.

The rooster is shark sightings, sunrise is ice cream sales, and Earth spin is heat. Spin lights the sky and wakes the bird, just as heat fills the beach with swimmers and buyers. Mute the bird and dawn still comes. Close the beach and tubs still sell on hot days.

Where it stops: the farm story sounds exact, while real beach days wiggle by a tub or two inside the same heat. That wiggle is why you must compute the within group link instead of trusting the pooled picture.

How It Actually Works

Call shark sightings XX, meaning the count you observe but do not control. Call ice cream tubs YY, meaning the outcome you want to move. Call temperature ZZ, meaning the background cause that comes first and pushes both. Correlation rr measures linear co-movement from the data you saw. Causation measures what forcing XX would do.

What correlation measures

Pearson correlation rescales covariance by both spreads:

r=Cov(X,Y)σXσYr = \frac{\mathrm{Cov}(X, Y)}{\sigma_X \sigma_Y}

Here Cov(X,Y)\mathrm{Cov}(X, Y) means the average product of deviations from the means, σX\sigma_X means the standard deviation of XX, and σY\sigma_Y means the standard deviation of YY. The result always sits between minus one and one. Plus one is a perfect rising line, minus one a perfect falling line, zero no straight line link. It says nothing about what would happen if you intervened.

What causation adds

Seeing is P(Y∣X=x)P(Y \mid X=x), meaning the share of YY among days where XX happened to equal xx. Doing is P(Y∣do(X=x))P(Y \mid do(X=x)), meaning the share if you forced XX to xx everywhere. A confounder fork X←Z→YX \leftarrow Z \rightarrow Y keeps those two apart: XX and YY move together through ZZ even when XX does nothing to YY. That open backdoor path is the whole trap.

You close it by stratifying on ZZ, meaning compare days within the same heat, then average. If the within group link is flat while the pooled link is steep, ZZ did the talking. When no measured ZZ can close every backdoor, you need a new design such as A/B testing or the counterfactual framing in potential outcomes.

Worked example: eight beach days from 0.96 to 0.00

Take eight days as a teaching set, not a trial. Cool days run near 20C, hot days near 30C:

  • Cool ZZ: X=[1,1,2,2]X = [1, 1, 2, 2], Y=[10,12,12,10]Y = [10, 12, 12, 10]
  • Hot ZZ: X=[5,5,6,6]X = [5, 5, 6, 6], Y=[24,26,26,24]Y = [24, 26, 26, 24]
  • Pooled X=[1,1,2,2,5,5,6,6]X = [1, 1, 2, 2, 5, 5, 6, 6], pooled Y=[10,12,12,10,24,26,26,24]Y = [10, 12, 12, 10, 24, 26, 26, 24]

Pooled means are 3.53.5 sharks and 18.018.0 tubs. Sum of squared deviations are 34.034.0 for XX and 400.0400.0 for YY, with cross sum 112.0112.0:

r=112.034.0×400.0=112.0116.62≈0.96r = \frac{112.0}{\sqrt{34.0 \times 400.0}} = \frac{112.0}{116.62} \approx 0.96

A naive line through the pool has slope 112.0/34.0≈3.29112.0 / 34.0 \approx 3.29 tubs per shark. It reads as if each extra shark brings three tubs.

Now hold heat fixed. Cool means are 1.51.5 sharks and 11.011.0 tubs. Hot means are 5.55.5 sharks and 25.025.0 tubs, so the strata gap is 25.0−11.0=14.025.0 - 11.0 = 14.0 tubs. Inside cool days the cross sum is 0.00.0 on sums of squares 1.01.0 and 4.04.0, so r=0.00r = 0.00. Hot days match exactly, cross sum 0.00.0, so r=0.00r = 0.00. Sharks explain none of the two tub wiggle inside a heat level. The diagram draws these same numbers: two clouds, one steep pooled tilt, two flat within group lines.

Code

The point is the check: pooled correlation looks strong, each heat slice is flat, and the strata gap carries the full 14 tubs.

X: list[float] = [1, 1, 2, 2, 5, 5, 6, 6]Y: list[float] = [10, 12, 12, 10, 24, 26, 26, 24]

def pearson(a: list[float], b: list[float]) -> float:    ma = sum(a) / len(a)    mb = sum(b) / len(b)    sxy = sum((x - ma) * (y - mb) for x, y in zip(a, b))    sxx = sum((x - ma) ** 2 for x in a)    syy = sum((y - mb) ** 2 for y in b)    return sxy / (sxx * syy) ** 0.5

print(pearson(X, Y))  # -> 0.9603920767980495print(pearson(X[:4], Y[:4]))  # -> 0.0print(sum(Y[4:]) / 4 - sum(Y[:4]) / 4)  # -> 14.0

The printout matches the hand computation: pooled 0.96, cool slice 0.0, strata gap 14.0.

Watch Out For

Shipping the proxy as the lever

Symptom: offline error looks great with sharks as a feature, the team closes the beach or bids on shark alerts, and tub sales do not move. Fix: demand an intervention test before you ship the lever, such as randomized experiments or A/B testing. Prediction needs correlation, action needs causation.

Adjusting for a downstream variable

Symptom: the estimate flips or blows up after you add a variable that the treatment or outcome causes, like beach photos that crowds and sales both produce. Fix: adjust only for pre treatment causes picked from a graph, never for consequences. Causal graphs and confounding and colliders show which node stays in and which stays out.

The Quick Version

  • Correlation 0.96 between sharks and tubs across eight beach days shrinks to 0.00 inside each temperature group.
  • A confounder fork X←Z→YX \leftarrow Z \rightarrow Y makes two variables move together through heat with no push between them.
  • Seeing P(Y∣X)P(Y \mid X) predicts the future while doing P(Y∣do(X))P(Y \mid do(X)) predicts the effect of an action, and only the second guides a decision.
  • Cool days average 11 tubs and hot days average 25 tubs, so the full 14 tub gap traces to heat rather than sharks.
  • A naive slope of 3.29 tubs per shark looks actionable offline and goes flat once heat is held fixed, which is why levers need experiments.