Lesson 16: Regression, Correlation and Causation
Two things that move together are correlated; that does not mean one causes the other. This lesson is the one to remember if you remember nothing else from this course, because the confusion between correlation and causation is the most common error in how data is reported — in news, in advertising, and in school projects. A correlation is a fact about the data: as one variable rises, the other tends to rise or fall. Causation is a claim about the world: changing one would change the other. The first is easy to measure; the second needs an experiment, a careful design, or a strong argument.
Correlation is measured by the correlation coefficient, r, which runs from −1 to 1. A value near 1 means the two rise together; near −1 means one rises as the other falls; near 0 means no straight-line relationship. The number says nothing about why. The classic examples are everywhere: the number of firefighters at a fire correlates with the damage, because bigger fires need more firefighters and cause more damage; shoe size correlates with reading ability in children, because both grow with age. In each case a third variable — the size of the fire, the age of the child — explains the link.
Regression: Drawing the Line
Simple linear regression draws the straight line that best fits a scatter of points, by minimising the squared distances from the points to the line — the method of least squares. The line has a slope, saying how much the outcome changes per unit of the predictor, and an intercept, where it crosses the vertical axis. The code below fits such a line with Python, predicting a test score from hours studied, and prints the slope, the intercept, and R-squared — the share of the variation in scores the line explains.
import pandas as pd
from sklearn.linear_model import LinearRegression
df = pd.read_csv("students.csv")
model = LinearRegression()
model.fit(df[["hours_studied"]], df["score"])
print("slope:", model.coef_[0])
print("intercept:", model.intercept_)
print("R-squared:", model.score(df[["hours_studied"]], df["score"]))
A regression line is a summary, not a law. It describes the data it was fitted on, and extrapolating beyond that range — predicting the score for a student who studied 100 hours when the data covers 0 to 10 — is guessing, not science. The line also assumes the relationship is straight; if the true pattern curves, a straight line will mislead at the extremes. Always plot the data with the line, and look at what the line misses.
When Can You Claim Causation?
Causation needs more than a correlation. The strongest evidence is a fair experiment, where the predictor is assigned by chance — the subject of Lesson 12. Without an experiment, you need a combination of things: a plausible mechanism, a relationship that survives controlling for confounders, a dose-response pattern where more of the cause gives more of the effect, and results that hold up in different settings. Even then, the claim is provisional. The honest habit is to say "associated with" unless you have the evidence to say "causes" — and to notice when others do not.
A Straight Line Is a Choice
Fitting a straight line is a choice, and it is worth asking when that choice is wrong. Many real relationships curve: the benefit of extra study time flattens as the hours grow, the risk of a disease rises steeply after a threshold, the growth of a population slows as it approaches a limit. A straight line fitted to curved data will be wrong at the extremes — over-predicting where the truth flattens, under-predicting where it steepens — and the residuals, the gaps between the points and the line, will show a pattern instead of scattering randomly. That pattern is the data telling you the line is the wrong shape.
The remedy is to look at the residuals, not just the R-squared. Plot them against the predictor: if they scatter randomly around zero, the line is a reasonable summary; if they curve, the relationship is not straight, and a different model is needed — perhaps a curve, or a transformation of the variables. This habit of checking the residuals is the regression equivalent of reading the training curve in deep learning: it is where the model's failures become visible, and where the next improvement begins.
Correlation in the News
News reports love correlations, and they rarely come with the cautions this lesson teaches. A headline that says 'people who drink coffee live longer' is reporting an association, and the readers who act on it are assuming a cause. But coffee drinkers may differ from non-drinkers in income, exercise, or a dozen other ways, and any of those could explain the link. Before believing such a claim, ask three questions: was it an experiment or an observation, what confounders were controlled for, and how big was the effect? If the report cannot answer those, the claim is not worth acting on.
The same three questions apply to your own work. When you find a correlation in your capstone data, report it as a correlation, show the scatter plot, and discuss the confounders that could explain it. If you can, control for the most plausible one and see whether the link survives. That single check — does the correlation survive controlling for the obvious alternative — separates a careful analyst from a careless one, and it is the habit that will protect your readers from being misled.
Watch & Learn
One video to watch for this unit, from a trusted educator.
- Linear Regression, Clearly Explained!!! — StatQuest with Josh Starmer
Least squares, R-squared and the p-value for a regression, explained step by step — the method behind this unit.
Key Terms
- Correlation
- When two variables tend to move together; measured by the correlation coefficient r.
- Causation
- When changing one variable would change the other.
- Correlation coefficient (r)
- A number from −1 to 1 measuring the strength and direction of a straight-line relationship.
- Linear regression
- Fitting the straight line that best describes how an outcome changes with a predictor.
- Least squares
- The method of fitting a line by minimising the squared distances from the points to the line.
- Extrapolation
- Predicting beyond the range of the data the model was fitted on; risky and often wrong.
Discussion Questions
- Firefighters and fire damage are correlated. What is the third variable, and what would happen if you sent fewer firefighters to a big fire?
- A study finds that students who study more score higher. Is that causation? What else could explain it?
- Why is 'associated with' more honest than 'causes' in most observational studies?
Practice Questions
- What is the difference between correlation and causation?
- What does a correlation coefficient of −0.8 mean?
- Why do shoe size and reading ability correlate in children?
- What does least squares do when fitting a regression line?
- Why is extrapolation risky?
Show answers
- Correlation means two variables tend to move together; causation means changing one would change the other. Correlation is easy to measure; causation needs an experiment or a strong argument.
- A strong relationship in which one variable falls as the other rises. The sign gives the direction, the size gives the strength.
- Because both grow with age — age is the third variable driving both, not because big feet cause good reading.
- It chooses the line that minimises the squared distances from the data points to the line.
- Because the line describes the data it was fitted on; beyond that range the true relationship may curve or change, so predictions are guesses, not science.