Skip to content

The bootstrap

Resample your one sample with replacement to see how much a statistic would wobble, with no formula needed.

Helps to know firstConfidence intervals

Helps to know first
This topic

First, the picture

You have eight response times and no way to get more. Draw from them again, with replacement, a thousand times, and watch their mean wobble.

One sample, a thousand what-ifs

Eight response times, resampled 1000 times with replacement (seed 6500).

One sample of eight response times, in ms. Resample it: draw 8 of its values at random, with replacement, and take their mean.

resamples
0
spread of the means
–

Predict first. Draw 8 values from these eight, with replacement. How many different values will one resample hold?

0.00 / 13.40 s
Describe this picture

Three panels that stay apart, stacked on one scale in ms. The first, “the one sample we have”, shows the eight response times 12, 14, 15, 15, 16, 18, 19 and 21 ms as dots, the two 15s stacked. The second, “one resample”, shows 8 values drawn from those eight with replacement: repeated values stack up, a triangle marks their mean, and the sample values not drawn are greyed out in the first panel. The third, “means of many resamples”, is a histogram of the resample means. Before the clip a question asks how many different values one resample of 8 will hold: all 8, about 5, or about 3. A tap picks one and starts the clip. In the clip 1000 resamples are drawn (seed 6500): the first ten one by one, each dropping its mean into the histogram, then the other 990 pour in. On a wide screen a small tally beside the second panel counts the different values in each of the first ten resamples: 3 to 6, mostly 4 or 5; at the end your guess is a dotted line on it. At the end a bracket over the histogram marks the middle 95 % of the means, 14.500 to 18.125 ms. Readouts give the number of resamples and the spread of their means, 0.9326 after 1000. After the clip a slider, “Resamples counted”, sets how many resamples are counted, from 10 to 1000 in steps of 10; the spread readout wanders with few and settles as the count grows.

Resampling a single sample

To see how much a statistic wobbles, I would like many samples from the population. I have one. The bootstrap pretends the sample is the population, and draws new samples from it: nn values, chosen at random with replacement, so a value can be picked twice or not at all. Each such draw is a resample.

Before the clip you guessed how many different values a resample holds. About 5 of the 8, on average. Each value is missed by all 8 draws with chance (7/8)8=0.344(7/8)^8=0.344, so about a third of the values are absent from any one resample, and 8×(1−0.344)=5.258\times(1-0.344)=5.25 are present. For large samples the missing share approaches e−1=0.368e^{-1}=0.368.

The resamples are not new data. They hold nothing but the same eight values, rearranged. What they show is how much a statistic would change if the sample had come out a little differently.

The spread of the resample means

Compute the mean of each resample: θ^1∗,…,θ^m∗\hat\theta^*_1,\dots,\hat\theta^*_m for mm resamples, the star marking “computed from a resample”. Their histogram is centred on 16.2516.25, the mean of the sample, not on the unknown true mean. The bootstrap cannot see past the sample.

The spread of the resample means is the bootstrap standard error:

bootstrap SE=standard deviation of θ^1∗,…,θ^m∗.\text{bootstrap SE}=\text{standard deviation of }\hat\theta^*_1,\dots,\hat\theta^*_m.

After the clip, drag the number of resamples. The readout wanders with few resamples and settles near 0.9640.964 ms as they grow; the clip’s 1000 resamples give 0.93260.9326. That limit is the spread of the sample itself, computed with divisor nn, 2.72722.7272, divided by 8\sqrt8. The formula of Confidence intervals, s/ns/\sqrt n with divisor n−1n-1, gives 1.03081.0308: slightly larger, for the reason Estimators: bias and variance gave.

More resamples make the readout steadier, but they never make the sample bigger. A thousand resamples still carry only the information in eight values.

A percentile interval

