Robust standard errors, and when they are not enough

Today let's understand robust standard errors clearly: when a regression's own standard error can be trusted, and when it cannot.

A retail chain tracks weekly online ad spend and weekly sales across its 50 stores. Ad spend is in hundreds of dollars, sales in thousands. Look at how far sales scatter from the trend as ad spend rises.

The scatter fans out. Stores spending a little sit close to the trend line, but stores spending a lot land far above it or far below it. That widening fan is what this lesson is about.

Unequal spread, not unequal effect

The pattern in that scatter has a name. When the spread of the outcome around its trend changes across a predictor's range, statisticians call it heteroskedasticity: hetero for unequal, skedasticity for spread. When the spread stays about the same everywhere, that is homoskedasticity.

Build the 50 stores and look at the numbers directly.

RInteractive R
# Generate the chain's 50 stores: ad spend and sales, with a true effect of 0.15 built in set.seed(42) n_stores <- 50 t <- seq(0, 1, length.out = n_stores) ad_spend <- round(1 + 24 * t^2, 1) sigma <- 0.3 + 0.35 * ad_spend sales <- round(10 + 0.15 * ad_spend + rnorm(n_stores, 0, sigma), 2) store_data <- data.frame(ad_spend, sales) store_data #> ad_spend sales #> 1 1.0 11.04 #> 2 1.0 9.78 #> 3 1.0 10.39 #> 4 1.1 10.60 #> 5 1.2 10.47 #> 6 1.2 10.10 #> 7 1.4 11.40 #> 8 1.5 10.15 #> 9 1.6 11.98 #> 10 1.8 10.21 #> 11 2.0 11.60 #> 12 2.2 12.78 #> 13 2.4 8.78 #> 14 2.7 10.06 #> 15 3.0 10.27 #> 16 3.2 11.38 #> 17 3.6 10.10 #> 18 3.9 6.16 #> 19 4.2 6.31 #> 20 4.6 13.21 #> 21 5.0 10.12 #> 22 5.4 6.91 #> 23 5.8 10.47 #> 24 6.3 13.99 #> 25 6.8 16.10 #> 26 7.2 9.87 #> 27 7.8 10.39 #> 28 8.3 5.59 #> 29 8.8 12.88 #> 30 9.4 9.11 #> 31 10.0 13.23 #> 32 10.6 14.42 #> 33 11.2 16.05 #> 34 11.9 9.07 #> 35 12.6 14.27 #> 36 13.2 3.53 #> 37 14.0 8.02 #> 38 14.7 7.57 #> 39 15.4 -1.43 #> 40 16.2 12.65 #> 41 17.0 13.84 #> 42 17.8 10.31 #> 43 18.6 17.95 #> 44 19.5 7.75 #> 45 20.4 2.88 #> 46 21.2 16.52 #> 47 22.2 6.78 #> 48 23.1 25.57 #> 49 24.0 9.85 #> 50 25.0 19.68

  

The true effect, 0.15, is the number sitting right there in 10 + 0.15 * ad_spend: every extra hundred dollars of ad spend adds 0.15 thousand dollars to sales, on average. Because this is simulated data, you get to know that truth exactly, instead of having to guess at it.

Ad spend itself is right-skewed: most stores spend modestly, and a few spend heavily, up near 25. Now fit the trend, and compare how far sales scatter from it when ad spend is low against when it is high.

RInteractive R
# Fit the trend, then compare how far sales scatter from it when ad spend is low versus high fit_naive <- lm(sales ~ ad_spend, data = store_data) resid_naive <- residuals(fit_naive) low_half <- store_data$ad_spend <= median(store_data$ad_spend) c(low_sd = sd(resid_naive[low_half]), high_sd = sd(resid_naive[!low_half])) #> low_sd high_sd #> 2.165914 5.659479

  

Among the 25 stores spending the least, sales scatter around the trend with a standard deviation of 2.17. Among the 25 spending the most, that scatter widens to 5.66, about 2.6 times as much. The upward trend itself is not in question here. What is in question is how far you can trust the standard error attached to it.