Ⅵ Counting, Probability & Statistics · Stage 34 — Statistics · 34.6 Correlation & RegressionAll lessons →
Stage 34 · Statistics

Two Variables Together: Correlation and Regression

When one number rises, does the other follow? Read the cloud, measure the link, draw the line, predict — and never confuse a partnership for a cause.

Ages 14–18 · Reading the world from data
Eight warm days, eight ice-cream sales. Each blue dot is one paired observation; the green line ŷ = b̂x + â is the least-squares fit, and the short red sticks are the residuals it leaves behind.

Until now every measurement stood alone — one pile of heights, one pile of scores. But the world comes paired: a student's study time and their grade, a day's temperature and the cones a truck sells, a person's height and their weight. The interesting question is no longer "where is the center?" but "do these two move together?" To answer it we plot the pairs as a cloud of dots, squeeze the cloud's tilt into a single number r between −1 and +1, then thread the best straight line through it to predict. One warning rides along the whole way: two things rising together is a partnership, never a proof of cause.

34.6.1 Paired data and the scatter plot

A single variable gives you a list: x₁, x₂, …, xₙ. Paired data gives you a list of couples — for each individual you record two numbers at once, (x, y). To see whether they move together, give each pair a home on the plane: walk right by its x, up by its y, and drop a dot. The picture is a scatter plot, and its overall drift — not any single dot — tells the story.

The horizontal axis carries the variable we treat as the input (the explanatory variable, often what we can dial or know first); the vertical axis carries the response we want to predict. The same plane you met in Stage 21 · Linear functions now holds messy real data instead of one tidy rule.

Six students' study hours paired with exam scores. Each blue dot is one student; together the cloud drifts up to the right — more hours, higher scores.
Key idea

A scatter plot turns a list of pairs (x, y) into a cloud of dots. We read its shape and tilt, not the individual dots: does the cloud rise, fall, or just sprawl?

34.6.2 Positive, negative, or no correlation

Stand back from the cloud and ask what it does as your eye travels left to right.

"Tends to" is the honest phrase. A few dots can buck the trend; correlation describes the crowd's behaviour, not a promise about any one point.

Three clouds of the same eight points reshaped: positive (rises), negative (falls), and none (sprawls). The green line is each one's least-squares fit, computed by GX.linReg.
Try it A GALLERY OF CLOUDS
Flip between four real-feeling datasets. Watch the cloud's tilt and the line follow each other — and watch r report it.
Dataset
Key idea

Direction is the sign of the tilt: rising = positive, falling = negative, flat-and-fuzzy = none. Strength is how tightly the dots hug a line. We are about to measure both with one number.

34.6.3 The correlation coefficient r

"Rises a lot" and "rises a little" are too vague to compare. Karl Pearson's correlation coefficient r squeezes the whole cloud into a single number that lives between −1 and +1:

So r = +0.97 is a strong upward line, r = −0.97 an equally strong downward one, and r = 0.1 is barely a whisper of a trend. The engine computes it with GX.corr(pairs); you never read r off the picture.

Worked example — r by the strengths

For the strong-rising gallery set, GX.corr returns r = 0.999 — the dots barely leave the line. Knock one point far off and recompute: the cloud is the same shape, but r can collapse toward 0.40. A single stray point swings r hard — keep that in your pocket for §34.6.7.

Watch out — r only hears straight lines

r measures linear strength only. A cloud shaped like a perfect parabola — falling, bottoming out, then rising in a flawless ∪ — has a rock-solid relationship, yet r ≈ 0 because no single straight line fits it. A small r means "no line," not "no pattern." Always look at the cloud first.

Try it r FEELS THE TILT — AND THE PARABOLA TRAP
Lerp a clean cloud from a falling line, through a fuzzy blob, to a rising line — and visit the parabola where r quietly lies.
Tilt
Shape

34.6.4 The least-squares regression line

If the cloud really does follow a line, which line? Among the infinitely many straight lines you could draw, statisticians pick the one that sits as close as possible to the dots. We write it

ŷ = b̂ x + â

