Statistics From Scratch by Rob Brotherton

18  Regression

  • Introduction
  • 1  Variables & Measurement
  • 2  Frequency
  • 3  Central Tendency
  • 4  Variability
  • 5  \(z\)-Scores
  • 6  Probability
  • 7  Sampling
  • 8  Hypothesis Testing
  • 9  Statistical Power
  • 10  Confidence Intervals
  • 11  The \(t\) test
  • 12  Independent-samples \(t\) test
  • 13  Related-samples \(t\) test
  • 14  ANOVA
  • 15  Related-samples ANOVA
  • 16  Factorial ANOVA
  • 17  Correlation
  • 18  Regression
  • References

Table of contents

  • Making a prediction
  • Straight lines
    • The line of best fit
    • The slope (\(b\))
    • The intercept (\(a\))
  • Testing regression
    • Sums of squares
  • Partitioning variability
    • Degrees of freedom
    • Mean squares
  • A regression test, step by step
    • Step 1: State the hypotheses
    • Step 2: Set the decision criteria
    • Step 3: Collect and analyze the data
    • Step 4: Make a decision
  • Reporting and interpreting the results
  • Multiple regression
    • Calculating the slopes
    • Intercept and regression equation
    • Picturing the sums of squares
    • Finishing the regression
    • Testing each predictor
    • Interpreting multiple regression

18  Regression

Multicolored dots with a correlation of about 0.6 pop into view, then their line of best fit draws across them as their colors change to green near the line through vermilion at the largest absolute residuals.

In this chapter we’ll introduce the last inferential procedure that we will cover: regression. This extends our ability to analyze relationships among variables, much like ANOVA extends our ability to analyze differences among groups beyond what the \(t\) test is capable of. And as we’ll see, regression is actually a variation of the ANOVA technique itself.

Making a prediction

Last chapter we looked at the association between coffee consumption and test scores. For our sample of seven students, those who drank more coffee tended to score lower. (The link weakened once we took sleep into account. We’ll circle back to that later, but for now we’ll just focus on coffee and test performance.)

That’s all well and good, but now suppose another student comes along to take the exam. Could you guess how they’re likely to score? As a reminder, here’s a scatterplot of the seven students’ coffee and test scores we looked at in Chapter 17. The dashed lines mark the means: one cup of coffee and the average test score of 70.

The seven students' coffee and test scores from Chapter 17, with dashed lines at the mean of one cup and the mean score of 70.

Make a guess

0 of 4
1

Say we don’t know how much coffee the new student drank. What test score would you guess they’ll get? What made you pick that score?

Example answer

I’d start with 70, the average for the seven students we’ve seen so far. That’s my best guess before I know anything about this particular student.

2

Now suppose the new student tells you they drank exactly one cup of coffee, the average amount for our sample so far. What would you guess now?

Example answer

The one student who drank exactly one cup scored 65, so I can see a case for 65. Or you might stick with 70. One cup puts our new student right in the middle of the scatterplot, where the two mean lines meet.

3

Now say they drank a cup and a half, more than average. Would you change your guess? What do you see in the scatterplot that makes you think so?

Example answer

I’d lean toward a lower score. The points tend to slope downward as I look from left to right. That gives me a direction to go in, but it still leaves me with the question of how far to go.

4

If you had to put a number on it, what score would you predict for a student who drank a cup and a half? What about a student who drank no coffee? How did you decide?

Example answer

At a cup and a half I see a 50 and a 65, so I might guess halfway between them. At zero cups there’s just one student. Do I go with their 90? Or do I step back and use the pattern across all seven students to make both guesses?

Quiz 18.1

This is a lot like how we started thinking about correlations in the previous chapter. But when we want to make specific predictions, rather than just talking about the general direction and strength of association between two things, we’re moving from correlation to regression. We saw that a perfect correlation means the points on a scatterplot fall on a straight line. Regression is about fitting a line through the points even when they don’t line up perfectly, to simplifiy and summarize the actual, messy relationship and quantify the underlying predictability.

When we are dealing with just two variables, it’s called a simple linear regression. The variable we use to make the guess is the predictor (\(X\), cups of coffee in our example). The variable we’re trying to predict is the outcome (\(Y\), test score).1

Quiz 18.1 was getting at the ways we might use information to make predictions. If we don’t have information about the predictor—we don’t know how much coffee someone had—a reasonable guess at their outcome would be the average test score, 70. On the scatterplot that’s the dashed line going straight across at a test score of 70. We would make the same guess for everyone, regardless of how much coffee they actually drank.

But when we do have information about the predictor, we can use it to potentially make a more accurate guess. We can let the line tilt, so our guess depends on how much coffee someone drank. We found a negative correlation, \(r = -.50\), so the line should slope downward, and we’d make different guesses for someone who drank no coffee versus someone who drank two cups, for example. But by how much should our guesses differ? That depends on the characteristics of the line we fit.

Straight lines

A brief reminder about straight lines. A line like the one we’re after is defined by its slope, \(b\), and intercept, \(a\).2 The slope describes how much the line goes up or down for each unit it moves to the right (“rise over run”). The intercept is where it crosses the \(Y\) axis, the value of \(Y\) when \(X\) equals zero.

That gives the equation for a straight line:

\[ Y = bX + a \tag{18.1}\]

A straight line you might already be familiar with is the relationship between temperatures on the Celsius scale and on the Fahrenheit scale.

Figure 18.1: The line crosses the Fahrenheit axis at 32 °F and rises 18 °F for every 10 °C.
The Celsius–Fahrenheit line. A guide marks 32 °F where the line meets the Y axis. From 10 to 20 °C, a run of 10 degrees Celsius, the line rises 18 °F.

The correlation between the two scales is exactly 1, since every pair of values falls on the same upward-sloping straight line. Converting from Celsius to Fahrenheit, the relationship for that line is \(Y = 1.8X + 32\). The slope is 1.8 °F per degree Celsius. As we increase Celsius by 10 degrees, Fahrenheit increases by 18 degrees. The intercept is 32 °F. That allows us to convert from one scale to the other. For example, 100 degrees Celsius is 212 degrees Fahrenheit: \(1.8(100) + 32 = 212\).

The line of best fit

How does this help us when we have a bunch of data that isn’t perfectly correlated? Simple: we draw a line through the points to summarize their relationship: the regression line. Rather than describing a perfect relationship and solving for \(Y\), the slightly modified equation below gives us a prediction, \(\hat{Y}\) (“Y-hat”): a typical value of \(Y\) for any value of \(X\), based on the slope and intercept of that line.

\[ \hat{Y} = bX + a \tag{18.2}\]

Here’s what such a line might look like for our coffee and test score data.

Figure 18.2: A scatterplot of the coffee and test score data, with a line drawn through the points. The red dashed lines show how to find a predicted test score for any amount of coffee. The red dot on the line is \(\hat{Y}\).
The coffee and test score scatterplot with the line of best fit drawn through the points, falling from an intercept of 80 with a slope of −10. Guides read half a cup up to the line and across to 75 points, and a slider moves the reading from 0 to 2.5 cups: a cup and a half reads across to 65.

How far off?

0 of 3
1

Use the slider in the figure above to read off the line’s prediction for any amount of coffee. Two of our students drank a cup and a half. What score does the line predict for each of them?

