📖 Contents · Hub · Full version Chapter 14 · Correlation & Regression
Statistics Easy Read · Chapter 14

Correlation & Regression

Almost every interesting question in the world is a question about two things at once. Does studying more raise a score? Does a heavier dose lower a symptom? Does price move with square footage? Correlation and regression are the two tools that answer those questions honestly. Correlation puts a single number on how tightly two quantitative variables track each other. Regression draws the one straight line that fits the cloud of points better than any other line could, and it lets you use that line to predict. Neither tool needs you to be fast at math. Every formula in this chapter is built from things you already know: means and standard deviations. What they do need is care in reading the results, because this is the corner of statistics where confident people say wrong things most often.

By the end of this chapter you can

  • Build and read a scatterplot, and describe a relationship by its form, direction and strength.
  • Put the explanatory and response variables on the correct axes.
  • Work out the correlation coefficient r by hand from deviations, and read its size and sign correctly.
  • State the cautions on r: it covers straight lines only, outliers sway it, a narrow range shrinks it and correlation is not causation.
  • Find the least-squares regression line, and explain just what amount "least squares" makes smallest.
  • Read the slope and intercept in the units of the problem, without sneaking in a claim about cause.
  • Work out residuals and r2, and read a residual plot for curves, spread and outliers.
  • Use the line to predict, and tell when a prediction is unfair extrapolation.
  • State the assumptions behind inference on the slope, and word a p-value and a confidence interval correctly.

Section 1Scatterplots

A scatterplot of paired data showing a strong positive relationship between two variables
Reference. A scatterplot with a strong positive relationship; each dot is one person or thing measured on two variables. Source and license: see the figure credits

One dot, one individual, two measurements

Everything up to this point in the book has described one variable at a time, such as the mean of a set of scores or the spread of a set of blood pressures. A scatterplot is the first graph that shows two quantitative variables measured on the same people or things. Each one gives a single dot, placed by its two values. If you measure six students on hours studied and exam score, you get six dots, not twelve.

Which variable goes where is not random. The explanatory variable (also called the predictor, or x) goes on the horizontal axis. The response variable (the outcome, or y) goes on the vertical axis. This habit shows the direction we care about. We are asking whether x helps us say something about y, not the reverse. Hours studied explains exam score far more naturally than exam score explains hours studied, so hours goes on the x axis. Sometimes neither variable is plainly the explainer, such as a person's arm span and their height. Then the choice is yours, but you must make it before you draw, because the regression line in Section 3 depends on it.

Form, direction, strength, and then outliers

Describing a scatterplot is a careful habit, and the habit is a fixed order of four questions.

Form asks what shape the cloud takes. Is it a straight band, a curve that bends, two separate clusters or a blob with no shape at all? Form comes first, because it decides whether the rest of this chapter even applies. Correlation and least-squares regression are tools for linear (straight line) form. Point them at a U shaped cloud, and they will hand you a number, and the number will be a lie.

Direction asks which way the band tilts. Positive means high x values tend to come with high y values, so the cloud rises from left to right. Negative means high x comes with low y, and the cloud falls. Note the word tend. Direction is a statement about the general drift of the whole cloud, not a promise about any single pair of points.

Strength asks how tightly the points hug that form. A narrow band as thin as a pencil is strong, and a fat, fuzzy band is weak. Strength is about the scatter around the pattern, not about how steep the pattern is. This is the most common misreading of a scatterplot, and it is worth pausing on. Points that lie almost exactly on a nearly flat line make a strong relationship with a small slope. A steep spray of widely scattered points is a weak relationship with a large slope. Steepness and tightness are different questions.

Outliers are the last question. An outlier in a scatterplot is a point that sits far from the overall pattern. Note that it need not be extreme in x alone or y alone. Think of a student with an ordinary 5 hours of study and an ordinary 95 on the exam. That student may be nothing special on either variable alone, yet fall well off the joint pattern. Only the picture with both variables shows that.

QuestionWhat you are looking atVocabulary to use
FormThe shape of the cloudLinear, curved (nonlinear), clustered, no pattern
DirectionWhich way a linear pattern tiltsPositive, negative, or neither
StrengthHow tightly points hug the patternStrong, moderate, weak
OutliersPoints far from the overall patternOutlier; influential point (Section 4)

The data we will carry through this chapter

To keep the math honest, one small data set will run through the next four sections. Six students recorded their total study hours before an exam, and we recorded their exam score out of 100.

StudentABCDEF
Hours studied (x)2457810
Exam score (y)726970808394

Sketch it in your head, or on paper; the form is about linear. The direction is positive: the students with few hours sit low, and the student with ten hours sits highest. The strength looks good but not perfect. Student A studied only 2 hours and outscored student B, who studied 4. That single crossing is just the kind of flaw that keeps r below 1. We will see it show up in the numbers in Section 2, and again as a residual in Section 4.