The resample means also give an interval with no formula at all. Sort them and cut off the lowest 2.5 % and the highest 2.5 %: what is left is a 95 % percentile interval. For the eight times the clip’s 1000 resamples give 14.5 to 18.125 ms, roughly 16.25±1.816.25\pm1.8; with many more resamples it settles near 14.4 to 18.1.

The t interval of Confidence intervals for the same data was 13.81 to 18.69 ms, a little wider: with eight values, the bootstrap underestimates the spread, as the divisor above suggests.

Statistics with no formula

For a mean, the formula s/ns/\sqrt n already does the job. The bootstrap earns its keep where no simple formula exists: the median, a ratio, a correlation, a trimmed mean. The recipe is the same: compute the statistic on each resample, then read the spread and the percentiles off the histogram. For the median of the eight times, the bootstrap standard error is about 1.3 ms.

When it fails

Watch out

The bootstrap treats the sample as the population, so it fails where the sample is a poor stand-in. With very small samples there are only a few different resamples. For extremes, such as the largest value, the sample’s own maximum is never exceeded by any resample.

Take the maximum of eight values. A resample contains the sample’s maximum with chance 1−(7/8)8=0.6561-(7/8)^8=0.656, so about two resamples in three report exactly that value. The bootstrap histogram of the maximum is mostly one tall spike, while the true distribution of a sample maximum over new samples has no spike at all. For large samples the spike holds about 1−e−1=0.6321-e^{-1}=0.632 of the resamples.

Worked example

1. Every resample of a tiny sample. The sample 1,2,61,2,6 has 33=273^3=27 equally likely ordered resamples. Their means take these values:

Resample meanResamplesChance
1, 2, 61 each1/27 each
4/3, 5/3, 8/3, 10/3, 13/3, 14/33 each3/27 each
366/27

The mean of these 27 means is 3, the sample mean. Their variance is 14/9=1.55614/9=1.556, standard deviation 1.2471.247. That equals the sample’s spread with divisor nn, 14/3\sqrt{14/3}, divided by 3\sqrt3: the bootstrap standard error of a mean is always the plug-in spread over n\sqrt n.

2. The eight times. About 34 % of the values are missing from each resample and 5.25 are present. There are 88=16 777 2168^8=16\,777\,216 ordered resamples, but only (158)=6435\binom{15}{8}=6435 different collections of values. The bootstrap standard error of the mean tends to 0.9640.964, a little below the formula’s 1.0311.031.

3. The maximum. At n=8n=8 a resample repeats the sample maximum with chance 0.6560.656; the bootstrap is not to be trusted for it.

Try it yourself. Draw 8 from 8 with replacement: a given value is missing with chance 0.3440.344. The bootstrap histogram of the mean centres on the sample mean.

Where you’ll meet this

Standard errors without formulas. Medians, ratios of two means, correlations and the coefficients of complicated models often get their error bars from the bootstrap in everyday statistics software.

Experiments on skewed data. Revenue per visitor is lopsided: most visitors spend nothing, a few spend a lot. Online A/B tests often bootstrap the difference in mean revenue instead of trusting a bell.

Curves and peaks. The uncertainty of a fitted curve, or of the position of a peak in a spectrum, is found by refitting to resampled data and watching the result move.

Where this leads · a selection matrix

A resample is a matrix times the data vector: a matrix with one 1 in each row, in the column of the value drawn. A matrix moves the plane in the linear algebra course reads such a matrix.

Reference card

QuantityFormulaNotes
Resamplenn draws from the sample, with replacementnot new data
Missing from a resample(1−1/n)n(1-1/n)^n, tends to e−1=0.368e^{-1}=0.368about a third
Bootstrap standard errorSD of θ^1∗,…,θ^m∗\hat\theta^*_1,\dots,\hat\theta^*_mmean: plug-in SD /n/\sqrt n
Percentile interval2.5th to 97.5th percentile of the θ^∗\hat\theta^*no formula needed
Centrethe sample’s statisticnot the truth
Fails fortiny samples, maxima and minimaresamples repeat the extreme

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look