Answer

65

Explanation

65 for both. The line gives one prediction for each amount of coffee, so it can’t pass through two different scores at the same \(X\). Unlike the temperature line, it’s going to miss somebody.

2

One of those students scored 50. By how many points was the prediction too high?

Answer

15

Explanation

We predicted 65 and they scored 50, so we were 15 points too high.

3

What if we moved the whole line down five points? How far off would the prediction be now for the other student, who scored 65?

Answer

5

Explanation

We’d now predict 60, so we’d be 5 points off for a student we used to get exactly right. We’d be closer for the student who scored 50, though. Moving the line closer to some points moves it further from others.

Quiz 18.2

There are infinitely many lines we could draw, and a line closer to some points will be farther from others. How do we know which line is best? We find the one that’s least wrong overall.

To quantify the wrongness of a line, we look at its residuals—the vertical distances (positive or negative) from the line to the points. For each student, we subtract the predicted score from the observed score to see how far above or below the line they fell.

\[ Y - \hat{Y} \tag{18.3}\]

Don’t let the fancy new name and symbol fool you. A residual is a deviation, just like \(Y - M_Y\), the equation for deviations from a mean. Think of \(\hat{Y}\) as a kind of mean that changes as you move along the line, giving a typical score for each amount of coffee.

Take the student who drank a cup and a half and scored 50 on the test, for example. The line predicted a score of 65 for someone who drank that amount of coffee, so that student’s residual is \(50 - 65 = -15\). It’s negative because the prediction was too high; other residuals will be positive. And just like with deviations from the mean, we square the residuals so the positive and negative misses don’t cancel out. Add up those squares and we get the sum of squared residuals, \(SS_{\text{residual}}\).

\[ SS_{\text{residual}} = \Sigma(Y - \hat{Y})^2 \tag{18.4}\]

In Chapter 4 the mean gave us the smallest possible sum of squared deviations. Here, the combination of slope and intercept that minimizes the sum of squared residuals gives us the line of best fit. Of all the straight lines we could draw through this scatterplot, this one gives us the least squared error (LSE) overall. That’s where the method gets its name, least squares.

So how do we find the slope and intercept that give the line of best fit? Thankfully we don’t have to go through every possible combination to find the one that gives the smallest answer.3 We can find the slope and intercept that minimize the squared error directly from the data.

The slope (\(b\))

In Chapter 17 we found the correlation coefficient \(r\) by dividing the sum of products, \(SP\), by \(\sqrt{SS_X SS_Y}\). Dividing by the variability of both variables cancels out the units. That’s why the correlation for Celsius and Fahrenheit comes out to 1, even though the slope is 1.8. For the slope we want to keep the units, so we divide \(SP\) by \(SS_X\) alone.

\[ b = \frac{SP}{SS_X} \]

For our coffee and test score data, \(SP\) is in cups times points, and \(SS_X\) is in cups squared, so what’s left is test points per cup—the “rise over run.”4

We calculated both \(SP\) and \(SS_X\) for the coffee and test score data in Chapter 17’s Activity 17.3. The sum of products, \(SP = \Sigma(X - M_X)(Y - M_Y)\), was \(-30\). The sum of squares for coffee, \(SS_X = \Sigma(X - M_X)^2\), was 3. Both use the same deviation from the mean coffee, \(X - M_X\).

\[ b = \frac{SP}{SS_X} = \frac{-30}{3} = -10 \]

In other words, as you follow the line one unit along the \(X\) axis, you move down ten units on the \(Y\) axis. Each cup of coffee consumed knocks 10 points off the predicted test score. The correlation of \(-.50\) told us your expected score would go down; the slope tells us by how much.5

The intercept (\(a\))

Having figured out the slope, we can use it to find \(a\), the predicted score when \(X = 0\). To do so, we take a known point on the line and work backwards. Which known point? The point where the mean of \(X\) and the mean of \(Y\) meet. Someone who is exactly average on the predictor will get an exactly average predicted score on the outcome. The regression line pivots on the two means, like the balance beam in Chapter 3, except we’re balancing both means simultaneously.

Each unit to the right changes the height of the line by \(b\). From \(X = 0\) to \(X = M_X\), that’s a change of \(b M_X\). Subtract that from \(M_Y\) and we reach the intercept.

\[ a = M_Y - b M_X \]

For our data:

\[ a = 70 - (-10) \times 1 = 80 \]

In other words, we predict a score of 80 for a student who drank no coffee.

Testing regression

Now we have our regression line, a model of the world in which we predict people who drank no coffee will score 80 on our exam, and each cup someone drinks will lower their predicted score by 10 points: \(\hat{Y} = -10X + 80\).

We can use that regression equation to see the predictions for each of the seven students in our data set.

\(X\) \(Y\) \(\hat{Y}\)
\(0\) \(90\) \(-10(0) + 80 = 80\)
\(0.5\) \(60\) \(-10(0.5) + 80 = 75\)
\(0.5\) \(85\) \(-10(0.5) + 80 = 75\)
\(1\) \(65\) \(-10(1) + 80 = 70\)
\(1.5\) \(50\) \(-10(1.5) + 80 = 65\)
\(1.5\) \(65\) \(-10(1.5) + 80 = 65\)
\(2\) \(75\) \(-10(2) + 80 = 60\)

Sums of squares

Not all of the predictions are perfect. In fact, there’s only one student whose test score is exactly what the line predicted: the student who drank a cup and a half and scored 65.

So the next question is, how good is this model? Answering that requires a different model to compare against: a model in which we don’t use coffee as a predictor. That would be the flat line from the quiz at the start of the chapter, where we just guess the mean test score, 70, for everyone.

The flat line’s misses are just each score’s deviation from the mean of \(Y\), \(Y - M_Y\). So its squared misses add up to the sum of squares for \(Y\), which we found in Chapter 17: \(SS_Y = 1200\). That’s how wrong we’d be giving everyone the same guess.

The regression line’s misses are the residuals, \(Y - \hat{Y}\). Their squares add up to \(SS_{\text{residual}} = 900\), the smallest total any straight line can produce for this data.

The difference, \(1200 - 900 = 300\), is how much squared error we avoided by letting the line tilt. That’s the regression sum of squares, \(SS_{\text{regression}}\). We get the same total by squaring and adding up how far each prediction moved from the mean, \(\hat{Y} - M_Y\).

So we have three very similar equations:

\[ \begin{aligned} SS_Y &= \Sigma(Y - M_Y)^2 = 1200 \\ SS_{\text{regression}} &= \Sigma(\hat{Y} - M_Y)^2 = 300 \\ SS_{\text{residual}} &= \Sigma(Y - \hat{Y})^2 = 900 \end{aligned} \]

All three sums are in squared test points. What changes is which two things we take the difference between: a score and the mean, a prediction and the mean, or a score and its prediction. Table 18.1 does this for all seven students.

