Lesson 3 of 8

Influence and Leverage

In Lesson 2, Priya's iced-coffee cart passed its checkup: the residuals-vs-fitted plot was a flat, even band, so linearity and equal variance both held. The line looked trustworthy. But that verdict rested on 12 tidy days. What happens when day 13 is a freak?

A residual plot, and the whole line behind it, can be quietly run by a single row. One unusual observation can grab the least-squares line and swing it somewhere it does not belong, while every other number still looks calm. This lesson teaches you to catch that row. Drag the far-right point below and watch the green line chase it while the grey dashed line (the fit without that point) stays put. That gap between the two lines is the whole lesson.

By the end of this lesson you will be able to:

  • Tell leverage (a point that is unusual in x) apart from influence (a point that actually moves the fit), and see why leverage alone is only the potential to do damage
  • Measure leverage with hat values and influence with Cook's distance, and apply the standard rules of thumb in R
  • Respond to an influential point the right way: investigate it and report the fit with and without it, instead of deleting it on sight

Prerequisites: Lesson 1 (you can fit a line with lm() and read its slope, intercept and R-squared) and Lesson 2 (a residual is actual minus predicted, and you can read a residuals-vs-fitted plot). You can run R and read its output. Every new term is defined as it appears.

The problem

One row can rewrite the whole story

Here are Priya's 12 good days again, and the line they gave her back in Lesson 1: about 1.94 more cups per degree, with temperature explaining 96% of her daily swing (an R-squared of 0.96).

Now add day 13. A heatwave pushes the temperature to a record 39C, exactly the kind of scorcher that should sell her out. But that afternoon a power cut kills her blender for two hours, and she manages only 34 cups. It is one row out of thirteen. Watch what it does to the model.

RInteractive R
# Priya's 12 good days from Lessons 1 and 2 (a fresh session starts empty). coffee <- data.frame( temp = c(15, 17, 18, 20, 21, 23, 24, 26, 27, 29, 30, 31), cups = c(30, 36, 33, 42, 40, 47, 44, 52, 55, 56, 61, 60) ) fit12 <- lm(cups ~ temp, data = coffee) # Add the one freak day: 39C, but a power cut held her to 34 cups. coffee13 <- rbind(coffee, data.frame(temp = 39, cups = 34)) fit13 <- lm(cups ~ temp, data = coffee13) # Put the two fits side by side. round(rbind(with_heatwave = coef(fit13), without = coef(fit12)), 3) #> (Intercept) temp #> with_heatwave 25.745 0.798 #> without 0.818 1.944 round(c(R2_with = summary(fit13)$r.squared, R2_without = summary(fit12)$r.squared), 3) #> R2_with R2_without #> 0.251 0.964

  

Read those numbers slowly. Adding a single day cut the slope from 1.944 to 0.798, less than half its old value, and collapsed R-squared from 0.96 to 0.25. Priya's honest "each warmer degree buys about two more cups" just became "each degree buys less than one," and a model that explained almost everything now explains almost nothing. Nothing about the other 12 days changed. Here is that one point in the picture:

Twelve points march up in a tidy line; the thirteenth sits far to the right and far too low. It is unusual in two different ways at once, and untangling those two kinds of unusual is exactly what leverage and influence are for.