Correlation Is Not Causation (Ice Cream Didn't Cause That Shark Attack)

· 2 min read · Syed Omar Faruk Towaha
Correlation Is Not Causation (Ice Cream Didn't Cause That Shark Attack)

Every introductory statistics class tells this story, and it remains undefeated: in many coastal places, ice cream sales and shark attacks rise and fall together. Plot them and you get a lovely upward trend.

Ice cream vs sharks
A strong correlation. Zero causal relationship between dessert and sharks.

A reckless analyst concludes that ice cream causes shark attacks. A more creative one concludes that sharks are attracted to people who just ate ice cream. Both should be kept away from policy decisions.

The hidden third variable

The confounder
Summer drives both. The two outcomes just happen to share a cause.

Hot weather makes people buy ice cream. Hot weather also makes people swim in the sea, where sharks live. Ice cream and sharks are connected only through summer. In statistics, summer is a confounder: a variable that influences both things you're looking at.

Confounders are everywhere

That last one is why naive comparisons can punish the people doing the best work.

Other ways correlation fools you

Reverse causation. Does exercise make people healthy, or are healthy people more able to exercise? Often both.

Coincidence. With enough variables, some will correlate by pure chance. There are whole websites of hilarious spurious correlations between unrelated statistics.

Selection bias. If you only survey customers who stayed, you'll never hear why people left.

How to get closer to causation

  1. Randomised experiments. Randomly assign who gets the new feature (an A/B test). Randomisation balances confounders you didn't even think of. This is the gold standard when it's possible and ethical.
  2. Control for known confounders. Compare within groups (same city size, same season) or include them in a regression model.
  3. Natural experiments. Sometimes a policy, a border or a random event creates comparable groups for you.
  4. Draw the causal diagram. Literally sketch arrows between variables before analysing. It forces you to say what you believe causes what.
import statsmodels.formula.api as smf

# naive
smf.ols("sharks ~ ice_cream", data=df).fit().params

# controlling for temperature: the ice cream effect shrinks toward zero
smf.ols("sharks ~ ice_cream + temperature", data=df).fit().params

How to say it in a meeting

Instead of "X causes Y," try: "X and Y move together. We haven't ruled out that something else, like seasonality, drives both. If we want to know whether changing X changes Y, we should test it."

It sounds less exciting. It's also much less likely to end with your company banning ice cream.

// related

// prefer the terminal?

Open the terminal blog and type read correlation-not-causation-ice-cream-sharks.