Table 18.1: Cups of coffee (\(X\)), test scores (\(Y\)), and predicted scores (\(\hat{Y}\)) for the seven students, with each student’s squared deviations for the three sums of squares. Tap or hover over any green value to see how it was calculated.
\(X\) \(Y\) \(\hat{Y}\) \((Y - M_Y)^2\) \((\hat{Y} - M_Y)^2\) \((Y - \hat{Y})^2\)
\(0\) \(90\) \(80\) \(400\) \(100\) \(100\)
\(0.5\) \(60\) \(75\) \(100\) \(25\) \(225\)
\(0.5\) \(85\) \(75\) \(225\) \(25\) \(100\)
\(1\) \(65\) \(70\) \(25\) \(0\) \(25\)
\(1.5\) \(50\) \(65\) \(400\) \(25\) \(225\)
\(1.5\) \(65\) \(65\) \(25\) \(25\) \(0\)
\(2\) \(75\) \(60\) \(25\) \(100\) \(225\)
\(M_X = 1\) \(M_Y = 70\) \(M_{\hat{Y}} = 70\) \(SS_Y = 1200\) \(SS_{\text{regression}} = 300\) \(SS_{\text{residual}} = 900\)

In case the math feels a bit abstract, Activity 18.1 visualizes each of the sums of squares getting produced.

Activity 18.1: Three sums of squares
For the seven students, squared deviations from the mean fill a square with area 1200. Squared residuals from the fitted line fill 900 of it. Squared deviations of the predictions from the mean fill the remaining 300.

Here are the seven coffee and test score pairs as a scatterplot.

What if we ignored \(X\) and just guessed the mean of \(Y\) every time? That’s a flat line at 70. Squaring each score’s distance from the line and summing the squares gives \(SS_Y = \Sigma (Y - M_Y)^2 = 1200\), the total variability in test scores.

The line of best fit traces the best path through the points: \(\hat{Y} = -10X + 80\).

Now we do the same thing as before, but with the best-fit line. First, the vertical distance shows how far off our prediction was. For a point on the line the prediction is exactly right and the residual is zero. For every point we calculate the residual the same way, \(Y - \hat{Y}\).

Then we square each residual. The student whose score we missed by 15 points contributes a square with an area of 225.

Now sum the squares. Add up the areas for all seven students and we get \(SS_{residual} = \Sigma (Y - \hat{Y})^2 = 900\). That fills a big chunk of the square, showing the collective error in our regression’s predictions—variability in test scores not accounted for by coffee.

The remaining chunk is the variability in test scores that is predictable from the coffee variable. We can find it by simple subtraction—it’s the leftover part of the big \(SS_Y\) square. Or we can find it by squaring the differences between the predicted values and the mean of \(Y\); \(SS_{regression} = \Sigma (\hat{Y} - M_Y)^2 = 300\). It fills the gap exactly. It shows how much we have reduced the squared error by using coffee to predict test scores rather than just guessing that everyone will get an average score.

Looking again at the squared residuals, this line—the line of best fit—leaves us with 900. No other line does better—that’s what makes it the least-squares solution. But you don’t have to take my word for it. Play with the sliders below the plot to try any slope and intercept you like. Remember the line we imagined moving down five points? Keep the slope at \(-10\) and change the intercept from 80 to 75. The squared misses for all seven students now add up to 1075.

Partitioning variability

Is this starting to feel like ANOVA to you? That’s because it is! We split the variability in the outcome variable into different components: the part our predictions account for, and what’s left over. The regression line plays the part the group means played in our previous encounters with ANOVA.

Diagram partitioning the total variability in Y into predictable variability (sum of squares regression) and unpredictable variability (sum of squares residual), whose mean squares form the F ratio for the analysis of regression.

The regression and residual sums of squares partition the total, just as between and within did for ANOVA.

\[ \begin{aligned} SS_Y &= SS_{regression} + SS_{residual} \\ 1200 &= 300 + 900 \end{aligned} \]

With the sums, we can ask what proportion of the total the line accounted for:

\[ r^2 = \frac{SS_{regression}}{SS_Y} = \frac{300}{1200} = .25 \]

There’s the same \(.25\) we got by squaring \(r = -.50\) in Chapter 17. In regression this proportion is called the coefficient of determination. It plays the same part as \(\eta^2\) in ANOVA. Here, knowing coffee consumption accounts for a quarter of the variability in these seven test scores. The other three quarters, \(SS_{residual}/SS_Y = 900/1200 = .75\), is the \(1 - r^2\) that went into the standard error of the correlation in Chapter 17. Back then we described it as the variability unaccounted for by the relationship. Now you can see exactly what that is: the squared misses around the regression line.

Degrees of freedom

We’ll need some degrees of freedom to go with our sums of squares.

\[ \begin{aligned} df_Y &= n - 1 \\ df_{\text{residual}} &= n - 2 \\ df_{\text{regression}} &= df_Y - df_{\text{residual}} \end{aligned} \]

Can you follow the logic? For our data, \(df_Y = 7 - 1 = 6\); seven values deviating around their mean costs one degree of freedom. You can also think of it as the points deviating from a line with no slope, just an intercept; fixing the deviations around that costs the degree of freedom since the deviations around the flat line must sum to zero. \(df_{\text{residual}} = 7 - 2 = 5\); seven values deviating around the regression line costs two degrees of freedom, because this line is defined by two parameters, its intercept and its slope. That leaves one degree of freedom left over for the regression; \(df_{\text{regression}} = 6 - 5 = 1\).

Mean squares

As in ANOVA, we divide each sum of squares by its degrees of freedom to get a mean square. Then we take the ratio of \(MS_{regression}\) to \(MS_{residual}\) to get the \(F\) statistic for the regression model.

\[ MS_{regression} = \frac{SS_{regression}}{df_{regression}} \]

\[ MS_{residual} = \frac{SS_{residual}}{df_{residual}} \]

\[ F = \frac{MS_{regression}}{MS_{residual}} \]

What if the population line were flat?

0 of 2
1

Suppose coffee had nothing to do with test scores in the population, so the population slope is exactly zero. We take a sample of seven students and fit the least-squares line. What should we expect of the sample slope?

Response options

Exactly zero in every sample

It would vary from sample to sample and usually be nonzero

Negative in every sample

Answer

It would vary from sample to sample and usually be nonzero

Explanation

Just as a sample mean usually misses the population mean, the sample slope will usually miss zero. The line tilts to follow whatever ups and downs happen to be in the sample.

2

If the fitted line tilts, what does that tell us about \(SS_{regression}\)?

Response options

Exactly zero

Above zero

Below zero

Answer

Above zero

Explanation

Above zero. If the best-fit line tilts, it saves some squared error compared with guessing the mean. That can happen by chance, even when the population slope is zero.

Quiz 18.3

If the population slope is zero, both mean squares estimate the same error variance, just like in Chapter 14. They can still differ by chance. A nonzero population slope tends to make \(MS_{regression}\) larger and pushes \(F\) up. But how large is large enough to be considered statistically significant? All that remains is to formally work through the hypothesis testing procedure.

A regression test, step by step

Now that we can find an \(F\) ratio for regression, we can follow the same four-step hypothesis testing procedure we used for ANOVA.

Step 1: State the hypotheses

A null hypothesis about a regression says that there is no linear relationship between the predictor and the outcome. In our case, knowing how much coffee someone drank would be no help in making a prediction of their test score. More technically, the hypothesis concerns the slope of the regression line: in the population, the slope is zero. The alternative is that the population slope could go either way, up or down.

In keeping with our usual system of using Greek letters for population parameters, we will write the population slope as \(\beta\), the Greek letter beta (versus the lowercase \(b\) for the slope in the sample).