Draw the picture before you work out the number. A correlation coefficient sums things up in one number, and every one number summary throws information away. The scatterplot is the only place you will ever see curves, clusters or a single point dragging the whole analysis around. Working out r without looking at the plot is like reporting a patient's average temperature without noticing that it spiked to 104 once.
Interactive Shape a relationship, draw real samples from it, and learn to read a scatterplot in order, form, direction, strength, while a live-computed correlation shows exactly what that one number can and cannot see. Open full ↑
Key points
  • A scatterplot shows two quantitative variables on the same people or things, with one dot for each.
  • The explanatory variable goes on the horizontal axis, and the response goes on the vertical.
  • Describe every scatterplot in the same order: form, direction, strength, outliers.
  • Strength is not steepness. A shallow but tight band is a strong relationship, and a steep but fuzzy one is weak.

Section 2The correlation coefficient

Anscombe's quartet: four very different scatterplots that share the same correlation and regression line
Reference. Anscombe's quartet: four data sets with nearly the same means, correlations and regression lines, but fully different shapes. Source and license: see the figure credits

What r actually measures

The correlation coefficient, written r (and formally called the Pearson correlation), is a single number between −1 and +1. It measures the direction and strength of a straight line relationship between two quantitative variables. Its sign gives the direction, and its distance from zero gives the strength. An r of exactly +1 means every point lies exactly on an upward line. −1 means every point lies exactly on a downward line, and 0 means no straight line tendency at all.

The formula looks scary until you see what it is doing:

r = Σ(x − x̄)(y − ȳ) ÷ √[ Σ(x − x̄)2 × Σ(y − ȳ)2 ]

Read the top part first. For each person, we ask two questions. Were they above or below average on x, and above or below average on y? If both answers agree, above on both or below on both, the product of the two deviations is positive. If they disagree, the product is negative. Adding those products across everyone asks the whole data set to vote; a large positive total means agreement wins. The bottom part then rescales that total so it can never be bigger than 1 in size. That is what lets you compare r across studies, and what makes it fully free of units.

Another form, which gives the same result, makes the unit free part obvious. Say zx and zy are the standardized scores of the two variables. Then

r = [ 1 ÷ (n − 1) ] × Σ zx zy

Correlation is nothing more than the average product of z-scores. That is also why r does not change if you convert inches to centimeters or dollars to euros: standardizing washes the units out.

Computing r, step by step

Take the six students. First the means: Σx = 2 + 4 + 5 + 7 + 8 + 10 = 36, so x̄ = 36 ÷ 6 = 6 hours. And Σy = 72 + 69 + 70 + 80 + 83 + 94 = 468, so ȳ = 468 ÷ 6 = 78 points. Now build the deviation table; this one table will serve us for the rest of the chapter.

xyx − x̄y − ȳ(x−x̄)(y−ȳ)(x−x̄)2(y−ȳ)2
272−4−6241636
469−2−918481
570−1−88164
78012214
8832510425
10944166416256
Sums: 364680012642466

There are two built in checks before going on. The raw columns must give back the means (36 ÷ 6 = 6 and 468 ÷ 6 = 78). And both deviation columns must add up to exactly 0. They do; now put in the numbers:

r = 126 ÷ √(42 × 466) = 126 ÷ √19,572 = 126 ÷ 139.90 = 0.9006

So r ≈ +0.90. Round to two decimals for reporting; the sign is positive, which matches the upward tilt we saw. The size, 0.90, is close to 1, which confirms a strong straight line relationship. It is strong but not perfect, because student A outscored student B.

If you prefer the z-score route, you need the standard deviations: sx = √(42 ÷ 5) = √8.4 = 2.898 hours and sy = √(466 ÷ 5) = √93.2 = 9.654 points. Then r = 126 ÷ [5 × 2.898 × 9.654] = 126 ÷ 139.89 = 0.9006, the same answer. Keep sx and sy handy, because Section 3 uses them.

Four cautions that matter more than the formula

1. r measures straight line (linear) association only. Think of hours of sleep versus alertness. Too little is bad, too much leaves you groggy, and the relationship is an arch. Such data can give an r very near zero, while the two variables are in fact tightly related, just not in a straight line. An r near 0 means "no linear pattern," never "no relationship."

2. r is not resistant. It is built from means and squared deviations, so a single far off point can drag r sharply up or down. This is the lesson of Anscombe's quartet in the figure above. Four data sets share almost the same means, the same r and the same regression line, yet look nothing alike. One is truly linear, and one is a clean curve. One is a perfect line ruined by a single outlier. And one is a vertical stack plus one lone point that makes up the whole correlation.

