Weighting observations that deserve less say

Today let's understand why some rows in a regression deserve less say than others, and how to give each one exactly the say it has earned.

Twenty coffee shops each report their seating capacity, from 15 seats up to 70, against their average daily revenue, from about 267 up to about 649. But these 20 numbers were not all measured with the same care. Some shops have been open and tracking their revenue for close to a year. Others opened their doors only a few weeks ago.

Revenue climbs with seating capacity across these 20 points. But some of those points rest on many more days of data than others, and a straight line fit that ignores that difference is not treating them fairly.

Twenty shops, twenty averages of very different quality

Let's build these 20 shops in R so you can see exactly what each one is made of.

RInteractive R
# Build 20 coffee shops: seating capacity, days open, and average daily revenue set.seed(206) seats <- round(seq(15, 70, length.out = 20)) days_open <- sample(c(sample(12:30, 10, TRUE), sample(200:365, 10, TRUE))) avg_revenue <- numeric(20) for (i in 1:20) { avg_revenue[i] <- mean(rnorm(days_open[i], 150 + 7 * seats[i], 85)) } shops <- data.frame(seats = seats, days_open = days_open, avg_revenue = round(avg_revenue, 2)) shops #> seats days_open avg_revenue #> 1 15 26 291.44 #> 2 18 342 267.41 #> 3 21 13 329.31 #> 4 24 29 306.68 #> 5 27 251 341.11 #> 6 29 19 356.16 #> 7 32 16 369.39 #> 8 35 324 390.44 #> 9 38 27 434.39 #> 10 41 12 437.09 #> 11 44 239 461.49 #> 12 47 310 486.29 #> 13 50 287 498.53 #> 14 53 25 497.31 #> 15 56 356 533.13 #> 16 58 271 543.59 #> 17 61 19 577.19 #> 18 64 229 599.99 #> 19 67 15 605.37 #> 20 70 365 648.51

  

seats is each shop's seating capacity. avg_revenue is the mean of every daily revenue figure the shop has recorded since it opened. days_open is how many of those daily figures went into that mean, anywhere from 12 days for the newest shop to 365 days for the oldest.

The sample() call on the second line shuffles the days_open values on purpose, so a shop's size and a shop's age have nothing to do with each other. A new, small shop is just as likely as a new, big one, and the same goes for the old shops. That is why you see a 12-day shop (row 10, 41 seats) sitting right next to shops with hundreds of days open: size and age were deliberately kept unrelated here.

Each day's revenue was really drawn at random around 150 plus 7 times that shop's seats, with some noise added on top. So the true slope linking seats to revenue is 7. avg_revenue is just the average of however many of those daily draws a shop happened to record, which is exactly why a shop with only 12 days behind it is a shakier average than one with 365.