\[ H_0: \beta = 0 \]

\[ H_1: \beta \ne 0 \]

Step 2: Set the decision criteria

Since regression produces an \(F\) statistic, we use the same table we introduced in Chapter 14, showing values of the \(F\) distribution under the null hypothesis, to set our decision criteria. We look up the critical value based on the degrees of freedom in the numerator (\(df_{\text{regression}} = 1\)) and denominator (\(df_{\text{residual}} = 5\)) of our \(F\) ratio. With \(\alpha = .05\), we reject the null if \(F > 6.61\).

Table 18.2: An excerpt of the \(F\) table for \(\alpha = .05\), with the critical value for \(F(1, 5)\) highlighted.
F table excerpt for numerator df 1 through 4 and denominator df 3 through 7, highlighting the .05 critical value of 6.61 at F(1, 5).

Step 3: Collect and analyze the data

Here’s the summary of the \(SS\) and \(df\) values we calculated on our way through this chapter so far, with the \(MS\) and final \(F\) ratio filled in.

Table 18.3: Summary table for the analysis of regression on the coffee data.
Source \(SS\) \(df\) \(MS\) \(F\)
Regression \(300\) \(1\) \(300\) \(1.67\)
Residual \(900\) \(5\) \(180\)
Total \(1200\) \(6\)

The denominator of our \(F\) ratio, \(MS_{residual} = 180\), estimates the variance of the scores around the line. Its square root, \(\sqrt{180} \approx 13.42\), is called the standard error of the estimate. Statistical software often reports this alongside the regression. It’s the regression version of a standard deviation: variance put back into the original units by taking its square root. Our predictions were typically off by about 13 test points.

Step 4: Make a decision

Our \(F\) of 1.67 falls short of 6.61, so we fail to reject the null. The line did better than the flat line for these seven students, but the test gives us little evidence that coffee improves straight-line predictions in the population.

This is the same answer that the correlation test led to. In fact, we get exactly the same \(p = .25\) as in Chapter 17. Remember how Chapter 14’s two-group \(F\) was the square of the independent-samples \(t\)? With one predictor, the regression \(F\) is the square of the \(t\) for the correlation. Here \((-1.291)^2 \approx 1.67\).

Figure 18.3: The observed \(F = 1.67\) falls short of the critical value of the null \(F\) distribution with 1 and 5 degrees of freedom.
Null F distribution with 1 and 5 degrees of freedom. The rejection region lies beyond 6.61; the observed F of 1.67 falls short of it.

Reporting and interpreting the results

When we report the results, we can mention the general trend in the data as reflected in \(b\), the slope of the regression line. And then we mention the \(F\) ratio for the analysis of regression with its degrees of freedom and its \(p\)-value. We can also say how much of the variability the line accounted for.

Each additional cup of coffee was associated with a predicted test score 10 points lower (\(b = -10\)). Coffee consumption accounted for 25% of the variability in scores, \(F(1, 5) = 1.67\), \(p = .25\), \(r^2 = .25\).

As usual, there are some assumptions behind the test. We’re assuming the students’ observations are independent and that the mean test score follows a straight line as we move along the coffee axis. At any given amount of coffee, we expect scores to be roughly normally distributed around the line, with about the same spread from one amount of coffee to the next.

One way to check the straight-line fit and the spread is to plot the residuals. In the three imaginary samples in Figure 18.4, each dot shows how far one student’s score fell above or below the prediction for the amount of coffee they drank. Zero means we got their score exactly right. We’d like to see a band of dots centered on zero, about the same thickness all the way across. The first plot shows that kind of scatter. The other two are examples of patterns that would violate the assumptions: a curved pattern to the residuals, suggesting a straight line is not the best fit, and a fan shape, suggesting the spread of scores is not constant across the range of coffee consumption.

Figure 18.4: In the first plot, the misses stay centered around zero and their spread stays roughly the same from one end to the other. In the curved pattern, the line predicts too low at both ends and too high in the middle. In the fan, the predictions still look about right on average, but they miss by more in either direction among the heavier coffee drinkers.
Residuals form a roughly even band above and below zero across the range of coffee consumption.
Residuals form a U, above zero at low and high coffee amounts and below zero in the middle.
Residuals stay centered near zero but fan out as coffee consumption increases.

As usual, our tiny toy data set isn’t really sufficient to check these assumptions rigorously or make any real inferences about coffee and test scores. But even if the data were real and there was enough of it to reach significance, we would still need to be cautious about interpreting the result. Regression analysis is a bit more mathematically sophisticated than the correlation coefficient, and it frames the variables as predictor and outcome, but this doesn’t change the caveats about correlation versus causation. We couldn’t conclude that coffee caused the change in test scores just from a significant regression \(F\) ratio. Perhaps being good on a test somehow caused people to drink less coffee. Or there could be other variables at play, like sleep, that we haven’t accounted for. Maybe under-slept students tend to do worse on the test, and their coffee consumption is just a side effect.

Predicting test scores from sleep

0 of 5
1

In Chapter 17 we also recorded how long each of the seven students slept. Now use sleep (\(Z\)) instead of coffee to predict test score (\(Y\)).

Hours of sleep (\(Z\)) Test score (\(Y\)) \((Z - M_Z)(Y - M_Y)\)
9 90 40
8 60 -10
8 85 15
5 65 10
6 50 20
6 65 5
7 75 0
\(M_Z = 7\) \(M_Y = 70\)
\(SS_Z = 12\) \(SS_Y = 1200\) \(SP = 80\)

What is the slope, in test points per hour of sleep?

Hint

Just as with coffee, divide the sum of products by the sum of squares for the predictor.

Answer

6.67

Explanation

\(b = SP / SS_Z = 80 / 12 \approx 6.67\). Each extra hour of sleep goes with a predicted score about 6.67 points higher.

2

The students slept an average of \(M_Z = 7\) hours, and their mean score was \(M_Y = 70\). What is the intercept?

Hint

The line goes through the point where the two means meet.

Answer

23.33

Explanation

\(a = M_Y - b M_Z = 70 - (80/12)(7) \approx 70 - 46.67 = 23.33\). So \(\hat{Y} = 6.67Z + 23.33\), which predicts 70 for someone who slept the average seven hours.

3

Use the slope and intercept to predict the test score for a student who slept nine hours. What is \(\hat{Y}\)?

Hint

Substitute \(Z = 9\) into \(\hat{Y} = bZ + a\).

Answer

83.33

Explanation

Using the unrounded slope and intercept, \(\hat{Y} = (80/12)(9) + [70 - (80/12)(7)] \approx 83.33\). Using \(6.67\) and \(23.33\) gives \(83.36\), a small rounding difference.

4

Here are the predictions for all seven students, calculated with the unrounded slope and intercept and then rounded to two decimal places.

Hours of sleep (\(Z\)) Predicted score (\(\hat{Y}\))
9 83.33
8 76.67
8 76.67
5 56.67
6 63.33
6 63.33
7 70.00

The mean test score is still \(M_Y = 70\). Find \(SS_{regression}\) by squaring each prediction’s distance from that mean and adding the seven squares.

Hint

Use \(SS_{regression} = \Sigma(\hat{Y} - M_Y)^2\). The first prediction contributes \((83.33 - 70)^2\). Include a square for each student, even when students have the same prediction.