The hat on ŷ ("y-hat") flags it as a prediction, not the real measured y. The slope says how much ŷ climbs per one-unit step in x; the intercept â is where the line crosses x = 0. The engine finds both from the data with GX.linReg(pairs), returning {b, a, r, predict}.

One beautiful fact pins the line down: it always passes through the cloud's centre of mass, the point (x̄, ȳ) — the average x paired with the average y. So the line is a see-saw balanced exactly on the means.

The least-squares line for the ice-cream data passes dead through the pivot (x̄, ȳ) = (27, 42) — the slate cross-hairs. Tilt the line however you like; it must still rest on that point.

34.6.5 The idea of "least squares"

Why that line and not some other? For a candidate line, drop a vertical from each dot to the line. That gap is the line's residual at that point — how far the line missed. Some misses are above (positive), some below (negative); if we just added them, ups and downs would cancel and even a terrible line could score zero.

So we square each residual (killing the sign and punishing big misses extra), then add them up. That total is the sum of squared residuals, the SSE:

SSE = Σ (yᵢ − ŷᵢ)²

The least-squares line is, by definition, the one line that makes this total as small as it can be. Tilt away from it in either direction and the SSE climbs. That single rule — minimise Σ residual² — is what makes the fit fair and unique.

Try it DRAG THE LINE, WATCH THE MISSES ADD UP
Nudge the slope of a candidate line (kept resting on the pivot). The red residual sticks grow or shrink, and the SSE bottoms out exactly at the least-squares slope.
slope b̂
Worked example — the SSE bowl

For the ice-cream data GX.linReg gives b̂ ≈ 3.10 with SSE = 130.5. Hold the line on the pivot and step half a unit either side of the best slope. Steepen it to b̂ + 0.5 ≈ 3.60: SSE jumps to 172.5. Flatten it to b̂ − 0.5 ≈ 2.60: SSE is again 172.5. Because the two slopes sit the same distance from , the total climbs equally on either side — the bowl bottoms out exactly at b̂ ≈ 3.10.

34.6.6 Predicting — and the danger of extrapolation

A fitted line earns its keep by predicting. Feed it an x and read off ŷ = reg.predict(x). For the ice-cream line ŷ = 3.10x − 41.57, a 31 °C day predicts ŷ = 3.10·31 − 41.57 ≈ 54 dozen cones.

The residual y − ŷ measures the line's miss on a point we actually observed: small residuals mean a faithful line. But there is a cliff. The line was learned from data spanning, say, 20 °C to 34 °C. Predicting inside that range (interpolation) is reasonable; predicting far outside it (extrapolation) is a leap of faith — the straight-line pattern may not hold there at all.

Watch out — extrapolation bites

Push the ice-cream line to x = 45 °C and it cheerfully predicts ever-more cones — but at scorching heat people stay home and sales would fall. The line knows nothing beyond the data it saw. Never trust a prediction far outside the observed range.

Try it PREDICT — AND FLAG THE LEAP
Slide the temperature x. Inside the data range the prediction is green and trustworthy; step beyond the cloud and it turns red — extrapolation.
temperature x (°C)
Try it THE SCATTER + REGRESSION EXPLORER
Toggle the residual sticks and the (x̄, ȳ) pivot lines on the full ice-cream dataset. The readout quotes ŷ and r straight from the engine.
Residuals
Pivot (x̄, ȳ)

34.6.7 Correlation is not causation

Here is the trap that has fooled scientists, journalists, and entire governments. Ice-cream sales and drowning deaths rise together across the year — a strong positive correlation. Does buying a cone make you drown? Of course not. A third, hidden actor — summer heat — drives both: hot days sell cones and send crowds into the water. That hidden actor is a lurking variable.

Correlation only says two variables move together. It cannot tell you whether x causes y, y causes x, or a lurking variable causes both. Proving cause needs a controlled experiment, not a scatter plot. The data shows a partnership; only careful reasoning can name a culprit.

Watch out — the four traps of correlation

Correlation ≠ causation — a lurking variable may drive both. ② r measures only linear strength — a perfect parabola scores r ≈ 0. ③ One outlier can swing both r and the line. ④ Don't extrapolate far past the data. Read all four before you trust a line.

