Statistics From Zero · Lesson 28 of 31

The Bootstrap: A Confidence Interval From Your Own Data

In one sentence: The bootstrap estimates how much a result would vary from sample to sample by resampling your own data with replacement thousands of times, which gives a confidence interval even when no formula exists.

The idea

A confidence interval (Lesson 9) needs to know how much your result would wobble if you took a different sample. For an average there's a formula for that wobble, the standard error. For many other things (a median, a percentile, a ratio, anything odd) there's no simple formula.

The bootstrap gets around it with a trick: treat your sample as a stand-in for the whole population, draw lots of new samples from your own data, and see how much the result varies between them. That variation is your estimate of the wobble.

Cousin Kevin's commute

Cousin Kevin has a new job and has timed his first 15 commutes, in minutes: 22, 25, 26, 27, 28, 29, 30, 31, 33, 35, 38, 41, 47, 58, 75. The 75 was a day with a broken-down train.

He wants to tell his boss how long the commute "usually" takes, with a range. Uncle Gary says he should just quote the worst day "to be safe". Aunt Linda says the median is 31 minutes, but how sure can he be after only 15 days?

The data are right-skewed (Lesson 26), so the median, 31, describes a typical day better than the mean, 36.3. But Lesson 9's formula is for means. How do you put a range around a median?

How the bootstrap works

Why with replacement? Without it, every resample would be Kevin's 15 days in a different order, with exactly the same median. Putting values back mimics drawing a fresh sample from a population that looks like his data.

Kevin's answer

We ran 200,000 resamples. The medians bunched around 30 and 31 and spread out from there:

Median of the res­ampleShare of res­amples
27 or less2.5%
28 to 3895%
41 or more2.5%

So a 95% interval for Kevin's typical commute is roughly 27 to 41 minutes, centred on 31. With 15 days, that's as precise as he can honestly be. He can tell his boss "usually about half an hour, somewhere between 27 and 41 on a typical day", which is more useful than Gary's 75.

Medians of 200,000 bootstrap resamples of 15 commutes

26 min0.4%
27 min2.1%
28 min6.2%
29 min12.5%
30 min18.4%
31 min20.9%
33 min18.3%
35 min12.4%
38 min6.3%
41 min2.1%
47 min0.4%
Share of resamples with each median. The middle 95% runs from 27 to 41 minutes: the 95% bootstrap interval.

Does it agree with the formula?

For the mean, where a formula exists, we can check. The bootstrap gives a 95% interval of 30.1 to 43.9 minutes. The usual formula, the mean plus or minus about two standard errors using the t-distribution (Lesson 14), gives 28.5 to 44.2. Close, and the bootstrap's is slightly lopsided, following the skew of the data. The bootstrap's estimate of the standard error (3.56) is also close to the formula's (3.67). When both methods are available, they usually agree; the bootstrap's value is that it keeps working where the formula stops.

Where it fails

Try it yourself

A café owner records the number of customers on 30 days and wants a 95% interval for the 90th percentile (a busy day). She bootstraps 10,000 resamples and finds that the 90th percentile of the resamples ranges, in its middle 95%, from 61 to 78 customers.

1. What should she conclude? 2. Why would the bootstrap be a poor tool for the busiest day she will ever have?

Show the answer

1. A typical busy day (the 90th percentile) is probably somewhere between about 61 and 78 customers; that's the range to staff for. The interval is wide because 30 days contain only three days above the 90th percentile.

2. The bootstrap can't produce a day busier than the busiest in her 30 days, so it says nothing about rare, extreme days. For those she needs a longer record, or a model of the tail.

The words your lecturer uses

Lec­turer saysIt means
Boot­strapEs­tim­at­ing the vari­ation of a result by res­ampling the data many times
Res­ampling with re­place­mentDrawing values and putting each back, so it can be drawn again
Boot­strap sample (res­ample)One new sample of the same size drawn from your data
Boot­strap dis­tri­bu­tionThe spread of the result across all the res­amples
Per­cent­ile in­ter­valThe middle 95% of the boot­strap dis­tri­bu­tion, used as a 95% con­fid­ence in­ter­val
Boot­strap stand­ard errorThe stand­ard de­vi­ation of the boot­strap dis­tri­bu­tion
Block boot­strapA version that res­amples runs of con­sec­ut­ive values, for data over time
Non­para­met­ricNot as­sum­ing a par­tic­u­lar shape, such as the bell curve, for the data

Three things to remember

Part of Statistics From Zero, a free beginner course by WrongStat. Not a substitute for your lecturer, but hopefully a good translator.