Answer

533.33

Explanation

\(SS_{regression} \approx 13.33^2 + 6.67^2 + 6.67^2 + (-13.33)^2 + (-6.67)^2 + (-6.67)^2 + 0^2 = 533.33\). This is the variability in the predicted scores around the mean: the part of the test-score variability that sleep accounts for.

5

The total sum of squares for test scores is still \(SS_Y = 1200\). Using your answer to the previous question, what is \(SS_{residual}\) for the line predicting test score from sleep?

Hint

\(SS_Y = SS_{regression} + SS_{residual}\). Subtract the part the line accounts for from the total. You should have found \(SS_{regression} = 533.33\) in the previous question.

Answer

666.67

Explanation

\(SS_{residual} = 1200 - 533.33 = 666.67\). Sleep on its own accounts for more of the variability in test scores than coffee did, 44% against 25%.

Quiz 18.4

Multiple regression

We saw one way to incorporate a potential third variable like sleep into our analysis with the partial correlation in Chapter 17. But much like ANOVA allowed us to compare any number of groups, regression can handle multiple predictors in a single model. A model with two (or more) predictors is called a multiple regression.

In our simple regression with just coffee (\(X\)) predicting test score (\(Y\)), we computed the slope and intercept of their fit line to make predictions (\(\hat{Y}\)) for each student. In multiple regression, we still make the same kind of predictions, but the predictions take into account scores on both predictors. Each predictor gets its own slope in the regression equation:

\[ \hat{Y} = b_1 X + b_2 Z + a \tag{18.5}\]

To make predictions, we multiply cups of coffee by one slope and hours of sleep by the other, then add the intercept. The logic of determining those slopes and the intercept is the same as before: we choose the values that make the sum of squared residuals as small as possible.

So how do we find the two slopes? You might think we could just reuse coffee’s slope on its own (\(-10\)) and the slope for sleep on its own that you found in Quiz 18.4 (\(6.67\)). But that wouldn’t give us a better model. In fact, it would defeat the purpose, by treating scores on the predictors as separate, unrelated information. The whole point here is that maybe they are related. The students who drank more coffee tended to sleep less, and those who slept less tended to score lower. Fitting the two slopes separately lets both pick up some of the same pattern in test scores. We need to fit them together, accounting for their relationship with each other.

The problem is that the predictors might vary together; people who get less sleep might drink more coffee or something. To tease them apart, we need to ask how much each predictor contributes to our prediction after accounting for the other predictor. We’ll see exactly what “accounting for” means mathematically, but for now, imagine that we make two predictions for students who got the same amount of sleep. If one drank a cup more coffee than the other, how much do their predicted test scores differ? We say we’re holding sleep constant because we use the same hours of sleep in both predictions. For the sleep slope we flip the question around: if two students drank the same amount of coffee but one slept an hour longer, how much do their predicted test scores differ? That’s what the two slopes capture.

Calculating the slopes

Here are the seven students again, this time with their hours of sleep alongside their coffee and test scores (the same sleep data from Quiz 18.4).

Table 18.4: The seven students’ coffee, sleep, and test scores, from Chapter 17.
Participant Coffee (\(X\)) Sleep (\(Z\)) Test score (\(Y\))
A \(0\) \(9\) \(90\)
B \(0.5\) \(8\) \(60\)
C \(0.5\) \(8\) \(85\)
D \(1\) \(5\) \(65\)
E \(1.5\) \(6\) \(50\)
F \(1.5\) \(6\) \(65\)
G \(2\) \(7\) \(75\)

To remove the part of coffee that sleep predicts, we initially compute another simple regression, this time with sleep as the predictor and coffee as the outcome. Finding the slope and intercept for their fit line allows us to generate a new set of predictions: \(\hat{X}\), the amount of coffee we’d predict from each student’s sleep. Then we see how much more or less coffee each student drank than we predicted from their sleep. That gives a new set of residuals, \(X - \hat{X}\). We square those residuals and add them up to get a sum of squares for coffee after taking sleep into account. Let’s label that \(SS_{X \cdot Z}\), the sum of squared deviations for \(X\) accounting for its relationship with \(Z\). We also multiply the new residuals by the old test score deviations, \(Y - M_Y\), to get a new set of products. Summing those gives a new sum of products, \(SP_{XY \cdot Z}\). Dividing the sum of products by the sum of squares gives us the slope for coffee in the multiple regression model: change in test score per cup of coffee, after accounting for coffee’s association with sleep.

\[ b_1 = \frac{SP_{XY \cdot Z}}{SS_{X \cdot Z}} \]

Table 18.5 shows all of this. It’s a lot, so start with the first row. From that student’s nine hours of sleep we’d predict about a third of a cup of coffee. They drank none, so their coffee residual is about \(-0.33\) cups. Tap or hover over any green value to see how it was calculated.

Table 18.5: Each student’s coffee predicted from their sleep (\(\hat{X}\)), the residuals, and their products with the test score deviations. Values are rounded to two decimal places; the sums use the exact values. Tap or hover over any green value to see how it was calculated.
Sleep (\(Z\)) Coffee (\(X\)) \((Z - M_Z)(X - M_X)\) \(\hat{X}\) \(X - \hat{X}\) \((X - \hat{X})^2\) Score (\(Y\)) \(Y - M_Y\) \((X - \hat{X})(Y - M_Y)\)
\(9\) \(0\) \(-2\) \(0.33\) \(-0.33\) \(0.11\) \(90\) \(20\) \(-6.67\)
\(8\) \(0.5\) \(-0.5\) \(0.67\) \(-0.17\) \(0.03\) \(60\) \(-10\) \(1.67\)
\(8\) \(0.5\) \(-0.5\) \(0.67\) \(-0.17\) \(0.03\) \(85\) \(15\) \(-2.5\)
\(5\) \(1\) \(0\) \(1.67\) \(-0.67\) \(0.44\) \(65\) \(-5\) \(3.33\)
\(6\) \(1.5\) \(-0.5\) \(1.33\) \(0.17\) \(0.03\) \(50\) \(-20\) \(-3.33\)
\(6\) \(1.5\) \(-0.5\) \(1.33\) \(0.17\) \(0.03\) \(65\) \(-5\) \(-0.83\)
\(7\) \(2\) \(0\) \(1\) \(1\) \(1\) \(75\) \(5\) \(5\)
\(M_Z = 7\) \(M_X = 1\) \(M_{\hat{X}} = 1\) \(M_Y = 70\)
\(SS_Z = 12\) \(SS_X = 3\) \(SP_{XZ} = -4\) \(SS_{X \cdot Z} = 1.67\) \(SP_{XY \cdot Z} = -3.33\)

\[ \begin{aligned} b &= \frac{SP_{XZ}}{SS_Z} = \frac{-4}{12} = -\frac{1}{3} \\ a &= M_X - b M_Z = 1 - \left(-\frac{1}{3}\right)(7) = \frac{10}{3} \\ \hat{X} &= -\frac{1}{3}Z + \frac{10}{3} \end{aligned} \]

\[ b_1 = \frac{SP_{XY \cdot Z}}{SS_{X \cdot Z}} = \frac{-10/3}{5/3} = -2 \]

So at the same amount of sleep, one more cup of coffee goes with a predicted score two points lower.