What to carry forward

The toolkit of two-variable analysis
IdeaWhat it doesFrom the engine
Scatter plotPairs (x, y) as a cloud; read its tiltP.scatter(pairs)
Correlation r ∈ [−1, 1]Sign = direction, |r| = linear strengthGX.corr(pairs)
Regression line ŷ = b̂x + âBest line; passes through (x̄, ȳ)GX.linReg(pairs)
Least squaresMinimises Σ(y − ŷ)² (the SSE)the definition of b̂, â
Prediction & residualŷ = predict(x); miss = y − ŷreg.predict(x)
CausationNOT implied — beware lurking variablesneeds an experiment

Exercises

  1. A scatter plot of cars' age (years) against resale price ($) drifts steadily down to the right. Describe the correlation in words, and predict the sign of r.

    Show answer

    The cloud falls as age rises, so it is a negative correlation: older cars are worth less. Because the dots hug a falling line fairly tightly, r will be negative and fairly close to −1 (e.g. around −0.9).

  2. A regression on study data gives ŷ = 5.29x + 46.46, where x is hours studied and ŷ is exam score. Interpret the slope and the intercept in plain words.

    Show answer

    Slope b̂ = 5.29: each extra hour of study is associated with about 5.3 more points on the exam. Intercept â = 46.46: a student who studied 0 hours is predicted to score about 46 — and since x = 0 is at the edge of the data, treat that figure with caution.

  3. For the same line ŷ = 5.29x + 46.46, predict the score for a student who studies 6 hours. If she actually scored 79, find the residual.

    Show answer

    ŷ = 5.29·6 + 46.46 = 31.74 + 46.46 = 78.2. Residual = y − ŷ = 79 − 78.2 = +0.8 — the line missed low by 0.8 of a point, a tiny, faithful miss.

  4. A study finds a strong positive correlation between the number of firefighters sent to a blaze and the damage done. Should the town send fewer firefighters? Name the lurking variable.

    Show answer

    No — that confuses correlation with causation. The lurking variable is the size of the fire: a big blaze causes both more firefighters to be sent and more damage. Cutting firefighters would make damage worse, not better.

  5. Two students fit lines to the same eight points. Ayra's line has SSE = 130, Ben's has SSE = 172, and the true least-squares SSE is 130. Whose line is the regression line, and what does that tell you about Ben's?

    Show answer

    Ayra's line is the least-squares regression line — its SSE equals the minimum, 130. Ben's larger SSE = 172 means his line tilts away from the best fit; the least-squares line is the unique one with the smallest possible Σ(y − ŷ)².

  6. A cloud of points falls, bottoms out, then rises in a clean ∪-shape (a parabola). Its correlation comes out as r ≈ 0. Is there "no relationship"? Explain.

    Show answer

    There is a strong relationship — just not a linear one. r measures only how well a straight line fits, and no straight line follows a ∪. So r ≈ 0 means "no line," not "no pattern." Always look at the scatter plot, not r alone.

🎯 Quick check

Six questions to lock it in. Tap the answer you think is right.

§ For teachers and parents

This lesson covers the bivariate-data strand of the Common Core: HSS-ID.B.6 (represent paired data on a scatter plot and fit a function — here the least-squares line — assessing the fit by residuals), HSS-ID.C.7 (interpret the slope and intercept of a linear model in context), HSS-ID.C.8 (compute and interpret the correlation coefficient r), and HSS-ID.C.9 (distinguish correlation from causation). Every statistic the page quotes — the slope, intercept, r, predictions, and residuals — is computed by the shared GX.linReg / GX.corr helpers, never read off a picture; the regression line in every figure is genuine least squares passing through (x̄, ȳ). It builds on Stage 21 (linear functions) and Stage 33 (the normal curve and expectation), and the "reaching a verdict from data" mindset carries on into Stage 34.7's chi-square test and the logic of Stage 35.

eastmath.com · Stage 34 · 34.6 Correlation & Regression · Reading the world from data