Estimating a density without assuming one

Today let's understand how to describe the shape of a set of numbers honestly, without carving them into bins first.

A support line logged how long each of 150 callers waited on hold before an agent answered, in minutes. Most of them got through in just a few minutes. A few waited much longer. And none of them waited a negative number of minutes, because that's impossible.

Here are all 150 hold times, drawn as a histogram with 1-minute bins.

Press Run, then change that 1 to a 2 or a 4 inside the code, and watch the same 150 numbers take on a different shape each time.

A histogram's shape depends on choices, not just the data

Let's build these hold times for real, then look at them through three different bin widths at once.

RInteractive R
# Build the 150 hold times, then compare histograms at three bin widths, plus one shifted origin set.seed(104) hold_times <- round(rgamma(150, shape = 2, rate = 0.5), 1) par(mfrow = c(2, 2)) hist(hold_times, breaks = seq(0, 16, by = 1), main = "1-minute bins", xlab = "minutes") hist(hold_times, breaks = seq(0, 16, by = 2), main = "2-minute bins", xlab = "minutes") hist(hold_times, breaks = seq(0, 16, by = 4), main = "4-minute bins", xlab = "minutes") hist(hold_times, breaks = seq(-1, 16, by = 2), main = "2-minute bins, shifted by 1", xlab = "minutes")

  

rgamma(150, shape = 2, rate = 0.5) draws from a gamma distribution, one shape commonly used to generate waiting times that pile up near small values and thin out slowly toward large ones. You don't need to know anything about the gamma family to follow this lesson. It's only here to produce 150 realistic hold times, and every method from here on works on the 150 numbers themselves, never on the formula that made them.

Look at the top two panels first, 1-minute bins against 2-minute bins. The 1-minute view has a dip around 6 to 7 minutes, then rises again near 8 minutes, a small second bump in the bars. Widen the bins to 2 minutes and that bump disappears, smoothed into one steady decline from the tallest bar down to almost nothing. Nothing about the 150 hold times changed between those two panels. Only the width of the box each bar represents did.

Widen the bins again, to 4 minutes, in the panel on the bottom left, and that decline flattens further still, down to little more than two tall bars and a thin tail. Same 150 numbers, a third shape.

Now compare the two panels on the right, top and bottom. Both use 2-minute bins, so every bar is the same width in each. But the top one starts its grid at 0, so its tallest bar covers 2 to 4 minutes. The bottom one starts its grid at -1, shifting every bin by 1 minute, and now the tallest bar covers 1 to 3 minutes instead. The width never changed. Only where the grid started did.

A histogram needs you to pick both of these before it can be drawn: how wide each bin is, and where the first one starts. Neither choice comes from the data. Change either one and the same 150 hold times can look like a different distribution.