Correlation and Regression

Stage 16 of 23 Strand 5 of 5 9 lessons

9 illustrated lessons, each teaching the why before the how.

Start with Pearson’s Correlation Coefficient in the app →
Revise Correlation and Regression with flashcards →

Jump to a lesson

Pearson’s Correlation Coefficient

One number from minus one to one.

Pearson’s r measures how closely two measurements follow one straight line, from minus one to one

Read the full lesson →

hours studiedscore

Every dot on one rising line gives r = 1, the largest value r can take.

hours of TVscore

Every dot on one falling line gives r = −1. The sign of r is the direction.

shoe sizescore

A shapeless cloud gives r near 0: one reading says nothing about the other.

hours studiedscore

The same rise with more scatter drops r toward 0. The size of r is the strength.

strengthr = 0.9strongr = 0.5moderater = 0.1weak

So one number carries both: the sign gives the direction, the size gives the strength.

water givencrop

And r judges straight lines only — this tight arch still gives r near 0.

Now you

shoe sizescore

Which value of r fits these dots best?

Critical Values of r

Small samples look linear by luck alone.

A correlation counts as evidence only once r beats the critical value for that sample size

Read the full lesson →

hours studiedscore

Three points nearly always look linear, so a high r on a tiny sample means little.

critical rn = 50.878n = 100.632n = 200.444

A table gives the value r must beat for that sample size, in a two-tailed test at the 5 percent level.

00.250.50.751barr

Ten pairs put the bar at 0.632, and an r of 0.81 clears it comfortably.

r = 0.81, n = 10ρ is the correlation of the whole population
:
r past the critical valuethe sample is evidence of a real association
reject

The null claim has a name: H₀ says ρ, the population correlation, is zero.

00.250.50.751barr

Falling short settles nothing — ten pairs simply cannot rule chance out.

heightreach

The bar assumes both readings are normal: an even cloud, no bend, and no outliers.

Now you

00.250.50.751barr

With n = 20 the critical value is 0.444, and r comes to 0.564. What follows?

00.250.50.751barr

With n = 10 the critical value is 0.632, and r comes to 0.512. What follows?

The Least-Squares Regression Line

The line that makes the squared gaps smallest.

The regression line of y on x is the line that makes the squared vertical gaps as small as possible

Read the full lesson →

hours studiedscore

Five dots rise from left to right. Many straight lines pass near them, and one fits best.

hours studiedscore

Measure the vertical gap from each dot to the line. Those gaps are the residuals.

hours studiedscore

Tilt the line and some gaps shrink while others grow. Gaps above and below the line have opposite signs, so square them before adding, or they cancel.

hours studiedscore

One line makes the sum of the squared residuals smallest, and that one is the fit.

hours studiedscore

Write the line as y = ax + b. A calculator gives a and b from the list of pairs.

a = 0.75a is a rate of change0.75 more marks per extra hourb = 1.45b is the interceptthe score at zero hours

Read them in context: a is the rise per unit of x, and b is y when x is 0.

Now you

hours studiedscore

Which total does the regression line of y on x make smallest?

b = 35b is the interceptthe cost at n = 0

Cost = 8n + 35 was fitted to n items. What is the 35?

Predicting from a Regression Line

Inside the data a result, beyond it a guess.

A regression prediction is a result inside the range of the data and a guess beyond it

Read the full lesson →

hours studiedscore

The data run from 2 hours to 8. The line was fitted to that range alone.

hours studiedscore

Read the line at 6 hours and measured points sit on either side. That is interpolation.

hours studiedscore

Stretch the same line to 18 hours, and no data point supports it there.

inside the datathe fit was measured therea resultoutside the datanothing shows the pattern continuesa guess

So reading inside the range is interpolation; beyond it is extrapolation.

y on x predicts y from xthe gaps it made small were verticalnot x from y

The line of y on x predicts y from x only, because its gaps were measured in y.

Now you

hours studiedscore

The fitted line is y = 0.5x + 1.5. Predict y when x is 3.

hours studiedscore

The fitted line is y = 0.5x + 3. Predict y when x is 4.

Spearman’s Rank Correlation

Rank the values first, then correlate the ranks.

Spearman’s rank correlation replaces every value by its rank and measures how well the two orders agree

Read the full lesson →

fertilizercrop

These points rise at every step, yet they do not follow a straight line.

valuerankA121B193C152D304

Replace each value by its rank, its place in size order: 1 for the smallest, then 2, 3, 4.

rank xrank yA11B22C33D44

Rank both measurements, then correlate the two rank columns instead of the values.

rank xrank y

Ranking turns the curved pattern into a straight line, and two orders that agree perfectly give a rank correlation of 1.

valuerankA121B152.5C152.5D194

Equal values take the average of the places they cover, so a tie for 2nd and 3rd gets rank 2.5 each.