3. A narrow (restricted) range shrinks r. Say you work out the correlation between admission test scores and college grades using only the students who were admitted. You have thrown away the whole low end of the x range. Cutting the range of x lowers r as a matter of math. That is why picky samples so often make good predictors look useless.

4. Correlation is not causation. This is the one everyone can recite and almost no one applies. A strong r between two variables fits at least four different worlds. x may cause y. y may cause x; a third, hidden lurking variable may cause both. Or the pattern may be chance in a small sample. Ice cream sales correlate with drowning deaths, because hot weather drives both. The correlation is real, but the story about cause is fiction. Only a randomized experiment breaks the link between the treatment and every lurking variable at once. So only that kind of study allows a claim about cause from data like these.

Two smaller notes are worth keeping. r needs both variables to be quantitative, so there is no correlation between eye color and height. And r is symmetric: the correlation of x with y equals the correlation of y with x. That symmetry is a warning in itself, because it means r alone can never tell you which variable is doing the explaining.

Value of rWhat it saysWhat it does not say
r = +1Every point on one upward straight lineNothing about how steep that line is
r = +0.90Strong positive linear associationThat x causes y
r = −0.90Strong negative association: exactly as strong as +0.90That the relationship is "worse" than a positive one
r = 0.05Almost no linear tendencyThat the variables are unrelated: the form may be curved
r = −1.4Nothing: this is impossiblecheck your arithmetic; r lives in [−1, +1]
The sign and the size are two separate messages. Read r = −0.87 as two facts glued together. The direction is negative, and the strength is 0.87, which is strong. A common exam error is calling −0.87 "weaker" than +0.60 because it is a smaller number. Strength is the distance from zero, so −0.87 is clearly the stronger of the two.
Interactive Drag points around a live scatterplot and watch the correlation coefficient r, the least-squares line, and r² recompute in real time. Open full ↑
Key points
  • r measures the direction and strength of a linear relationship, and it always lies between −1 and +1.
  • r = 126 ÷ √(42 × 466) = 0.90 for our study hours data, which is strong and positive.
  • r has no units, does not change with rescaling and is symmetric in x and y.
  • r is not resistant to outliers. It is blind to curves, it shrinks under a narrow range and it never proves causation.

Section 3The regression line

A scatterplot with a fitted straight regression line drawn through the points
Reference. A least-squares regression line fitted through a cloud of points. Source and license: see the figure credits

What "least squares" means

Once a scatterplot looks linear, you can lay a straight line through it and use that line as a model. But endless lines pass through a cloud of points, so we need a rule that picks just one. The rule is least squares.

For any line you try, and for each data point, measure the vertical distance from the point to the line. That is how far off the line's prediction was. That distance is the residual: residual = y − ŷ, where ŷ ("y-hat") is the value the line predicts. Square every residual, so that misses above and below both count as errors and cannot cancel. Then add them up. The least-squares regression line is the one and only line that makes that sum, Σ(y − ŷ)2, as small as it can possibly be.

Two details in that definition carry real weight. First, the distances are vertical, not perpendicular. That is because we are predicting y from x, and vertical distance is exactly the error in predicting y. Second, we square instead of taking absolute values. A side effect is that a large miss counts far more than its size. That is why one outlier can tilt a regression line so easily.

Squaring vertical distances has a direct result. The regression line of y on x is not the same as the line of x on y. Correlation is symmetric, but regression is not. Swap the roles of the variables, and you get a different line. So decide which variable you are predicting before you fit anything.

Slope and intercept

Write the line in the familiar form ŷ = a + bx, where b is the slope and a is the y intercept. The least-squares answer is remarkably tidy:

b = Σ(x−x̄)(y−ȳ) ÷ Σ(x−x̄)2    equivalently    b = r × (sy ÷ sx)

a = ȳ − b x̄

The second slope formula is worth staring at. The slope is the correlation, turned from standardized units back into real ones by the ratio of the two standard deviations. It also tells you that the slope and r always share a sign, so a positive correlation promises an upward line. And the intercept formula is a rearranged form of ȳ = a + bx̄. That says something useful in its own right: the least-squares line always passes through the point of averages (x̄, ȳ). If your line misses that point, you have made a math error.

Fitting the line to our data

Everything we need is already in the Section 2 table; the slope is:

b = 126 ÷ 42 = 3

Check it the other way: b = r × sy ÷ sx = 0.9006 × (9.654 ÷ 2.898) = 0.9006 × 3.331 = 3.00. They agree; now the intercept:

a = ȳ − bx̄ = 78 − (3)(6) = 78 − 18 = 60

The least-squares line is ŷ = 60 + 3x. Check the point of averages: at x = 6, ŷ = 60 + 18 = 78 = ȳ; it is correct.

