The Bootstrap
Resampling your data to measure uncertainty.
You have one sample and a statistic computed from it. How uncertain is that number? Efron's bootstrap answers by treating the sample as if it were the population and resampling it. This lesson makes the plug-in idea precise, builds standard errors and confidence intervals, proves when the bootstrap works and shows where it breaks, and connects it to estimating prediction error and to bagging.
What you’ll learn
- State the plug-in principle, compute bootstrap standard errors by Monte Carlo resampling, and separate sampling error from Monte Carlo error.
- Construct normal, percentile, basic, studentized and BCa intervals, and compare their coverage accuracy.
- Prove that the bootstrap is consistent for the sample mean, and show why it fails for the sample maximum and for means of heavy-tailed data.
- Derive the leave-one-out bootstrap, .632 and .632+ estimators of prediction error, and interpret bagging as bootstrap smoothing.
The plug-in principle
Data are i.i.d. from an unknown distribution , and a statistic estimates , where puts mass on each observation. How accurate is depends on its sampling distribution, which depends on the unknown . The bootstrap (Efron, 1979) plugs in for : draw a bootstrap sample from , which means draws with replacement from the data, recompute , and let the distribution of given the data stand in for that of .
Under each draw has mean and variance , and the draws are independent, so
Hence : the textbook formula, with divisor instead of inside . For the mean the bootstrap adds nothing; its value is that the same recipe works for a median, a correlation, a ratio, or the output of a whole learning pipeline, where no formula exists.
A bootstrap sample is a multiset of size drawn from points, so there are only distinct ones, and for tiny the ideal bootstrap could be computed exactly. Otherwise a couple of hundred replicates usually suffice for a standard error, and a thousand or more for interval endpoints, which live in the tails (Efron & Tibshirani, 1993).
import numpy as np
rng = np.random.default_rng(0)
def bootstrap(x, stat, B=2000):
n = len(x)
return np.array([stat(x[rng.integers(0, n, n)]) for _ in range(B)])
reps = bootstrap(x, np.median) # x: a 1-D NumPy array
se = reps.std(ddof=1) # bootstrap standard error
lo, hi = np.percentile(reps, [2.5, 97.5]) # 95% percentile intervalA nonparametric bootstrap of the median. rng.integers(0, n, n) draws indices with replacement.
Confidence intervals
Write for the -quantile of the bootstrap replicates, , and for the bootstrap standard error. The common confidence intervals of nominal level :
| Interval | Endpoints | Idea |
|---|---|---|
| Normal | assumes is approximately normal | |
| Percentile | read the interval off the bootstrap distribution; respects monotone transformations | |
| Basic | treat as a copy of , and invert | |
| Studentized (bootstrap-) | , with | bootstrap an approximate pivot; needs a standard error inside every replicate |
| BCa | percentile interval at levels adjusted for bias and skewness (Efron, 1987) |
The bootstrap distribution of your statistic is strongly skewed and its median sits well away from . Which interval is designed for this situation?
- The normal interval
- The percentile interval, because it reads the skewness directly off the replicates
- Any of them: all bootstrap intervals agree in large samples
- The BCa interval, which adjusts the percentile levels for bias () and skewness ()
Show the answer
D. The BCa interval, which adjusts the percentile levels for bias () and skewness ()
A replicate median far from signals median bias, which corrects, and skewness that changes with is what the acceleration captures. BCa is second-order accurate and transformation-respecting; the studentized interval is the other second-order option.
Why it works, and when it fails
Conditionally on the data, is a normalized sum of i.i.d. draws with mean 0 and variance , and almost surely by the strong law of large numbers:
The summands form a triangular array, since their distribution changes with , so check Lindeberg's condition. With , almost surely, so for any the truncated second moment is eventually exactly zero:
Lindeberg's central limit theorem gives the conditional limit , and since the limit is continuous, Pólya's theorem upgrades this to uniform convergence of distribution functions. Bickel & Freedman proved much more, for functionals that are smooth in a suitable sense, using the Mallows distance between distributions.
Where it fails. Take and the maximum . Then converges to an exponential distribution, which is continuous. But a bootstrap sample contains the observed maximum with probability , so the bootstrap distribution of has an atom of mass near 0.632 at zero, and it cannot converge to the continuous limit. (Bickel & Freedman, 1981, also discuss counterexamples, cases where the bootstrap is inconsistent.) The trouble is that is a poor stand-in for exactly where the statistic looks: at the edge of the support.
With observations, what is the probability that a bootstrap sample contains the observed maximum, so that ?
Show the answer
64 %
, already close to the limit . Almost two thirds of the replicates of the maximum are identical, while the true sampling distribution has no atom at all.
Other failures follow the same pattern. For the mean of heavy-tailed data with infinite variance (in the domain of attraction of a stable law with index below 2), the bootstrap distribution converges to a random limit rather than the true one (Athreya, 1987). Parameters on the boundary of the parameter space and non-smooth functionals cause similar trouble. For dependent data, resampling single observations destroys the dependence; block bootstraps resample contiguous blocks instead (Künsch, 1989). A widely applicable repair is to resample fewer points: subsampling of the observations without replacement, with and , is consistent under very weak conditions (Politis & Romano, 1994), and the -out-of- bootstrap works similarly, at the price of choosing .
Bootstrap estimates of prediction error
Error estimation adds a twist: the statistic is the test error of a fitted model. Training on a bootstrap sample and testing on the original data is optimistic, because about 63% of the test points were also training points. The leave-one-out bootstrap tests each example only on fits whose bootstrap samples did not contain it. With the set of bootstrap samples that exclude example :
Take labels that are pure noise, two equally likely classes, and a 1-nearest-neighbor classifier. The training error is 0 and the true error is 0.5; the leave-one-out bootstrap is about 0.5, since each example is predicted from other, unrelated examples. The .632 estimator is far too optimistic:
Efron & Tibshirani (1997) measure how badly a model overfits. The no-information error is the error if inputs and labels were independent, , where is the fraction of labels in class and the fraction of predictions; the relative overfitting rate is
The .632+ estimator gives the leave-one-out bootstrap more weight as overfitting grows:
With no overfitting () the weight is 0.632, recovering the .632 estimator. In the 1-NN noise example and , so and the estimate is the honest 0.5.
Bagging as bootstrap smoothing
Bagging replaces a predictor by its bootstrap mean, , approximated with resamples; Breiman (1996) named it bootstrap aggregation. Efron (2014) studied the same operation for estimates computed after data-driven model selection, calling it bootstrap smoothing: averaging over resamples removes the jumps that selection introduces. He also gave a standard error for the smoothed estimate that needs no second level of resampling. Let be the number of times example appears in bootstrap sample , and the corresponding replicate:
Think first Why can the same resamples serve both to compute the bagged predictor and to estimate its variance, when the bootstrap standard error of an ordinary statistic needs its own resampling?
The bagged predictor is itself a bootstrap average, a smooth function of the resampling weights . Its sensitivity to each observation's weight can be read off from how the replicates covary with the counts, which is exactly the directional derivative the infinitesimal jackknife needs. For an unsmoothed statistic there is no such average to differentiate, so a separate bootstrap is required.
Key takeaways
- The bootstrap plugs in the empirical distribution for the unknown one: resample the data with replacement, recompute the statistic, and use the replicates' spread. For the mean it gives ; its value is that it works where no formula exists.
- Percentile, basic and normal intervals are first-order accurate; studentized and BCa intervals are second-order accurate, with one-sided coverage error (Hall, 1988). BCa corrects for bias and acceleration .
- The bootstrap is consistent for the mean under finite variance (Bickel & Freedman, 1981) and more accurate than the normal approximation for standardized means (Singh, 1981). It fails for the sample maximum (an atom of mass about 0.632), for heavy-tailed means, at boundaries and for dependent data; subsampling and block bootstraps repair many cases.
- The leave-one-out bootstrap (the out-of-bag error, for bagging) is pessimistic; .632 blends in the training error, and .632+ adapts the weight to the relative overfitting rate.
- Bagging is bootstrap smoothing, and its variance can be estimated from the same resamples by the infinitesimal jackknife, .
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
What is the ideal bootstrap standard error of the sample mean of observations?
- with
- with
- Zero, because resampling cannot change the mean
Show the answer
A. with
Each bootstrap draw has variance under the empirical distribution, which uses divisor , and the draws are independent, so .
Why does the nonparametric bootstrap fail for the maximum of a Uniform sample?
- The maximum has infinite variance
- About 63% of bootstrap samples contain the observed maximum, giving the bootstrap distribution an atom at zero that the continuous true limit does not have
- Too few bootstrap replicates are used in practice
- The bootstrap requires normally distributed data
Show the answer
B. About 63% of bootstrap samples contain the observed maximum, giving the bootstrap distribution an atom at zero that the continuous true limit does not have
, while converges to a continuous exponential law. The empirical distribution is a poor proxy for at the edge of the support, which is where the maximum lives.
A 1-nearest-neighbor classifier is trained on two balanced classes whose labels are pure noise. What do the .632 and .632+ estimators report?
- Both report about 0.5
- .632 reports about 0.5 and .632+ about 0.316
- .632 reports about 0.316, too optimistic, and .632+ about 0.5, because its relative overfitting rate is 1
- Both report 0, the training error
Show the answer
C. .632 reports about 0.316, too optimistic, and .632+ about 0.5, because its relative overfitting rate is 1
The training error is 0 and the leave-one-out bootstrap is about 0.5, so . The .632+ estimator computes , so , and it reports the leave-one-out bootstrap, 0.5.
Which bootstrap intervals are second-order accurate, with one-sided coverage error for smooth functions of means?
- The normal and percentile intervals
- The basic and percentile intervals
- All bootstrap intervals
- The studentized (bootstrap-) and BCa intervals
Show the answer
D. The studentized (bootstrap-) and BCa intervals
Hall (1988) showed that one-sided normal, percentile and basic intervals have coverage error of order , while studentizing or correcting for bias and acceleration gains an order. Two-sided intervals of all kinds have coverage error, by cancellation between the tails.
Further reading
- B. Efron, "Bootstrap methods: another look at the jackknife," Annals of Statistics 7(1), 1–26 (1979).
- B. Efron & R. J. Tibshirani, An Introduction to the Bootstrap (Chapman & Hall, 1993).
- P. J. Bickel & D. A. Freedman, "Some asymptotic theory for the bootstrap," Annals of Statistics 9(6), 1196–1217 (1981).
- B. Efron, "Better bootstrap confidence intervals," Journal of the American Statistical Association 82(397), 171–185 (1987).
- B. Efron & R. Tibshirani, "Improvements on cross-validation: the .632+ bootstrap method," Journal of the American Statistical Association 92(438), 548–560 (1997).