To get the slope for sleep, holding coffee constant, do a second mini regression like that first one, now with the variables flipped around: sleep (\(Z\)) as outcome and coffee (\(X\)) as predictor. We find that slope and intercept to get a set of \(\hat{Z}\) predictions, residuals (\(Z - \hat{Z}\)), and the sum of squared residuals for sleep accounting for coffee consumption, \(SS_{Z \cdot X}\). Multiply the residuals by the test score deviations and add those up to get a sum of products, \(SP_{ZY \cdot X}\). Divide to get the slope for sleep: change in test score per hour of sleep, after accounting for sleep’s association with coffee.

\[ b_2 = \frac{SP_{ZY \cdot X}}{SS_{Z \cdot X}} \]

Table 18.6: Each student’s sleep predicted from their coffee (\(\hat{Z}\)), the residuals, and their products with the test score deviations. Values are rounded to two decimal places; the sums use the exact values.
Coffee (\(X\)) Sleep (\(Z\)) \((X - M_X)(Z - M_Z)\) \(\hat{Z}\) \(Z - \hat{Z}\) \((Z - \hat{Z})^2\) Score (\(Y\)) \(Y - M_Y\) \((Z - \hat{Z})(Y - M_Y)\)
\(0\) \(9\) \(-2\) \(8.33\) \(0.67\) \(0.44\) \(90\) \(20\) \(13.33\)
\(0.5\) \(8\) \(-0.5\) \(7.67\) \(0.33\) \(0.11\) \(60\) \(-10\) \(-3.33\)
\(0.5\) \(8\) \(-0.5\) \(7.67\) \(0.33\) \(0.11\) \(85\) \(15\) \(5\)
\(1\) \(5\) \(0\) \(7\) \(-2\) \(4\) \(65\) \(-5\) \(10\)
\(1.5\) \(6\) \(-0.5\) \(6.33\) \(-0.33\) \(0.11\) \(50\) \(-20\) \(6.67\)
\(1.5\) \(6\) \(-0.5\) \(6.33\) \(-0.33\) \(0.11\) \(65\) \(-5\) \(1.67\)
\(2\) \(7\) \(0\) \(5.67\) \(1.33\) \(1.78\) \(75\) \(5\) \(6.67\)
\(M_X = 1\) \(M_Z = 7\) \(M_{\hat{Z}} = 7\) \(M_Y = 70\)
\(SS_X = 3\) \(SS_Z = 12\) \(SP_{XZ} = -4\) \(SS_{Z \cdot X} = 6.67\) \(SP_{ZY \cdot X} = 40\)

\[ \begin{aligned} b &= \frac{SP_{XZ}}{SS_X} = \frac{-4}{3} \\ a &= M_Z - b M_X = 7 - \left(-\frac{4}{3}\right)(1) = \frac{25}{3} \\ \hat{Z} &= -\frac{4}{3}X + \frac{25}{3} \end{aligned} \]

\[ b_2 = \frac{SP_{ZY \cdot X}}{SS_{Z \cdot X}} = \frac{40}{20/3} = 6 \]

Intercept and regression equation

We have two slopes, but there’s only one intercept. We can use the same logic as before, that the relationship pivots on the means of all three variables. The predicted score for a student with average coffee and average sleep will be the average test score. So we can solve for \(a\) in the multiple regression equation, using the means of all three variables.

\[ a = M_Y - b_1 M_X - b_2 M_Z \]

Plugging in our two slopes and the three means gives us:

\[ a = 70 - (-2)(1) - 6(7) = 30 \]

So if someone drank no cups of coffee and slept for zero hours (yikes), we’d predict a test score of 30. That doesn’t mean that anyone in our sample had that combination of coffee and sleep answers (our students all slept between five and nine hours), or that we necessarily expect it to be a realistic scenario. It’s just the point where a score of \(0\) on both predictors intersects the \(Y\) axis according to the equation.

That gives us the multiple regression equation:

\[ \hat{Y} = -2X + 6Z + 30 \]

For someone who slept six hours and drank a cup and a half, we get a predicted test score of \(-2(1.5) + 6(6) + 30 = 63\). Now keep sleep at six hours and change coffee from one and a half cups to half a cup. The predicted score goes up by just two points. With coffee alone that same change raised the prediction by ten points. That’s what the coffee slope means with sleep in the equation. Likewise, holding coffee constant, each extra hour of sleep raises the predicted score by six points.

Picturing the sums of squares

Now that we produced the regression equation, we can check the prediction errors just as we did in Table 18.1. Two students had those same six hours and one and a half cups. Their prediction goes from 65 with coffee alone to 63 with both predictors. Their scores were 50 and 65, so their new residuals are \(-13\) and \(+2\).

Table 18.7: Predicted values and residuals with both coffee and sleep as predictors. \(SS_{residual} = 660\).
Coffee (\(X\)) Sleep (\(Z\)) Score (\(Y\)) \(\hat{Y}\) \(Y - \hat{Y}\) \((Y - \hat{Y})^2\)
\(0\) \(9\) \(90\) \(84\) \(6\) \(36\)
\(0.5\) \(8\) \(60\) \(77\) \(-17\) \(289\)
\(0.5\) \(8\) \(85\) \(77\) \(8\) \(64\)
\(1\) \(5\) \(65\) \(58\) \(7\) \(49\)
\(1.5\) \(6\) \(50\) \(63\) \(-13\) \(169\)
\(1.5\) \(6\) \(65\) \(63\) \(2\) \(4\)
\(2\) \(7\) \(75\) \(68\) \(7\) \(49\)
\(M_X = 1\) \(M_Z = 7\) \(M_Y = 70\) \(M_{\hat{Y}} = 70\) \(SS_{\text{residual}} = 660\)

Notice what happens if we fix sleep at a particular value. For someone who slept nine hours, the equation becomes \(-2X + 6(9) + 30\), or \(-2X + 84\). That’s just an ordinary straight line, with a slope of \(-2\) and an intercept of 84. Every amount of sleep gives a line like that, all with the same slope, each 6 points above the one for an hour less.6 That gives us a way of visualizing the sums of squares we just computed using the equations.

Activity 18.2: Adding sleep
The seven students' coffee and test scores, colored by how long they slept. Dashed outlines first move to the prediction of one cup at seven hours of sleep, then move left or right by each student's coffee residual. The fit through the adjusted outlines has a slope of −2 points per cup. Back at the real cups, that line becomes the seven-hour line of five parallel lines, one for each amount of sleep from 5 to 9 hours, each falling 2 points per cup and 6 points higher for each extra hour. Squared misses from each student's own line add up to 660 of the total 1200. The squared distances from each prediction to the mean fill the other 540.

Here’s where we left off: coffee on its own, the line of best fit, and its squared misses filling three quarters of the square.

To show how the multiple regression model incorporates sleep, let’s color each student by how long they slept, darker for more sleep. You can see a bit of a pattern already: the darker dots tend to sit toward the left. The students who slept more drank less coffee.

To take sleep out of the equation (so to speak), we’ll put everyone at the same starting point. Seven hours was the average amount of sleep, and our model with sleep predicting coffee predicts one cup of coffee at seven hours of sleep. So we adjust each coffee value to the one-cup line as a dashed outline. (Each dot’s height stays the same; we’re only adjusting coffee, not changing test scores.)