Reading the slope. The slope is a rate, and its units are the units of y per unit of x: 3 exam points per hour of study. State it as a prediction, not a promise: "for each extra hour studied, the model predicts an increase of about 3 points in exam score, on average." Do not say "an extra hour raises your score by 3 points." That is a claim about cause, and these data come from watching, not an experiment. A lurking variable, such as how well prepared a student was before, could be producing both.

Reading the intercept. The intercept is the predicted y when x = 0. A student who studies 0 hours is predicted to score 60. Sometimes that means something and sometimes it is nonsense. The deciding question is always whether x = 0 is inside the range of the data we actually saw. Our hours ran from 2 to 10, so x = 0 sits outside the data: close by, but outside. Treat that 60 as an anchor that places the line, not as a real forecast about a student who never opens the book.

Proving the line is best

"Least squares" is a claim we can test with math. Our line gives the following predictions and errors. At x = 2, ŷ = 66, and the actual score was 72, an error of +6. At x = 4, ŷ = 72 versus 69, an error of −3. At x = 5, ŷ = 75 versus 70, an error of −5. At x = 7, ŷ = 81 versus 80, an error of −1. At x = 8, ŷ = 84 versus 83, an error of −1. At x = 10, ŷ = 90 versus 94, an error of +4. Squaring and adding: 36 + 9 + 25 + 1 + 1 + 16 = 88.

Now try a steeper line. Keep it through the point of averages, because for any slope you fix, the best intercept is a = ȳ − b x̄. So the best line at that slope always passes through (x̄, ȳ). With a slope of 3.5, a = 78 − 3.5(6) = 57, and ŷ = 57 + 3.5x. Its errors are +8, −2, −4.5, −1.5, −2 and +2, and the squared total is 64 + 4 + 20.25 + 2.25 + 4 + 4 = 98.5. That is worse. A shallower slope of 2.5 gives a = 63 and errors of +4, −4, −5.5, −0.5, 0 and +6. Its squared total is 16 + 16 + 30.25 + 0.25 + 0 + 36 = 98.5. That is also worse, and by exactly the same amount, because the penalty for missing the best slope is symmetric.

Candidate lineSlopeInterceptΣ(y − ŷ)2Verdict
ŷ = 63 + 2.5x2.56398.5Too shallow
ŷ = 60 + 3x36088Least squares: the best line
ŷ = 57 + 3.5x3.55798.5Too steep

No other slope beats 88. That number has a name we will use all through Section 4: the sum of squared errors, SSE.

Fit a line only after the scatterplot earns it. Least-squares math will happily fit a straight line to a perfect parabola and report a slope with a straight face. The formula has no way of knowing the form is wrong. That check is yours, made with your eyes before you work anything out, and confirmed afterward with the residual plot in the next section.
Interactive Tilt and shift a line through a fixed cloud of points and watch the sum of squared residuals fall to its unique minimum, with each residual drawn as a literal square and a live SSR-vs-slope landscape. Open full ↑
Key points
  • The least-squares line makes Σ(y − ŷ)2, the sum of squared vertical distances, as small as possible.
  • b = Σ(x−x̄)(y−ȳ) ÷ Σ(x−x̄)2 = r sy ÷ sx, and a = ȳ − b x̄.
  • Our line is ŷ = 60 + 3x: the predicted score rises about 3 points per extra study hour.
  • The line always passes through (x̄, ȳ), and the slope always shares the sign of r.
  • Regression is not symmetric: predicting x from y gives a different line.

Section 4r-squared and residuals

A residual plot showing the residuals from a fitted regression line scattered about zero
Reference. A residual plot from an ordinary least-squares fit, with residuals scattered about the zero line. Source and license: see the figure credits

Residuals: what the line missed

A residual is the leftover: residual = observed − predicted = y − ŷ. A positive residual means the actual value sat above the line, so the person did better than the model expected. A negative residual means it sat below. The residuals are the raw material for everything in this section, so work them out with care.

x (hours)y (actual)ŷ = 60 + 3xResidual y − ŷResidual2
27266+636
46972−39
57075−525
78081−11
88384−11
109490+416
Sums--088

The residuals add up to exactly zero; that is not luck. It is a math promise of least squares, and so it is a free error check every time you do this by hand. Student A, who studied 2 hours and scored 72, has the largest residual: 6 points better than the model predicted. Student C, at 5 hours and 70 points, came in 5 points short.

r2: how much variation the line explains

Before we had a line, our only guess for any student's score would have been the overall mean, 78. The total variation in y around that mean is the total sum of squares, SST = Σ(y − ȳ)2 = 466, which we already worked out in Section 2. After fitting the line, the variation still left over is SSE = Σ(y − ŷ)2 = 88. So the line accounted for 466 − 88 = 378 of the original variation.