fertilizercrop

One outlier drags r a long way, but it can only move a rank by a place or two.

straight-line agreementPearson’s rorder agreementand it survives curves and outliersSpearman’s rank correlation

Use r for a straight-line pattern, and rank correlation when only the order matters.

Now you

valuerankA121B15?C15?D194

Two values tie for the places 2 and 3. What rank does each take?

ABCDvalue31432938

Ranked smallest first, what rank does the marked value get?

The Regression Line of x on y

The other fit, for when x is the unknown.

The line of x on y makes the horizontal gaps smallest, and it is the line that predicts x

Read the full lesson →

hours studiedscore

The line of y on x minimizes the vertical residuals, so it predicts a score.

scorehours studied

Swap the axes and fit again: the residuals are now measured horizontally.

hours studiedscore

Back on the original axes, the fit of x on y is a different line.

(1, 2) (3, 6) (5, 4) (7, 6) (9, 7)y on x, for predicting a scorey = 0.5x + 2.5x on y, for predicting the hoursx = 1.25y − 1.25

Write x on y as x = cy + d. Put a score into it and it gives back the hours.

both lines pass through (5, 5)and they coincide only when r is 1 or −1the mean of x with the mean of y

Both lines cross at the mean point, and they coincide only when r is 1 or −1.

want y from xy on xwant x from yminimize the residuals in the predicted variablex on y

Choose by what you are predicting: minimize the residuals in that variable.

Now you

hours studiedscore

Where do the line of y on x and the line of x on y always meet?

want y from xy on xwant x from yminimize the residuals in the predicted variablex on y

You know a score and want the hours behind it. Which line?

The Coefficient of Determination

The share of the variation a model accounts for.

R squared is the share of the variation in y that the fitted model accounts for

Read the full lesson →

hours studiedscore

With no model at all, the best guess for y is its mean. Those squared gaps total 18.

hours studiedscore

The regression line leaves smaller residuals. Squared and added, they total 3.6.

the model accounts for four fifths of the variation

R squared is one minus the unexplained share, so 0.8 of the variation is accounted for.

r = 0.894for a straight-line fit the two agree exactly

For a straight line R squared is exactly r squared, so it never carries a sign.

R²a line0.8a quadratic0.82a quartic1

Adding terms can only raise R squared, so the largest value is not always the best fit.

hours studiedscore

R² here is 0.91, but the residuals still curve, so look at them as well as at R².

Now you

one minus the share the model failed to account for
?

The squared gaps to the mean total 25 and the squared gaps to the line total 4. What is R squared?

gaps to the line ÷ gaps to the meanboth totals measured on squared gaps1 − that share = 0.81

A model reports R² = 0.81. What does that say?

Non-Linear Regression

The same least-squares rule, over a curve.

Least squares fits a curve by the same rule that fits a line, and the shape of the data decides the family

Read the full lesson →

water givencrop

The best straight line here sits below the middle dots and above the outer ones.

water givencrop

Fit a quadratic by the same rule and every gap closes: a straight line was the wrong shape for these data.

formquadraticax² + bx + ccubicax³ + bx² + cx + dexponentialab^xpowerax^bsinea sin(bx + c) + d

A calculator offers five families: quadratic, cubic, exponential, power and sine.

weekcolonies

Counts that double every two weeks need ab^x, a curve that never turns back down.

squared gaps: line 8.96, quadratic 0then let least squares pick the numberspick the family from the shape

The rule never changes. What changes is the family of curves least squares searches over.

Now you

water givencrop

Which quantity does least squares make smallest when it fits a curve?

weekcolonies

Counts that double every two weeks are fitted best by which family?

Straightening with a Square or a Reciprocal

The axis with r closest to 1 or −1 gives the model.

Plot y against x, x² and 1/x; the axis whose r is closest to 1 or −1 gives the model

Read the full lesson →

xy

A straight line misses these points in a pattern: above it at both ends, below it in the middle. Here r = −0.8809.

1/xy

Plot y against 1/x instead and the same points lie almost on a line: r = 0.9997.

rx−0.8809x²−0.77441/x0.9997

Find r for y against x, x² and 1/x. Here 1/x gives the r closest to 1 or −1, so the model is y = a + b/x.

the regression line of y on 1/x

The regression line of y on 1/x gives a and b, so the model is y = 0.98 + 12.0/x.

x²y

Points that fall faster and faster straighten against x². Here r = −0.9999 is closer to −1 than 0.7667 is to 1, so x² wins.

Now you

put in 1/x, not x

The regression line of y on 1/x is y = 3 + 12(1/x). Estimate y when x = 6.

rx0.9772x²0.99991/x−0.7656

r is found for y against x, x² and 1/x. Which model fits the data best?

Continue your journey in the app — save your progress