Section 11.19

Bootstrap

Definition

The bootstrap is a method for estimating how much an estimate would vary across repeated experiments, using only the one sample at hand. It treats the sample as a stand-in for the population. It draws many new samples of the same size from the observed units with replacement, meaning each drawn unit is put back and can be drawn again, recomputes the estimate on each, and uses the spread of these recomputed estimates in place of the estimate’s unknown sampling distribution. Bradley Efron introduced it in 1979.

The idea

An engineer has measured 30 request times and reports their 90th percentile §11.16. To see how uncertain that number is, the engineer would have to repeat the whole experiment a thousand times and look at how the thousand percentiles spread, which is usually impossible. For a mean there is a formula, s/ns / \sqrt n, where ss is the sample standard deviation §11.14 and nn the number of observations. For a percentile or a ratio of two means there is often no usable formula.

The bootstrap lets the sample play the population. The sample is the best available picture of the population, so drawing new samples from it imitates drawing new samples from the population. Each imitation sample, called a resample, has the same number of units, some repeated and some left out, and the estimate computed on it varies roughly as the real estimate varies. The name comes from the phrase “to pull oneself up by one’s bootstraps”. The picture fails at the edges of the data: a resample contains only observed values, so the bootstrap knows nothing about rare values the sample missed, and it never creates new information.

How it works

  1. Choose the resampling unit: the unit that was sampled independently of the others. It is a single observation when the observations are independent and identically distributed §11.5 (IID), a whole pair in a paired design §11.7, a whole cluster such as a device or a session when the observations inside it share disturbances (the cluster bootstrap §11.21), and a block of consecutive observations in a time series.

  2. Draw a resample: draw nn units at random with replacement from the nn observed units, each draw choosing every unit with probability 1/n1/n.

  3. Recompute the estimate on the resample with exactly the same procedure as on the original data, including every filtering, pairing and weighting step. The result is one bootstrap replicate.

  4. Repeat steps 2 and 3 BB times, typically B=1000B = 1000 to 1000010\,000.

  5. Summarize the BB replicates. Their standard deviation estimates the standard error §11.15 of the estimate. Their mean minus the original estimate estimates the bias, the systematic offset of the estimator §11.2. Their percentiles give the percentile bootstrap §11.20 interval; more refined interval rules also exist.

Two separate errors remain. The Monte Carlo error, the error of approximating by random simulation, comes from using BB random resamples instead of all possible ones, and a larger BB removes it. The sampling error comes from having only nn original units, and only more independent units reduce it. A million resamples of ten units still describe ten units.

Worked example

All resamples of a tiny sample. The observed values are 1 and 3 milliseconds, so n=2n = 2 and the mean is 2 milliseconds. Drawing two values with replacement gives four equally likely ordered resamples, each with probability 1/2×1/2=1/41/2 \times 1/2 = 1/4: (1, 1), (1, 3), (3, 1) and (3, 3). Their means are 1, 2, 2 and 3 milliseconds. The mean of these replicates is (1+2+2+3)/4=2(1 + 2 + 2 + 3) / 4 = 2 milliseconds, and their variance is ((1−2)2+0+0+(3−2)2)/4=2/4=0.5((1 - 2)^2 + 0 + 0 + (3 - 2)^2) / 4 = 2 / 4 = 0.5 square milliseconds, so the bootstrap standard error is 0.5≈0.707\sqrt{0.5} \approx 0.707 milliseconds. The formula s/ns / \sqrt n gives 1 millisecond, because s2=((1−2)2+(3−2)2)/(2−1)=2s^2 = ((1 - 2)^2 + (3 - 2)^2) / (2 - 1) = 2 and 2/2=1\sqrt 2 / \sqrt 2 = 1. For a mean, the bootstrap standard error computed over all possible resamples always equals (n−1)/n\sqrt{(n - 1)/n} times s/ns / \sqrt n, here 1/2≈0.707\sqrt{1/2} \approx 0.707 times: in small samples the bootstrap is too narrow.

Why the unit matters. Two programs, A and B, each run once on three boards, with times in milliseconds: board 1 gives A 10 and B 12, board 2 gives A 20 and B 21, and board 3 gives A 30 and B 33. The boards differ greatly in speed, but B is slower than A by 2, 1 and 3 milliseconds, a mean difference of 2 milliseconds.