The coefficient of determination is that accounted for share:

r2 = 1 − (SSE ÷ SST) = 1 − (88 ÷ 466) = 1 − 0.1888 = 0.8112

And it lives up to its name: it really is the square of the correlation. From Section 2, r = 0.9006, and 0.90062 = 0.8111, the same value up to rounding. So we report r2 = 0.81, or 81%.

The correct sentence is: about 81% of the variation in exam scores is explained by the linear relationship with hours studied. The other 19% is variation the line does not capture, such as sleep, prior knowledge, test anxiety and luck. Here are three wordings that sound alike and are all wrong. It does not mean 81% of the points lie on the line. It does not mean predictions are 81% accurate, and it does not mean studying causes 81% of exam performance. r2 is a statement about variation, nothing else.

Because it is a square, r2 always falls between 0 and 1 and is never negative. That means it throws away the direction of the relationship. Report r alongside it, or your reader cannot tell whether the link was positive or negative.

Reading a residual plot

A residual plot graphs the residuals on the vertical axis against x (or against ŷ) on the horizontal. Its whole purpose is to magnify what the original scatterplot hides. In the original plot, a gentle curve can be swamped by the steep overall rise. Subtracting the line removes that rise and leaves the misfit standing alone.

What you want to see is nothing. That means a band of points with no shape, scattered above and below the zero line, with about the same width all along. That is the residual plot's way of saying the straight line model is good enough. Any shape is a message.

What the residual plot showsWhat it meansWhat to do
Formless horizontal band around zeroA line is an adequate modelProceed: report slope, r, r2
A clear U or arch (curvature)The true form is curved, not linearDo not use the line; transform a variable or fit a curve
A fan widening left to rightSpread of y grows with x (non-constant variance)Predictions are far less reliable at the wide end
One point far from the rest verticallyAn outlier in the y directionInvestigate it; report results with and without it
One point far out in x with a small residualA high-leverage, possibly influential pointRefit without it: if the line moves a lot, say so

Our six residuals, in x order, run +6, −3, −5, −1, −1 and +4. They start high, dip negative in the middle and come back up, in a faint U. With only six points, that is far too little evidence to drop the straight line model. But it is just the pattern you would flag and watch if you collected forty students instead of six.

The difference in the last two table rows deserves stress. Leverage is about being extreme in x. A point far to the right or left of the other x values sits at the end of a long lever and can swing the line. Influence is about actually changing the answer. A point is influential if removing it clearly moves the slope, the intercept or r. High leverage points are the ones most likely to become influential. But the only way to know is to refit without the point and compare.

A high r2 does not mean the model is right. Anscombe's curved data set and his data set driven by an outlier both show a respectable r2, while being badly served by a straight line. r2 tells you how much variation the line soaked up. The residual plot tells you whether a line was the right shape in the first place. Always report both, and trust the residual plot when they disagree.
Interactive Split a variable's variation into the share the regression line explains (r-squared) and the share left over, then read a live residual plot across four scenarios to tell a good fit from a wrong-shaped line or growing spread. Open full ↑
Key points
  • Residual = observed − predicted = y − ŷ. Residuals from a least-squares line always add up to 0.
  • SST = 466 (variation about ȳ) and SSE = 88 (variation left after the line), so r2 = 1 − 88÷466 = 0.81.
  • Say it as: "81% of the variation in y is explained by the linear relationship with x." It does not mean 81% of points, 81% accurate or 81% caused.
  • r2 is never negative, so it hides direction. Report r too.
  • A good residual plot shows no pattern. A curve, a fan shape or a lone stray point each mean something different.

Section 5Prediction

A regression line shown with prediction bands widening away from the center of the data
Reference. A fitted line with prediction bands. Note how the bands widen away from the center of the data. Source and license: see the figure credits

Using the line

Prediction is mechanical. Put a value of x into the equation, and read off ŷ. With ŷ = 60 + 3x, a student who studies 6 hours is predicted to score 60 + 3(6) = 78. A student who studies 9 hours is predicted to score 60 + 3(9) = 87.

What is not mechanical is knowing what that number means. The regression line predicts the average y for people with that x, not the value any one person will get. Our own data prove the point. Student E studied 8 hours, the line predicted 84 and the actual score was 83, off by one. Student A studied 2 hours, the line predicted 66 and the actual score was 72, off by six. A prediction from a regression line is a center of gravity, not a promise.

You can measure the typical miss. The standard error of the estimate measures the typical size of a residual:

se = √[ SSE ÷ (n − 2) ] = √(88 ÷ 4) = √22 = 4.69 points