But that model had some error in its predictions. So now we add the residuals in the \(X - \hat{X}\) column of Table 18.5 to the one cup. It tells us how much more or less coffee each student drank than we predicted for the hours they actually slept. The student who scored 90 on the test drank a third of a cup less than predicted based on their 9 hours of sleep, so their adjusted dot moves to about \(0.67\). We do that for everyone and fit a line through the adjusted values. Its slope is \(-2\) points per cup. That’s \(b_1\), the coffee slope after accounting for sleep.

Doing the same thing for the regression predicting sleep duration from coffee gave the second slope, \(b_2 = 6\). At this point, a lot of books would have a graph showing the two slopes as a 3-dimensional plane. But I like to picture a set of parallel lines, one for each sleep duration, set 6 test-points apart. Each one holds sleep constant and shows the test score predictions for each amount of coffee. The predicted score always drops by 2 points for each additional cup of coffee, but now we can see how adding an hour of sleep (moving to the next line up) adds 6 predicted points.

Now we collect the prediction errors just as before, but the errors are relative to the corresponding sleep line. This student drank no coffee and slept nine hours, so we read their prediction off the nine-hour line. They scored a little higher than predicted. That’s the residual that we square.

The student who scored 85 slept eight hours and drank half a cup of coffee. The eight-hour line predicts a score of 77. They scored eight points higher than predicted, so their residual is \(+8\) and its square is 64.

And the same for everyone else, each measured from the line for their own amount of sleep.

Collect the squares. With both predictors, they add up to 660. That’s \(SS_{\text{residual}} = 660\) for the multiple regression model with both predictors, the same as we found in Table 18.7.

As before, the rest of the square is what our predictions saved us compared with just guessing that everyone would get an average test score. Each white circle marks a predicted score. Square the distance from each prediction to the mean test score, and sum the squares. That gives \(SS_{\text{regression}} = 540\), filling the remaining portion of the big \(SS_Y\) square exactly.

Finishing the regression

We’re predicting the same seven test scores, so the total sum of squares is still \(SS_Y = 1200\). The residual sum of squares drops from \(900\) to \(660\), leaving \(1200 - 660 = 540\) accounted for by the two predictors together. This time there are two slopes, so regression gets two degrees of freedom. Estimating those slopes and the intercept leaves \(7 - 3 = 4\) degrees of freedom for the residual.

Table 18.8: Summary table for the regression with coffee and sleep as predictors.
Source \(SS\) \(df\) \(MS\) \(F\)
Regression \(540\) \(2\) \(270\) \(1.64\)
Residual \(660\) \(4\) \(165\)
Total \(1200\) \(6\)

\[ R^2 = \frac{SS_{regression}}{SS_Y} = \frac{540}{1200} = .45 \]

With more than one predictor we write this proportion as capital \(R^2\). Coffee alone accounted for 25% of the variability in our sample. Coffee and sleep together account for 45%.

The overall \(F\) tests the two slopes together against a model that just predicts the mean test score for everyone. The null hypothesis is that both slopes are zero in the population. Here \(F(2, 4) = 1.64\), \(p = .30\).

What does each predictor add?

0 of 2
1

Coffee alone accounted for 25% of the variability in these seven test scores. Coffee and sleep together account for 45%. Once we already know how much coffee someone drank, what percentage of the total variability in test scores does knowing their sleep add?

Answer

20

Explanation

\(45 - 25 = 20\) percentage points. That’s the part of the variability in test scores that sleep accounts for and coffee doesn’t.

2

In these data, students who slept less tended to drink more coffee and tended to score lower. Now flip the question. Once we already know how much someone slept, how much do you expect knowing their coffee consumption to add?

Response options

About 25%, the same as coffee alone

Less than 25%, because some of what coffee told us, sleep tells us too

More than 25%, because now we have two predictors

Answer

Less than 25%, because some of what coffee told us, sleep tells us too

Explanation

Less. Much of the information coffee gave us about test scores was information about sleep. If sleep is already in the equation, coffee can only add what sleep doesn’t already tell us. We’ll see just how much less in a moment.

Quiz 18.5

Testing each predictor

The overall \(F\) tells us whether coffee and sleep together predict test scores better than chance would. But it doesn’t tell us how much of that predictability is coming from coffee on its own, how much is from sleep, or how much is coming from the two together—from what they share.

To find each predictor’s unique contribution to the regression model, we can compare that full multiple regression model with the simpler models we’ve put together throughout this chapter: the first one, with just coffee predicting test scores, and the one you calculated in Quiz 18.4 with sleep predicting test scores.

The model with both coffee and sleep as predictors accounted for the most variability, of course; adding more predictors can never lower \(SS_{\text{regression}}\). For that model, \(SS_{\text{regression}}\) was \(540\). In comparison, the regression with coffee as the only predictor had \(SS_{\text{regression}} = 300\). In other words, adding sleep to the coffee model increased the regression sum of squares by \(540 - 300 = 240\). That is sleep’s unique contribution in the full, two-predictor model: what sleep accounts for that coffee doesn’t.

On the other hand, the model with sleep as the only predictor had \(SS_{\text{regression}} = 533.33\). Adding coffee only increased the regression sum of squares by \(540 - 533.33 = 6.67\). That is the unique contribution of coffee in the full model, the variability in test scores that coffee consumption accounts for and sleep doesn’t.

Table 18.9: What each model accounts for and what it misses, with both predictors and with each one alone. The regression and residual sums of squares in each row add up to 1200. Dropping a predictor increases the squared misses by the amount only that predictor could account for.
Predictors Dropped \(SS_{\text{regression}}\) \(SS_{\text{residual}}\) Increase in \(SS_{\text{residual}}\)
Coffee and sleep \(540\) \(660\)
Coffee Sleep \(300\) \(900\) \(240\)
Sleep Coffee \(533.33\) \(666.67\) \(6.67\)

We have a sum of squares value each predictor can claim as its own. That means we can test each predictor separately to see whether it adds significantly to the model once we account for the other predictor. As usual, we divide the \(SS\) by its \(df\) to get a mean square. Each predictor’s sum of squares has one degree of freedom.

Both tests use the same denominator, the same one we used for the \(F\) test for the model as a whole: the residual mean square, \(MS_{\text{residual}} = 165\).

\[ F_{sleep} = \frac{240}{165} \approx 1.45 \qquad F_{coffee} \approx \frac{6.67}{165} \approx 0.04 \]

Activity 18.3: Each predictor’s own part
The regression sum of squares with both predictors, 540, drawn as a square. A band of 240 grows up from the bottom: what only sleep accounts for. A sliver of 6.67 grows on top of it: what only coffee accounts for. The remaining 293.33 is shared. The rest of the square fades away, and the two predictors' parts move out as squares of their own. Each is divided by its 1 degree of freedom, so its mean square is the same as its sum of squares. Under each, a fraction line and the residual mean square, 165: 240 over 165 gives F of about 1.45 for sleep, and 6.67 over 165 gives about 0.04 for coffee.

Here’s the regression sum of squares for the model with both predictors, 540, drawn as a square.

Coffee alone accounted for 300. Adding sleep brought the model up to 540, so \(540 - 300 = 240\) belongs to sleep alone: what sleep accounts for that coffee doesn’t.

