Correlation and Linear Regression
Read scatterplots, interpret the correlation r, fit and use a least-squares regression line, and avoid extrapolation and causation traps.
Welcome back!
Step 1 of 14Learn
Two variables at once
A teacher records, for each of 40 students, how many hours they studied for an exam and the score they earned. Do more hours go with higher scores? By how much?
When both variables are quantitative, the right graph is a scatterplot: each individual is one dot, with the explanatory variable (the one that may explain or predict, here hours) on the horizontal axis and the response variable (the outcome, here score) on the vertical axis.
Describe a scatterplot with four features:
- Direction: positive (as x increases, y tends to increase) or negative (y tends to decrease).
- Form: is the pattern roughly linear (a straight-line trend) or curved?
- Strength: how closely the points follow the pattern. Tightly clustered is strong; a loose cloud is weak.
- Unusual features: outliers, or separate clusters.
A good description: "There is a moderately strong, positive, linear relationship between hours studied and exam score, with no obvious outliers."
The words "tend to" matter. A positive relationship doesn't mean every student who studied more scored higher. Some students who studied 3 hours beat some who studied 6. It describes the overall trend, not every individual.
Step 2 of 14Learn
The correlation coefficient r
The correlation coefficient r measures the direction and strength of a linear relationship with one number between −1 and 1.
- r = 1: perfect positive line. r = −1: perfect negative line.
- r near 0: no linear relationship.
- Roughly: |r| above 0.8 is strong, 0.5–0.8 moderate, below 0.5 weak. These cutoffs vary by field; in social science, 0.3 can be notable.
Key facts about r:
- It only measures linear relationships. A perfect U-shaped curve can have r = 0. Always look at the scatterplot first.
- It has no units, and changing units (inches to centimeters, dollars to euros) doesn't change it.
- It doesn't care which variable is x. The correlation of hours with score equals the correlation of score with hours.
- It is not resistant. A single outlier can push r a long way toward 0 or toward ±1.
- The sign gives direction; the size gives strength. r = −0.9 is a stronger relationship than r = 0.6.
That last point trips people up. Negative doesn't mean weak; it means that as one variable goes up, the other goes down, like a car's age and its resale price.
Step 3 of 14Practice · Match the pairs
Match each correlation to the best description of its scatterplot.
Tap an answer, then tap the place where it belongs (or drag it there).
- r = 0.95
- r = −0.90
- r = 0.40
- r = 0.02
- r = −0.55
Step 4 of 14Practice · Chart
Study hours vs. exam score
Tap the student who breaks the overall pattern.
Tap the point that answers the question, then press Check.
| Point | Hours studied | Score |
|---|---|---|
| Ana | 1 | 58 |
| Ben | 2 | 62 |
| Cai | 2 | 66 |
| Dee | 3 | 66 |
| Eli | 4 | 72 |
| Fay | 5 | 74 |
| Gus | 6 | 79 |
| Hal | 7 | 45 |
| Ivy | 8 | 88 |
| Jo | 9 | 91 |
Step 5 of 14Learn
The least-squares regression line
Correlation measures strength. To predict, we fit a line:
ŷ = a + bx
ŷ ("y-hat") is the predicted response; b is the slope and a is the intercept. (Statistics writes the intercept first, unlike y = mx + b in algebra, but it's the same idea.)
Of all possible lines, the least-squares regression line is the one that makes the sum of the squared vertical distances from the points to the line as small as possible. Its slope and intercept come from five summary numbers:
b = r × (s_y / s_x) and a = ȳ − b x̄
Example. For the study data: x̄ = 5 hours, s_x = 2 hours, ȳ = 75 points, s_y = 10 points, r = 0.8.
- b = 0.8 × (10/2) = 4
- a = 75 − 4 × 5 = 55
- Line: ŷ = 55 + 4x
Interpreting the slope: for each additional hour studied, the predicted exam score increases by 4 points, on average.
Interpreting the intercept: a student who studies 0 hours has a predicted score of 55. The intercept only makes sense if x = 0 is realistic and within the range of the data; often it isn't.
The line always passes through the point (x̄, ȳ), here (5, 75).
Step 6 of 14Try the calculator
Regression line from summary statistics
Enter the means, standard deviations and correlation to get the least-squares line, then make a prediction for any x.
- Slope b = r × s_y/s_x
- 4
- Intercept a = ȳ − b x̄
- 55
- Predicted ŷ at x
- 83
- r² (share of variation explained)
- 0.64
Step 7 of 14Practice · Work it out
Using ŷ = 55 + 4x, what exam score is predicted for a student who studies 7 hours?
Step 8 of 14Learn
Residuals, r² and extrapolation
A prediction is rarely exact. The residual for each point is
residual = observed y − predicted ŷ
If a student who studied 7 hours actually scored 90, the residual is 90 − 83 = +7: the student did 7 points better than the line predicted. Points above the line have positive residuals; points below, negative. The least-squares line makes the sum of squared residuals as small as possible, and its residuals always add to zero.
A residual plot (residuals vs. x) is a check on whether a line is the right model. A random scatter around zero is good. A curved pattern means a straight line is the wrong form.
r², the coefficient of determination, is the fraction of the variation in y that is explained by the linear relationship with x. With r = 0.8, r² = 0.64: 64% of the variation in exam scores is accounted for by hours studied. The other 36% comes from everything else: prior knowledge, sleep, test anxiety.
Extrapolation means predicting outside the range of x-values in the data. If students studied between 1 and 9 hours, the line predicts that 20 hours gives 55 + 80 = 135 points, on a 100-point exam. Relationships that look linear within the data often bend or break outside it.
Step 9 of 14Practice · Work it out
A student who studied 4 hours scored 65. Using ŷ = 55 + 4x, what is this student's residual?
Step 10 of 14Learn
Correlation is not causation
Countries that eat more chocolate per person win more Nobel Prizes per person. The correlation is strong. Should governments hand out chocolate to future scientists?
Of course not. Wealthier countries tend to have both more chocolate consumption and more research funding. Wealth is a lurking variable: a variable not included in the analysis that influences both variables being studied.
A strong correlation, or a regression line with a big r², can arise in several ways:
- x causes y. (Studying raises scores, at least partly.)
- y causes x, the reverse. Cities with more police officers have more crime, partly because high-crime cities hire more police.
- A lurking variable drives both. Ice cream sales and drowning deaths, linked by summer heat.
- Coincidence. Search enough data and you'll find two unrelated series that move together by chance.
Observational data alone can't tell these apart. As in the study design lesson: only a randomized experiment can establish cause and effect. When experiments are impossible, as with smoking and lung cancer, scientists build a causal case from many lines of evidence: a strong association found in many studies, a dose-response pattern, the right time order, and a plausible mechanism.
The safe wording for an observational result is "is associated with" or "predicts," never "causes" or "leads to."
Step 11 of 14Practice · Diagram
A lurking variable behind a correlation
Tap the variable that explains the chocolate-Nobel correlation.
Tap the shape that answers the question, then press Check.
- National wealth
The lurking variable: it drives both of the things we measured.
- Chocolate eaten
Richer countries can afford more luxury foods.
- Nobel Prizes
Richer countries fund more universities and research.
Step 12 of 14Note
Step 13 of 14Practice · What would you do?
What would you do?
A study of 200 used cars finds the regression line predicted price = 24,000 − 1,800 × (age in years). Which interpretation of the slope is correct?
Step 14 of 14Practice · Choose one
An observational study finds a correlation of r = 0.7 between the number of hours teenagers spend on social media and their reported anxiety levels. Which conclusion is justified?
Lesson complete!