We divide by n − 2 instead of n − 1, because fitting a line used up two pieces of information: a slope and an intercept; here is what it means. Single scores fall about 4.7 points away from the regression line, on average. So the prediction of 87 for a student who studies nine hours is better read as "somewhere in the mid to high 80s, give or take five points or so." A rough working range of ŷ ± 2se, about 78 to 96, is a usable ballpark. It is only a ballpark. A proper prediction interval is wider than that near the edges of the data, which is just the flaring you see in the figure above.

Interpolation is safe; extrapolation is not

Interpolation means predicting at an x value inside the range you saw. Our hours ran from 2 to 10, so predicting for 6 hours is interpolation. It rests on evidence, because we watched what happened to students on both sides of 6.

Extrapolation means predicting outside that range. It rests on an assumption you cannot check: that the straight line pattern goes on where you have no data. Very often it does not. Watch what our perfectly reasonable line does when it is pushed:

Hours (x)Prediction ŷ = 60 + 3xInside the data (2 to 10)?Verdict
369YesInterpolation: trustworthy
678YesInterpolation: trustworthy
987YesInterpolation: trustworthy
060No (just outside)The intercept: anchors the line, not a real forecast
15105NoImpossible: the exam is out of 100
25135NoAbsurd: the model has left reality behind

The line never warns you. It will happily give 135 for a student who studies 25 hours, because a line goes on forever and math has no common sense. The real relationship must flatten out. Scores are capped at 100, and past some point, extra hours give nothing or actually hurt through tiredness. Our data never visited that region, so our line knows nothing about it. Always state the range of x your model was built on, and refuse predictions outside it.

Four more habits before you predict

Do not predict backward with the same line. Our line predicts score from hours. To predict hours from score, you must refit with the roles reversed. That line has a slope of 126 ÷ 466 = 0.27, not 1 ÷ 3. Turning a regression line around with algebra gives the wrong answer.

Remember regression to the mean. The slope is r × sy ÷ sx, and r is less than 1 in size. So predictions are always pulled toward ȳ, compared with how extreme x was. A student one full standard deviation above average in hours is predicted to be only r = 0.90 standard deviations above average in score. This is not a flaw; it is a result of imperfect correlation. It explains why great performances tend to be followed by more ordinary ones, without any cause at all.

Check the conditions before you trust any inference. The tools that describe, r, the slope and r2, only need a scatterplot that is about linear. But the moment you attach a p-value or a confidence interval to the slope, you are relying on a model, and that model has four stated assumptions. Linearity: the true relationship between x and y is a straight line. Check the scatterplot, and confirm with a residual plot that has no pattern. Independence: the observations do not depend on one another. This comes from how the data were collected, not from anything you can see in a plot. Constant variance: the spread of y about the line is the same across the range of x. The fanning row in the Section 4 table is just this condition failing. Approximate Normality: the residuals are about Normal around the line, checked with a histogram or Normal plot of the residuals. Our six students are far too few to check any of this convincingly, and saying so is the honest report.

Be exact about the language of uncertainty. Regression output most often includes a test of whether the slope differs from zero, along with a p-value and a confidence interval. Three statements must be kept straight. First, a p-value is the probability of getting data at least this extreme if the true slope were zero. It is not the probability that the true slope is zero, and not the probability that your finding is wrong. Second, a large p-value means you fail to reject the hypothesis of zero slope. It does not let you accept that the slope is zero. Absence of evidence for a relationship is not evidence that there is none, since a small sample can easily hide a real slope. Third, a 95% confidence interval for the slope describes how the method behaves over the long run. If you repeated the whole study many times, about 95% of the intervals built this way would contain the true slope. It does not mean there is a 95% chance that the true slope lies inside the one interval in front of you. That interval either contains it or it does not.

Every prediction should come with three sentences. Give the value ("about 87 points"), the typical error ("single scores fall about 4.7 points from the line") and the range where it holds ("this model was built on students studying 2 to 10 hours"). A prediction reported without its uncertainty and its limits is not a statistic. It is a guess wearing a decimal point.
Interactive Fit a least-squares line to childhood height data (ages 2 to 9), then slide a prediction age from inside the data out to adulthood and watch the line, trustworthy in range, insist a grown adult should be over eleven feet tall; every prediction, error, and reality-check computes live against the true growth curve. Open full ↑
Key points
  • Putting x into the line predicts the average y at that x, not any one person's value.
  • se = √[SSE ÷ (n−2)] = √22 = 4.69: the typical distance of a point from the line.
  • Interpolation (inside the x range you saw) is backed by data. Extrapolation is not, and it gave an impossible 105 at 15 hours.
  • To predict x from y, refit. Do not turn the equation around.
  • Inference about the slope assumes linearity, independence, constant variance and residuals that are about Normal. State and check them.
  • A p-value is not the probability that the null is true. Failing to reject a zero slope is not accepting it. And a 95% CI describes the method over the long run, not this one interval.