Sleep alone accounted for 533.33. Adding coffee only brought the model up to 540, so coffee’s own part is \(540 - 533.33 = 6.67\). It’s just a sliver.

The rest, \(540 - 240 - 6.67 = 293.33\), is shared. It’s the part of coffee that just tracks sleep, and the part of sleep that just tracks coffee. Either predictor could account for it on its own, so we’d only lose it by dropping both.

Each predictor’s test uses only its own part. The shared part goes to neither test, so we set it aside and pull out the two predictors’ parts as squares of their own, with the same areas.

To turn each into a mean square, divide by its degrees of freedom. Each predictor’s own part comes from one slope, so it has 1 degree of freedom, and dividing by 1 leaves it as it was: \(240 / 1 = 240\) and \(6.67 / 1 = 6.67\).

Both tests use the same denominator, the residual mean square from the model with both predictors, 165. Each \(F\) is a predictor’s mean square over it: \(240 / 165 \approx 1.45\) for sleep and \(6.67 / 165 \approx 0.04\) for coffee.

With 1 and 4 degrees of freedom, neither of these \(F\) ratios comes close to significance: \(p = .29\) for sleep and \(p = .85\) for coffee.7

The shared part counts toward the overall multiple regression test but not toward either predictor’s own test, so predictors that go together can produce a significant overall test even when neither predictor is significant once we account for the other.

Interpreting multiple regression

Notice how much the coffee slope changed, from \(-10\) on its own to \(-2\) with sleep. A slope in multiple regression always depends on what else is in the equation. Add another predictor that’s related to coffee and the coffee slope could change again.

When we compare the predictors in a model individually, often we want to know if one is more important than the other. The slopes tell us how much each predictor contributes to the prediction of the outcome variable, after accounting for the other predictors in the model. One is in test points per cup, the other in test points per hour. Because cups and hours are different units, we can’t compare the two slopes directly. Software often also reports standardized slopes, which are the slopes you’d get if every variable were first converted to \(z\)-scores. Here they’re \(-.10\) for coffee and \(.60\) for sleep. This permits direct comparison, telling us that sleep is a stronger predictor of the outcome variable than coffee, after accounting for the other predictors in the model. Statistical software often calls these standardized estimates “Beta.” We’ve been using \(\beta\) for the population slope in the original units, so that’s a bit confusing.

And just as with partial correlations in Chapter 17, holding sleep constant is something we’re doing statistically, not experimentally. It tells us what coffee adds to our predictions once we know about sleep. It doesn’t tell us whether coffee or sleep causes anything. Other things we didn’t measure could still be behind the relationships. That’s still a job for random assignment.

Learning Checks

0 of 7
1

Suppose our line predicts test score from hours spent studying. The intercept is 60 and the slope is 4. What does the 4 tell us?

Response options

Students’ scores tend to miss the line by about four points

An extra hour of studying goes with a predicted score four points higher

The predicted score for someone who studied for zero hours is four

Answer

An extra hour of studying goes with a predicted score four points higher

Explanation

Start anywhere on the line and move one hour to the right. The height of the line goes up by four test points.

2

Using that same line, a student studied for three hours and scored 68. What is their residual, in test points?

Hint

First work out the prediction from the slope and intercept.

Answer

-4

Explanation

We predict \(60 + 4(3) = 72\). The student scored four points below that prediction, so their residual is \(68 - 72 = -4\).

3

The students in that study spent between zero and five hours studying. Someone plugs 12 hours into the equation and predicts a score of 108. What’s the problem?

Response options

Nothing, as long as the slope was statistically significant

The line only describes the range of study times we observed

The intercept should be dropped for large values of study time

Answer

The line only describes the range of study times we observed

Explanation

We haven’t seen anyone who studied for 12 hours, so we have no idea whether the relationship carries on in a straight line out there. A score of 108 on a test out of 100 is a good clue that it doesn’t.

4

Suppose we instead used test score to predict how many hours someone studied, using the same students. Compared with the line predicting score from study time, what changes?

Response options

Nothing; it’s the same line, just read the other way

The correlation changes, but the line stays the same

We get a different line, because now we’re minimizing misses in hours

Answer

We get a different line, because now we’re minimizing misses in hours

Explanation

The correlation is the same either way, but the line isn’t. Least squares makes the misses as small as possible on the variable we’re predicting. Unless the correlation is perfect, as with Celsius and Fahrenheit, the two lines differ.

5

Two lines pass through the point where the means meet. For line A, more students fall exactly on the line. For line B, the squared residuals add up to less. Which line fits better by least squares?

Response options

Line A

Line B

They fit equally well

Answer

Line B

Explanation

A few large misses can outweigh several exact predictions. We need the sizes of the misses from all the students to judge the fit.

6

In another class, guessing the mean score for everyone gives a sum of squared deviations of 800. Using study time brings the sum of squared residuals down to 600. What percentage of the variability in scores does the line account for?

Answer

25

Explanation

The line accounts for \(800 - 600 = 200\) of the original 800, so \(r^2 = 200/800 = .25\), or 25%.

7

A researcher uses both study time and hours of sleep to predict test score. The slope for study time is now 3. Which two predictions can we say differ by exactly three points?

Response options

Predictions for students who differ by one hour of study and got the same sleep

Predictions for students who differ by one hour of sleep and studied the same amount

Predictions for students who differ by one hour of study and one hour of sleep

Answer

Predictions for students who differ by one hour of study and got the same sleep

Explanation

Holding sleep steady leaves only the study-time term to change. An extra hour of study adds three points to the prediction.


  1. Which is which depends on the research question. We could use test scores to predict coffee instead. The correlation would stay the same, but the regression model would be different.↩︎

  2. These symbols aren’t universal. When I learned this stuff in school, we used \(m\) for the slope and \(c\) for the intercept. There are both regional and disciplinary differences in the notation. In statistics, \(b\) and \(a\) are the most common symbols for slope and intercept.↩︎

  3. Since there are infinitely many, it’d take forever.↩︎

  4. Here’s another way to see what the formula is doing. Draw a line from the point where the means meet (one cup, 70 points) to each student who drank a different amount from the mean. The student who drank no coffee and scored 90 is one cup to the left and 20 points up, a slope of \(-20\). The student who drank two cups and scored 75 gives a slope of \(+5\). The best-fit slope is a weighted average of those slopes, with weights \((X - M_X)^2\), so students farther from the average amount of coffee get more say. The weighted slopes add up to \(SP = -30\), and the weights add up to \(SS_X = 3\).↩︎

  5. If we convert both variables to \(z\)-scores, \(SS_X\) and \(SS_Y\) are equal. The two formulas then have the same denominator, so with one predictor the slope in \(z\)-score units is just \(r\).↩︎

  6. Parallel lines mean this model has no interaction, in the sense of Chapter 16: the coffee slope is the same at every amount of sleep. Regression can include an interaction, by adding a third predictor made by multiplying each student’s coffee by their sleep. Its slope lets the coffee slope change with the amount of sleep, so the lines no longer have to be parallel.↩︎

  7. Statistical software usually reports a \(t\) for each slope rather than an \(F\). It’s the slope divided by its standard error, and \(t^2 = F\), just like before.↩︎

17  Correlation
References