Beau
Okay, so Jo, we've talked a lot about running tests, you know, t-tests, all that stuff. And it always feels like there's this big assumption lurking in the background.
Transcript
Beau
Okay, so Jo, we've talked a lot about running tests, you know, t-tests, all that stuff. And it always feels like there's this big assumption lurking in the background.
Jo
The assumption of normality? That your data plays by certain rules?
Beau
Exactly! That everything is a nice, clean bell curve. But what if it isn't? What if you're looking at something weird, like... I don't know, the median time users spend on a specific feature. That's probably not going to be a perfect bell curve. What do you do then?
Jo
That is the perfect question, because it leads us directly into one of my favorite topics: the bootstrap. It's a way to do inference without having to assume what the underlying population looks like.
Beau
Okay, bootstrap. Like pulling yourself up by your own bootstraps? Sounds... fictional.
Jo
It's a surprisingly good analogy, actually. The core idea is called the 'plug-in principle'. Instead of assuming the population follows some ideal mathematical formula, like the normal distribution, we just... plug in what we have.
Beau
What we have is our sample, right? My, say, one thousand data points on user times.
Jo
Precisely. The plug-in principle says our best guess for what the entire population looks like... is the sample we actually collected. We treat our sample *as if* it were the population. This is sometimes called the empirical distribution function. We just use the data we see.
Beau
Wait, that feels a bit like cheating. How can a sample of a thousand represent millions of users? It's just a tiny piece.
Jo
It's not perfect, but it's the best information we have! And this is where the 'pulling yourself up' part comes in. We can't go back and survey millions of users. So, we leverage the sample we have by resampling from it.
Beau
Resampling. You mean... just drawing samples from my sample?
Jo
Exactly. But with a crucial twist: it's resampling *with replacement*.
Beau
Okay, 'with replacement'. Walk me through that. Let's say I have just five data points to keep it simple: 2, 3, 5, 8, and 10.
Jo
Perfect. So, you want to create a new 'bootstrap sample' of the same size, so five points. You reach into a metaphorical hat with your five numbers. You pull one out... say, the number 8. You write it down.
Beau
Okay, so my new sample starts with 8.
Jo
And here's the key: you put the 8 *back in the hat*. So for your second draw, all five original numbers are still in there. You could draw 8 again.
Beau
Oh, I see. So my first bootstrap sample could be something like... 8, 2, 10, 2, 5. Some numbers are repeated, and some, like the 3, might not get picked at all.
Jo
You've got it. And that little dataset you just created—8, 2, 10, 2, 5—is called a bootstrap replicate. Now, what's the whole point of this? Why are we doing it?
Beau
Well, in normal statistics, we want to know how much our statistic—like the mean or median—would jump around if we could collect many different samples from the real population. We want to estimate the sampling distribution.
Jo
Yes! And since we can't do that in reality, we're using this process as a simulation. For each bootstrap replicate, we calculate our statistic of interest. So, you'd calculate the median of your first sample: 8, 2, 10, 2, 5. What's that, sorted it's 2, 2, 5, 8, 10... so the median is 5.
Beau
Okay, so I have one bootstrapped median: 5.
Jo
Now, do it again. Create a second bootstrap sample. Maybe this time you get 3, 10, 10, 5, 3. The median of that is 5. Do it a third time. And a fourth. And you do this, say, ten thousand times.
Beau
And at the end, I'll have a list of ten thousand medians.
Jo
And that list of ten thousand medians *is* your bootstrapped sampling distribution. You've just computationally estimated the distribution of the median without using any complex formulas. This is the whole beauty of it. It's computational versus analytical inference.
Beau
Okay, that's clicking. For something like the mean, there's a nice formula for the standard error based on the Central Limit Theorem. But for the median... I don't even know what the formula for its standard error is. Is there one?
Jo
There is, but it's much more complicated and relies on assumptions about the probability density at the median, which is hard to estimate! But with the bootstrap, you don't need to know the formula. You just calculate the standard deviation of your list of ten thousand medians, and boom—that's your bootstrap standard error.
Beau
So this is a general-purpose tool. I can use it for the mean, the median, the 90th percentile, the ratio of two means... anything I can dream up and code?
Jo
Literally anything you can write a function for. That's its power. It turns a hard, analytical math problem into a relatively simple, if repetitive, coding problem. And computers are really, really good at repetitive coding problems.
Beau
So, in Python, I'd just have my list of original data points. Then I'd loop, say, ten thousand times. Inside the loop, I'd use something like... `numpy.random.choice` with `replace=True` to generate my bootstrap sample.
Jo
Exactly. `numpy.random.choice` is built for this. Then you calculate your statistic—`numpy.median` or whatever—on that new sample and append it to a list. After the loop finishes, you have your distribution.
Beau
This feels... a lot more intuitive than trying to remember all those formulas and their assumptions. The assumption here is just that my sample is a decent representation of the population.
Jo
That's the main one. The bootstrap principle is that the relationship between our sample and the population it came from is similar to the relationship between a bootstrap sample and our original sample. We're using the second one, which we can control, as an analogy for the first one, which we can't.
Beau
It's a simulation of uncertainty. We're seeing how much our median 'wiggles' just due to random sampling luck.
Jo
'A simulation of uncertainty' is a perfect way to put it. Instead of deriving the wiggle with math, we're measuring the wiggle with code.