The chapter in one breath

  • A scatterplot shows two quantitative variables on the same people or things. Describe it as form, direction, strength, outliers, with the explanatory variable on the x axis.
  • r measures the direction and strength of a linear relationship. It lies in [−1, +1], has no units and is symmetric. For our data, r = 126 ÷ √(42×466) = 0.90.
  • r is blind to curves, open to sway by outliers, shrunk by a narrow range and silent about cause. A lurking variable can produce any correlation you like.
  • The least-squares line makes Σ(y−ŷ)2 as small as possible. b = r sy÷sx = 3 and a = ȳ − b x̄ = 60, giving ŷ = 60 + 3x, which passes through (6, 78).
  • The slope is a predicted rate of change (3 points per hour). The intercept only means something if x = 0 sits within the data.
  • Residuals (y − ŷ) add up to zero and give SSE = 88. With SST = 466, r2 = 0.81: 81% of the variation in scores is explained by the linear relationship with hours.
  • A residual plot should look like nothing at all. Curves, fanning and stray points each point to a different failure that r2 alone would hide.
  • Interpolate freely, but never extrapolate. Our line predicts an impossible 105 at 15 hours. Report every prediction with its typical error, se = 4.69, and the range where it holds.
  • Inference on the slope assumes linearity, independence, constant variance and residuals that are about Normal. A p-value is not the probability that the null is true, failing to reject is not accepting and a 95% CI is a claim about the method.

ReferenceWords worth knowing

A quick reference for the terms in this chapter. Skim it now, or come back whenever a word trips you up.

Coefficient of determination (r2)
The share of the variation in y explained by the linear relationship with x. It equals 1 − SSE÷SST, and it equals the square of r.
Correlation coefficient (r)
A number with no units between −1 and +1 that measures the direction and strength of a straight line relationship between two quantitative variables.
Explanatory variable
The variable used to explain or predict the other. It is plotted on the horizontal axis and written x. It is also called the predictor or independent variable.
Extrapolation
Predicting at an x value outside the range of the data you saw. It is not backed by evidence, and it is a common source of absurd results.
Fitted value (ŷ)
The value the regression line predicts for a given x, also called the predicted value.
Influential point
An observation whose removal clearly changes the slope, intercept or r. It is most often a high leverage point, one that is extreme in the x direction and sits at the end of a long lever. But only refitting without it can confirm influence.
Intercept (a)
The predicted value of y when x = 0. It is worked out as ȳ − b x̄, and it means something only if x = 0 falls within the data.
Interpolation
Predicting at an x value inside the range you saw. It is the fair use of a regression line.
Least-squares regression line
The one and only line ŷ = a + bx that makes the sum of squared vertical distances from the points to the line as small as possible.
Lurking variable
A third variable, not measured, that affects both x and y. It can create a correlation with no link of cause between them.
Outlier
A point lying far from the overall pattern of the scatterplot. It need not be extreme on either variable alone.
Regression to the mean
The tendency for predicted y values to be less extreme than their x values. This happens because the slope is r times sy÷sx, and |r| is less than 1.
Residual
Observed minus predicted, y − ŷ. It is positive above the line and negative below, and the residuals always add up to zero for a least-squares fit.
Residual plot
A graph of residuals against x (or against ŷ); a good one shows no pattern at all.
Response variable
The outcome being explained or predicted; it is plotted on the vertical axis and written y; it is also called the dependent variable.
Restricted range
A sample that covers only part of the possible x values. As a matter of math, that shrinks r and can hide a real relationship.
Scatterplot
A graph of two quantitative variables measured on the same people or things, with one dot for each.
Slope (b)
The predicted change in y for a one unit increase in x. It equals r × sy ÷ sx and always shares the sign of r.
Spurious correlation
A strong link between variables that have no link of cause, most often produced by a lurking variable or by chance.
Standard error of the estimate (se)
The typical size of a residual, √[SSE ÷ (n − 2)]. It is a root mean square measure of how far the points fall from the line. It divides by n − 2 because the fit used up a slope and an intercept.
Sum of squared errors (SSE)
Σ(y − ŷ)2, the variation in y left unexplained after fitting the line.
Total sum of squares (SST)
Σ(y − ȳ)2, the total variation in y about its mean, before any line is fitted.

Check yourself