Breaking the pairs lets the large differences between boards swamp the small difference between programs, and the standard error comes out more than 14 times too large.

Stated precisely

Let x1,…,xnx_1, \dots, x_n be the observed units and θ̂=T(x1,…,xn)\hat\theta = T(x_1, \dots, x_n) the estimate, where TT is the procedure that computes it. The empirical distribution F̂n\hat F_n puts probability 1/n1/n on each observed unit. A bootstrap resample x1*,…,xn*x_1^*, \dots, x_n^* is nn independent draws from F̂n\hat F_n; the star marks a resampled quantity. The bootstrap replicate is θ̂*=T(x1*,…,xn*)\hat\theta^* = T(x_1^*, \dots, x_n^*). With BB replicates θ̂1*,…,θ̂B*\hat\theta^*_1, \dots, \hat\theta^*_B and their mean θ‾*\bar\theta^*, the bootstrap standard error is sêB=1B−1∑b=1B(θ̂b*−θ‾*)2,\widehat{\mathrm{se}}_B = \sqrt{\frac{1}{B - 1} \sum_{b=1}^{B} \bigl(\hat\theta^*_b - \bar\theta^*\bigr)^2}, where ∑b=1B\sum_{b=1}^{B} adds over the BB replicates. As BB grows, sêB\widehat{\mathrm{se}}_B approaches the standard deviation of θ̂*\hat\theta^* over all possible resamples, the ideal bootstrap standard error.

The bootstrap rests on three assumptions.

  1. The resampled units are independent and identically distributed, so that drawing them independently imitates the real data collection.

  2. The estimator depends smoothly on the data, as a mean, a difference of means or a ratio of means does; or it is a quantile of a distribution that has a continuous, positive probability density (probability per unit of value) at that quantile.

  3. The sample is large enough that F̂n\hat F_n resembles the population near the values that matter to the estimator.

When they hold, the spread of θ̂*\hat\theta^* around θ̂\hat\theta approaches the spread of θ̂\hat\theta around the true value θ\theta as nn grows. Known failures include the sample maximum §18.5.9 or minimum, a parameter at the edge of its allowed range, and the mean of data whose variance is infinite.

Limits and common mistakes

The bootstrap cannot see what the sample missed. If a process rarely produces a 100-millisecond request and the sample has none, no resample has one, and the bootstrap underestimates the uncertainty of tail statistics such as the 99th percentile.

Resampling the wrong unit gives wrong answers, usually overconfident ones. Resampling single requests when requests share a device or a session treats dependent rows as independent, the mistake called pseudoreplication §11.6; resample whole devices or sessions instead, with the cluster bootstrap.

Small samples give replicate distributions that are too narrow, by the factor (n−1)/n\sqrt{(n - 1)/n} even for a mean, and lumpy: ignoring order, a sample of 5 values has only 126 distinct resamples.

Increasing BB reduces only the Monte Carlo error. Report BB and the random seed so that others can repeat the computation.

Every data-dependent step belongs inside the loop. If extreme values were removed using the full sample, the removal must be repeated on every resample; otherwise the replicates miss that source of variation.

Questions answered

What object must be resampled to preserve pairing or dependence?

The object to resample is the independent unit of the design: the object that was sampled independently, so that all observations that depend on one another stay together inside one resampled object and the resampled objects are independent of one another. For paired measurements, such as two programs measured on the same board, resample whole pairs, never the two members separately. For clustered data, such as many requests from each of several devices or sessions, resample whole clusters with all their observations; this is the cluster bootstrap. For a time series, where neighboring observations are correlated, resample blocks of consecutive observations long enough to contain the correlation §15.44; this is the block bootstrap §18.5.6.

After drawing the resample, recompute the full estimate exactly as on the original data, for example the mean of the within-pair differences. Resampling individual rows instead breaks the dependence. With three boards whose speeds differ by about 10 milliseconds and two programs that differ by about 2 milliseconds, resampling the two programs’ times separately inflates the bootstrap standard error of the difference from about 0.47 to about 6.85 milliseconds. Resampling single requests from shared sessions errs the other way: it ignores the disturbance that all requests of a session share, and the intervals come out too narrow.

Related entries: Paired design (§11.7), Percentile bootstrap (§11.20), Cluster bootstrap (§11.21), Standard error (§11.15), Confidence interval (§11.18), Pseudoreplication (§11.6). Further reading: [76, 172].