Regression that ignores the outlier

Today let's see why one bad data point can pull an ordinary regression line's slope away from the true relationship, and how to stop it, using one coffee chain's own weekly numbers.

This chain has fifteen coffee shops. Each one reported its customer visits for one week, in hundreds, and that week's revenue, in thousands of dollars. Visits ranged from 1.0 hundred to 8.0 hundred across the fifteen shops.

Here is all fifteen shops, plotted as visits against revenue.

Fourteen of these points sit close to one rising line. But look at the point sitting apart from it: its visit count is unremarkable, right in the middle of the range, yet its revenue sits far below where that line says it should be.

Least squares and the pull of one point

Let's generate these same fifteen numbers in R, then fit a regression line through all of them, and again through just the fourteen shops that behaved normally.

RInteractive R
# Generate the fifteen coffee shops once, then fit OLS with and without shop 9's bad week set.seed(3) visits <- seq(1, 8, length.out = 14) revenue <- 2 + 1.4 * visits + rnorm(14, 0, 0.6) visits <- c(visits, 7.2) # shop 9's visit count: 7.2 hundred revenue <- c(revenue, 2.0) # shop 9's revenue: only 2 thousand dollars fit_all <- lm(revenue ~ visits) fit_clean <- lm(revenue[-15] ~ visits[-15]) c(all_15_slope = round(unname(coef(fit_all)[2]), 2), clean_14_slope = round(unname(coef(fit_clean)[2]), 2), true_slope = 1.4) #> all_15_slope clean_14_slope true_slope #> 1.06 1.41 1.40

  

lm() fits what is called ordinary least squares, or OLS: of all the straight lines you could draw, it picks the one that makes the sum of each point's squared vertical distance from the line, its residual, as small as possible.

With all fifteen shops, including shop 9, that slope comes out at 1.06, well under the true slope of 1.4 used to generate the data. Drop just that one shop, and the slope on the remaining fourteen comes back to 1.41, almost exactly the true slope.

One shop out of fifteen pulled the slope down by about a quarter of its true value. The next question is why squared error lets one point do that much damage.