What is the difference between correlation and causation?
Correlation means two variables move together. Causation means a change in one actually produces a change in the other. Correlation can come from a hidden third factor, from chance, or from cause running the other way, so proving causation usually needs a controlled experiment such as an A/B test.
Explain it simply
In summer, ice cream sales go up, and so do cases of drowning. The two numbers are correlated. But ice cream does not make anyone drown. Hot weather causes both: more people buy ice cream and more people go swimming.
Correlation says "these two things tend to rise and fall together". Causation says "pushing this one will move that one". The first is easy to measure from data. The second is much harder to prove.
Example
A coaching institute looks at its data and finds that students who attended more doubt-clearing sessions scored higher in the final exam. The correlation is strong. Can they claim "our sessions raise marks"?
Not from this data alone. Some possibilities:
- Confounding variable: motivated students both attend more sessions and study more at home. Motivation drives both numbers.
- Reverse causation: students who are already doing well may enjoy the sessions more and attend more often.
- Chance: with a small group, a pattern can appear by luck.
To test the claim properly, they could randomly assign half the students to get extra sessions and compare the two groups. Random assignment spreads motivation evenly between the groups, so a difference in marks can be credited to the sessions.
import pandas as pd
df = pd.DataFrame({
"sessions": [2, 5, 8, 3, 10, 6],
"marks": [55, 62, 78, 58, 85, 70],
})
print(df["sessions"].corr(df["marks"])) # about 0.99, a strong positive correlation
# A high value here says nothing about which one causes the other.How it works
- The Pearson correlation coefficient (r) ranges from -1 to +1. +1 is a perfect straight-line rise, -1 a perfect straight-line fall, 0 means no linear relationship.
- r only measures linear relationships. Two variables can be strongly related in a curve and still have r near 0.
- Causation needs evidence that the link survives after other explanations are ruled out. The strongest evidence comes from randomised controlled experiments. When experiments are not possible (you cannot randomly assign people to smoke), researchers use careful observational methods and look for consistent evidence from many studies.
Real-world use
- A/B testing in product teams exists precisely because correlation is not enough. Flipkart or Swiggy will not trust "users who saw the new button bought more" until the button is shown to a random half of users.
- Medicine: drug trials randomly assign patients to the drug or a placebo.
- Feature selection in ML: a feature correlated with the target can help prediction even if it does not cause the outcome. Prediction and causation are different goals.
Common mistakes
- Treating a high r as proof that one variable causes the other.
- Ignoring confounders like age, income or season.
- Reading r = 0 as "no relationship at all", when the relationship might be non-linear.
- Finding a correlation after testing hundreds of variable pairs and reporting it as meaningful. Some will be high by chance.
What to say in the interview
"Correlation means two variables move together; causation means changing one actually changes the other. A correlation can be explained by a confounding variable, by reverse causation, or by chance. The classic example is ice cream sales and drownings, both driven by hot weather. To establish causation I would run a randomised experiment like an A/B test, and if that is not possible, I would control for known confounders and be careful about the claims I make."
Follow-up questions
- What is a confounding variable? Give an example.
- Can two variables have a strong relationship but a correlation near zero?
- How does an A/B test help establish causation?
- What is the difference between Pearson and Spearman correlation?
Go deeper
Read these once the basics above feel easy.
Spearman correlation works on ranks instead of raw values. It measures whether the relationship is consistently increasing or decreasing (monotonic), even if it is not a straight line, and it is less affected by outliers than Pearson.
Simpson's paradox is a sharp warning about confounders: a trend that appears in every subgroup can reverse when the groups are combined, because the groups have different sizes and baselines. Always ask what hidden grouping might be in the data.