1. A scatterplot of daily temperature (x) against heating cost (y) shows a tight band of points falling steadily from upper left to lower right, with one point far above the band. Describe the relationship in the four needed terms.
Form: linear. Direction: negative. Strength: strong. Outliers: one point lies well above the pattern. Use that fixed order every time. Form comes first, because if the form were curved, r and a least-squares line would both be wrong tools, no matter how tight the band looked.
2. Two scatterplots are shown. In plot P, the points are scattered loosely around a very steep line. In plot Q, the points lie almost exactly on a nearly flat line. Which shows the stronger relationship, and why?
Plot Q. Strength is about how tightly the points hug the pattern, not how steep the pattern is. Q's points barely stray from its line, so Q has the larger |r|. P's steep slope tells you about the rate of change, which is a separate question from strength.
3. For a data set, you work out Σ(x−x̄)(y−ȳ) = 60, Σ(x−x̄)2 = 40 and Σ(y−ȳ)2 = 250. Find r, and explain what it means.
r = 60 ÷ √(40 × 250) = 60 ÷ √10,000 = 60 ÷ 100 = 0.60. It is a moderate positive straight line relationship. Above average x values tend to come with above average y values, but with a lot of scatter. Note that r2 = 0.36, so only 36% of the variation in y is explained.
4. A classmate says, "r = −0.85 is a weaker relationship than r = +0.60 because −0.85 is a smaller number." Correct them.
Strength is the distance from zero, so −0.85 is clearly the stronger relationship. The sign carries only the direction: −0.85 means a strong downward pattern. Sign and size are two separate messages packed into one number.
5. The number of firefighters sent to a fire correlates strongly with the damage the fire causes. Should cities send fewer firefighters? Explain in the words of this chapter.
No. This is a lurking variable, not causation. The size of the fire drives both. Big fires draw more firefighters and cause more damage. The correlation is real, but the reading as cause is false. Only a randomized experiment could support a claim about cause, and no one would run that one.
6. A researcher measures hours of sleep and daytime alertness and reports r = 0.04, concluding that the two are unrelated. What has been missed?
An r near zero means no straight line tendency, not no relationship. Alertness rises and then falls with sleep, in an arch. The upward half and the downward half cancel in the top part of r. A scatterplot would have shown the curve at once, which is why you always plot before you work anything out.
7. Given x̄ = 50, ȳ = 200, sx = 10, sy = 30 and r = 0.60, find the least-squares regression line.
b = r sy ÷ sx = 0.60 × 30 ÷ 10 = 1.8; a = ȳ − b x̄ = 200 − 1.8(50) = 200 − 90 = 110. So ŷ = 110 + 1.8x. Check the point of averages: at x = 50, ŷ = 110 + 90 = 200 = ȳ; it is correct.
8. Our chapter line is ŷ = 60 + 3x for exam score on hours studied. Write a correct reading of the slope, and explain what makes the tempting version wrong.
"For each extra hour studied, the model predicts an increase of about 3 points in exam score, on average." The tempting version says, "studying one more hour raises your score by 3 points." That claims cause from data that came from watching, not an experiment. It also drops "on average," which suggests a promise for every person. The residuals of +6 and −5 flatly go against that.
9. The same line has an intercept of 60. Is that a meaningful prediction? Why or why not?
Not really. The hours we saw ran from 2 to 10, so x = 0 lies outside the data. The intercept is needed in the math to place the line. But predicting a score of 60 for a student who studies zero hours is extrapolation. An intercept is a fair forecast only when x = 0 falls inside the range you saw.
10. For our data, r2 = 0.81; which of these are correct readings? (a) 81% of the points lie on the line. (b) Predictions are 81% accurate. (c) 81% of the variation in exam scores is explained by the linear relationship with hours studied. (d) Studying causes 81% of exam performance.
Only (c). r2 = 1 − SSE÷SST = 1 − 88÷466 is a statement about variation. (a) mixes up variation with a count of points; in our data, zero points lie exactly on the line. (b) makes up an accuracy rate. (d) sneaks in cause, which no correlation can give.
11. Student C studied 5 hours and scored 70. Work out the residual, and state what its sign means. Then say what the six residuals must add up to.
ŷ = 60 + 3(5) = 75; residual = 70 − 75 = −5. The negative sign means the actual score fell below the line, so C did 5 points worse than the model predicted. All residuals from a least-squares line add up to exactly 0 (+6 − 3 − 5 − 1 − 1 + 4 = 0), which is a free math check.
12. A manager uses ŷ = 60 + 3x to argue that a student studying 20 hours would score 120. What is wrong, and what should the manager say instead?
This is extrapolation. 20 hours is double the largest value we saw, 10. And the "prediction" of 120 is above the 100 point maximum, which alone proves the line has left reality. The correct statement is this. The model was built on students studying 2 to 10 hours, and it only holds in that range. Beyond it, the relationship almost surely flattens as scores near their ceiling, and we have no data to describe that region.