The Bootstrap Method

Measuring the uncertainty of an estimate by resampling the data with replacement. The plug-in idea behind the bootstrap, standard errors and percentile intervals worked on the diabetes data, a regression slope where the bootstrap agrees with the robust rather than the textbook standard error, checks by simulation of how accurate bootstrap standard errors are and how often percentile intervals cover the truth, how many resamples are enough, where the bootstrap fails, and bootstrap estimates of prediction error, from the naive version through leave-one-out to the .632 and .632+ estimators.

Resampling the data with replacement, the bootstrap, estimates the uncertainty of almost any statistic. For the median BMI of the 442 diabetes patients it gives a standard error of 0.215 and a 95% percentile interval of 25.35 to 26.20. For a regression slope, resampling whole patients agrees with the heteroskedasticity-robust standard error (0.607 against 0.613), not the textbook one (0.674). The method works for statistics that depend smoothly on the data and fails for extremes such as the sample maximum. Percentile intervals undercover in small skewed samples (85% for the mean of 10 exponential values). For prediction error, the .632 and .632+ estimators are nearly unbiased for a cubic fit but 30% to 35% low for 1-nearest-neighbor regression, where 10-fold cross-validation is accurate.

The median body mass index (BMI) of the 442 patients in the diabetes study is 25.70. How precise is that number? For a mean there is a formula: the standard deviation divided by $\sqrt{n}$ (The Sampling Distribution of the Mean proves it). For a median there is no simple exact formula, and the large-sample approximation depends on the height of the population's density at its median, which is itself hard to estimate. The same problem arises for a correlation, a ratio, a regression coefficient when the textbook assumptions fail, or the error rate of a classifier.

The bootstrap, introduced by Efron (1979), answers all of these questions the same way. If many samples could be drawn from the population, the spread of the median across them would show its precision directly. Only one sample exists, so the bootstrap draws new samples from the sample itself, computes the median of each, and uses their spread. It replaces a formula with computation, and it works for almost any statistic. This article covers how and why it works, checks its accuracy by simulation, shows where it fails, and then turns to its use in estimating the prediction error of a model, the subject of this topic.

The idea: resample the sample

Suppose $z_1, \dots, z_n$ are an independent sample from an unknown distribution $F$, and $\hat{\theta} = s(z_1, \dots, z_n)$ is a statistic such as their median. Its standard error is the standard deviation of $\hat{\theta}$ over repeated samples of size $n$ from $F$. It cannot be computed, because $F$ is unknown.

The best available estimate of $F$ is the empirical distribution $\hat{F}$, which puts probability $1/n$ on each observed value. The bootstrap's step is to compute the standard error with $\hat{F}$ in place of $F$: to ask how much $\hat{\theta}$ would vary if the population were exactly the sample. This substitution is the plug-in principle, which The Plug-In Principle and Why the Bootstrap Works states in general. Drawing a sample of size $n$ from $\hat{F}$ means drawing $n$ times from the observed values, each time choosing each value with probability $1/n$, that is, sampling with replacement. Such a draw is a bootstrap sample, written $z^{*1}$.

The standard error under $\hat{F}$ could in principle be computed exactly, by enumerating all possible bootstrap samples, but their number is astronomical for any real $n$. Instead, draw $B$ bootstrap samples at random, compute the statistic on each, $\hat{\theta}^{*1}, \dots, \hat{\theta}^{*B}$, and take their standard deviation (Hastie, Tibshirani and Friedman, 2009, eq. 7.53; James, Witten, Hastie and Tibshirani, 2021, eq. 5.8):

$$\widehat{\mathrm{SE}}_B = \sqrt{\frac{1}{B - 1} \sum_{b=1}^{B} \bigl(\hat{\theta}^{*b} - \bar{\theta}^{*}\bigr)^2}, \qquad \bar{\theta}^{*} = \frac{1}{B} \sum_{b=1}^{B} \hat{\theta}^{*b}.$$

Two approximations are stacked here. The first, $\hat{F}$ for $F$, is the statistical one, and its quality depends on the sample size and the statistic. The second, $B$ random resamples for all of them, is a Monte Carlo approximation that can be made as accurate as computing time allows.

What a bootstrap sample looks like

A bootstrap sample of the 442 patients is 442 draws with replacement from the 442. In the first one drawn by the article's script (seed 742), 179 patients appear once, 74 twice, 21 three times and 12 four or more times, while 156 do not appear at all. A given patient is missed by one draw with probability $1 - 1/n$, and by all $n$ draws with probability $(1 - 1/n)^n$, so the probability that it appears is

$$1 - \Bigl(1 - \frac{1}{n}\Bigr)^n \;\to\; 1 - e^{-1} \approx 0.632 \quad \text{as } n \to \infty.$$

This is 0.6723 for $n = 5$, 0.6513 for $n = 10$ and 0.6325 for $n = 442$; over 10,000 bootstrap samples of the diabetes data, the share of distinct patients averaged 0.6327. Random Forests puts the roughly 37% of cases left out of each sample, the out-of-bag cases, to work as a built-in test set. The number 0.632 returns below.

Standard errors and percentile intervals

The median BMI

From $B = 2{,}000$ bootstrap samples of the 442 BMI values, the bootstrap standard error of the median is 0.215. The bootstrap medians take only 34 distinct values, because a median is always one of the data values or the midpoint of two, and BMI is recorded to one decimal place; the bootstrap distribution of a median is lumpy for that reason, but its spread is still informative.

The bootstrap distribution also gives a confidence interval directly. The percentile interval at level 95% runs from the 2.5th to the 97.5th percentile of the $B$ bootstrap values: here 25.35 to 26.20. Its justification is not that the bootstrap values vary around $\hat{\theta}$ as $\hat{\theta}$ varies around the true value; that reasoning leads to a different interval, the basic interval, which reflects the percentiles through $\hat{\theta}$. The percentile interval is exact when some increasing transformation of the statistic has an error of a fixed, symmetric shape that the bootstrap reproduces, because percentiles carry over to any increasing scale, and the transformation need not be known (Bootstrap Confidence Intervals proves this and compares the two). That condition holds only approximately, which is why the coverage checks below matter.

A regression slope

A least-squares regression of disease progression on BMI alone, as in Simple Linear Regression, gives a slope of 10.233 progression units per unit of BMI. Its textbook standard error, from the formula that assumes errors of constant variance, is 0.674.

The bootstrap can resample a regression in two ways. Pairs (or case) resampling draws whole patients, each with their BMI and progression, and refits the line to each bootstrap sample. Residual resampling keeps the inputs fixed and adds resampled residuals to the fitted values; it assumes the errors are exchangeable, which is the same constant-variance assumption as the textbook formula. Pairs resampling makes no such assumption. With $B = 2{,}000$:

Standard error of the slope Value
Textbook formula (constant error variance) 0.674
Bootstrap, resampling patients 0.607
Heteroskedasticity-robust (sandwich, HC0) 0.613
The slope of progression on BMI in 2,000 bootstrap samples of the 442 patients. The bootstrap distribution is close to normal but narrower than the normal curve implied by the textbook standard error; the percentile interval (dashed) runs from 9.04 to 11.44.
The slope of progression on BMI in 2,000 bootstrap samples of the 442 patients. The bootstrap distribution is close to normal but narrower than the normal curve implied by the textbook standard error; the percentile interval (dashed) runs from 9.04 to 11.44.

The pairs bootstrap agrees with the robust standard error, the White (1980) estimator described in Linear Regression Assumptions, to within 1%, and not with the textbook one. That is what one would hope: both measure the slope's variability without assuming constant error variance. Here the spread of progression is not the same at all levels of BMI, and the textbook formula overstates the slope's uncertainty by about 10%. The 95% percentile interval, 9.04 to 11.44, is correspondingly narrower than the textbook $t$ interval, 8.91 to 11.56. The same article discusses when unequal variance matters and what else can be done about it, and The Jackknife shows that leaving out one case at a time gives HC3, a variant of White's estimator.

The bootstrap also estimates bias: the mean of the bootstrap slopes minus the original slope, here $+0.024$, about 4% of a standard error. A bias estimate this small relative to the standard error is noise and is best ignored; correcting for it would add variance without a reliable gain.

How many resamples?

$B$ controls only the Monte Carlo error, the variation that would disappear with infinitely many resamples. To see its size, the bootstrap standard error of the slope was computed 200 times for each of several values of $B$:

$B$ Mean bootstrap SE SD across 200 repetitions Relative SD
25 0.615 0.089 14.4%
50 0.610 0.065 10.7%
100 0.617 0.046 7.5%
200 0.614 0.030 4.9%
1,000 0.616 0.015 2.4%

The relative error falls like $1/\sqrt{2B}$, the sampling error of a standard deviation estimated from $B$ values (Worked problem 2 derives it): about 7% at $B = 100$, enough for a standard error reported to two significant figures. Percentile intervals depend on the tails of the bootstrap distribution, which few resamples describe poorly, so they need $B$ in the thousands. Computing is rarely the constraint for a statistic like a median or a slope, and $B = 2{,}000$ or more costs a fraction of a second.

Checking the bootstrap by simulation

On real data the true standard error is unknown, so the bootstrap cannot be checked there. In a simulation, the population is known and the truth can be computed. The population here is an exponential distribution with mean 1, which is strongly skewed to the right, like incomes, waiting times or many laboratory measurements.

The standard error of a median

For samples of $n = 25$, the true standard deviation of the sample median is 0.2019. The median is the 13th smallest value, and for an exponential population with mean 1 its variance is exactly $\sum_{k=13}^{25} 1/k^2$, by Rényi's representation of exponential order statistics as sums of independent exponential spacings. A simulation of 200,000 samples gave 0.2014. For each of 1,000 samples of 25, the bootstrap standard error was computed with $B = 1{,}000$.

Bootstrap standard errors of the median from 1,000 different samples of 25 exponential values. They center near the true value, about 0.20 (the line marks the simulated 0.201; the exact value is 0.2019), but any one of them can be far off: the middle 80% run from 0.13 to 0.30.
Bootstrap standard errors of the median from 1,000 different samples of 25 exponential values. They center near the true value, about 0.20 (the line marks the simulated 0.201; the exact value is 0.2019), but any one of them can be far off: the middle 80% run from 0.13 to 0.30.

On average the bootstrap gets the standard error about right: the 1,000 estimates have a mean of 0.2173 and a median of 0.2132, within 8% of the truth. Any single estimate is much less accurate. The middle 80% run from 0.1298 to 0.3041, so one sample of 25 can give a standard error a third too small or half too large. That is not a failure of the bootstrap. A sample of 25 contains limited information about the shape of the population near its median, and no method can extract more. Raising $B$ would not help, because the variation comes from the sample, not from the resampling.

Coverage of percentile intervals

A 95% confidence interval should contain the true value in 95% of samples, the property called coverage that Confidence Intervals and Coverage defines and checks by simulation. For the mean of the exponential population, 4,000 samples were drawn at each of four sizes, and two intervals computed from each: the textbook $t$ interval and the bootstrap percentile interval with $B = 2{,}000$.

$n$ $t$ interval Bootstrap percentile
10 0.896 0.854
20 0.919 0.903
40 0.938 0.933
80 0.940 0.934
Coverage of nominal 95% intervals for the mean of an exponential population, 4,000 samples at each size. Both intervals fall short with small samples; the bootstrap percentile interval falls shorter. Both approach 95% as n grows.
Coverage of nominal 95% intervals for the mean of an exponential population, 4,000 samples at each size. Both intervals fall short with small samples; the bootstrap percentile interval falls shorter. Both approach 95% as n grows.

For a skewed population and small samples, the percentile interval covers the mean less often than the $t$ interval, which itself falls short. The reason is that the bootstrap distribution of the mean is centered on the sample mean and inherits the sample's own spread. A sample that missed the long right tail has both a low mean and a small spread, so its interval is too low and too narrow together. The same failure of the $t$ interval, and its cause, are worked out in the Academics section's Confidence Intervals for a Mean. The bootstrap does not remove it; resampling a sample that lacks the tail cannot create one. For the median, which does not depend on the tail, the percentile interval did well: coverage 0.952 at $n = 25$ and 0.946 at $n = 80$.

Refinements of the percentile interval adjust its endpoints for bias and skewness in the bootstrap distribution. The most widely used, the bias-corrected and accelerated (BCa) interval, is the default method of SciPy's scipy.stats.bootstrap (SciPy 1.18.0 documentation, checked 23 November 2026), and Bootstrap Confidence Intervals derives it. They improve coverage in many settings but cannot add information a small sample lacks. A bootstrap interval for a difference in means is worked in the Academics section's Significance Testing.

Where the bootstrap fails

The bootstrap works when the statistic depends smoothly on the empirical distribution, as means, medians, regression coefficients and correlations do. It fails for statistics that depend on the extremes of the sample. The sample maximum is the standard example. For 50 values drawn from a uniform distribution on $[0, 1]$, the true maximum of the population is 1, and the sample maximum is always below it. A bootstrap sample contains the sample's own maximum, and so reproduces it exactly, whenever that observation is drawn at least once, which happens with probability $1 - (1 - 1/50)^{50} = 0.636$. In 10,000 bootstrap samples, 63.2% had exactly the original maximum. The bootstrap distribution therefore has a spike at the observed value and never goes beyond it, while the true sampling distribution is continuous and lies entirely below 1. No bootstrap interval built from it can be trusted.

Other limits are less dramatic but more common:

  • The sample must represent the population. A biased or tiny sample produces bootstrap samples with the same bias, and a precise-looking standard error around the wrong value.
  • The resampling must match how the data were collected. Resampling individual observations assumes they are independent. Time series, repeated measurements on the same patients and clustered samples need resampling of blocks, patients or clusters instead, as Resampling Dependent and Clustered Data shows.
  • Selection steps must be resampled too. If a model's inputs were chosen by a search, the usual standard errors of the chosen model's coefficients are not valid, because they ignore the search (Hastie et al., 2009, §3.3.2). A bootstrap can account for the search only if the search is repeated on each bootstrap sample; resampling the final model alone ignores it in the same way.

Estimating prediction error by the bootstrap

The bootstrap can also estimate how well a model predicts new data, the question that cross-validation answers. The obvious version does not work, and the reasons why lead to estimators that do.

The naive bootstrap

Fit the model to each bootstrap sample, and measure its error on the original dataset (Hastie et al., 2009, eq. 7.54):

$$\widehat{\mathrm{Err}}_{\text{boot}} = \frac{1}{B} \frac{1}{n} \sum_{b=1}^{B} \sum_{i=1}^{n} L\bigl(y_i, \hat{f}^{*b}(x_i)\bigr).$$

The training and test data overlap: each bootstrap sample contains about 63% of the original observations, and a model is evaluated on many cases it was fitted to. Hastie et al. (2009, §7.11) give a stark example. Suppose two equal classes and inputs that carry no information about them, so that every classifier has a true error rate of 0.5, and use the 1-nearest-neighbor classifier. A case that is in the bootstrap sample is its own nearest neighbor and is classified correctly; a case that is not is classified at random. The expected naive estimate is therefore $0.5 \times 0.368 = 0.184$, far below 0.5.

The leave-one-out bootstrap

The fix mirrors cross-validation: evaluate each case only with the models that did not see it. Let $C^{-i}$ be the set of bootstrap samples that do not contain case $i$. The leave-one-out bootstrap estimate is (Hastie et al., 2009, eq. 7.56)

$$\widehat{\mathrm{Err}}^{(1)} = \frac{1}{n} \sum_{i=1}^{n} \frac{1}{|C^{-i}|} \sum_{b \in C^{-i}} L\bigl(y_i, \hat{f}^{*b}(x_i)\bigr).$$

Each case is out of bag in about 37% of the bootstrap samples, so with $B = 200$ every case has around 74 models to average over. This is the bootstrap analogue of out-of-bag error in Random Forests, where each case is predicted by the trees that did not see it. A closely related procedure, common in practice, records the error on the out-of-bag cases separately for each bootstrap round and averages the rounds; it weights cases slightly differently but estimates the same thing.

The leave-one-out bootstrap has the opposite problem from the naive one. Each model is fitted to a bootstrap sample containing only about $0.632n$ distinct cases, so it behaves roughly like a model fitted to a training set of that size, and its error is biased upward in the way that 2-fold cross-validation is (Hastie et al., 2009, §7.11).

The .632 and .632+ estimators

Efron (1983) proposed to cancel the two biases by mixing the optimistic training error $\overline{\mathrm{err}}$ with the pessimistic leave-one-out bootstrap:

$$\widehat{\mathrm{Err}}^{(.632)} = 0.368 \cdot \overline{\mathrm{err}} + 0.632 \cdot \widehat{\mathrm{Err}}^{(1)}.$$

The weights come from the inclusion probability $1 - e^{-1}$ derived above. Its derivation is not simple, and Hastie et al. (2009, §7.11) describe it informally as pulling the leave-one-out bootstrap down toward the training error.

The .632 estimator fails when a model fits its training data perfectly. In the no-information example above, the 1-nearest-neighbor classifier has $\overline{\mathrm{err}} = 0$ and $\widehat{\mathrm{Err}}^{(1)} \approx 0.5$, so the .632 estimate is about $0.632 \times 0.5 = 0.316$, while the truth is 0.5. Efron and Tibshirani (1997) corrected this with the .632+ estimator, which gives more weight to $\widehat{\mathrm{Err}}^{(1)}$ the more the model overfits. It first estimates the no-information error rate $\hat{\gamma}$, the error the model would make if inputs and outputs were unrelated, by evaluating its predictions on all $n^2$ pairings of inputs with outcomes. The relative overfitting rate

$$\hat{R} = \frac{\widehat{\mathrm{Err}}^{(1)} - \overline{\mathrm{err}}}{\hat{\gamma} - \overline{\mathrm{err}}}$$

runs from 0, when the leave-one-out bootstrap error equals the training error (no overfitting), to 1, when it equals the no-information rate. The weight on $\widehat{\mathrm{Err}}^{(1)}$ is then $\hat{w} = 0.632 / (1 - 0.368 \hat{R})$, which runs from 0.632 to 1 (Hastie et al., 2009, eqs. 7.58 to 7.61):

$$\widehat{\mathrm{Err}}^{(.632+)} = (1 - \hat{w}) \cdot \overline{\mathrm{err}} + \hat{w} \cdot \widehat{\mathrm{Err}}^{(1)}.$$

The article's script also caps $\widehat{\mathrm{Err}}^{(1)}$ at $\hat{\gamma}$ and keeps $\hat{R}$ between 0 and 1, so that the weight stays in that range.

A comparison by simulation

The estimators were compared in the simulation used for cross-validation: training sets of 40 points with $x$ uniform on $[0, 1]$, $y = \sin(5x)$ plus normal noise with standard deviation 0.3, a cubic fitted by least squares and 1-nearest-neighbor regression, 1,000 training sets (seed 742) and $B = 200$. The true conditional error of each fitted model is known, and its average over training sets, the expected error, is the target.

Cubic (expected error 0.1051) Mean Bias SD
Training error 0.0828 −0.0223 0.0189
Naive bootstrap 0.0941 −0.0110 0.0217
Leave-one-out bootstrap 0.1190 +0.0139 0.0289
.632 0.1056 +0.0006 0.0249
.632+ 0.1060 +0.0009 0.0251
10-fold cross-validation 0.1060 +0.0009 0.0258
1-nearest neighbor (expected error 0.1844) Mean Bias SD
Training error 0.0000 −0.1844 0.0000
Naive bootstrap 0.0690 −0.1153 0.0174
Leave-one-out bootstrap 0.1900 +0.0056 0.0477
.632 0.1201 −0.0643 0.0302
.632+ 0.1285 −0.0559 0.0343
10-fold cross-validation 0.1851 +0.0007 0.0546
Estimates of prediction error over 1,000 simulated training sets (mean, with bars of one standard deviation); the dashed line is the true expected error. For the cubic, the .632 and .632+ estimators and 10-fold cross-validation all land on target. For the 1-nearest-neighbor rule, which fits its training data exactly, the .632 estimators are pulled far too low and only the leave-one-out bootstrap and cross-validation are accurate.
Estimates of prediction error over 1,000 simulated training sets (mean, with bars of one standard deviation); the dashed line is the true expected error. For the cubic, the .632 and .632+ estimators and 10-fold cross-validation all land on target. For the 1-nearest-neighbor rule, which fits its training data exactly, the .632 estimators are pulled far too low and only the leave-one-out bootstrap and cross-validation are accurate.

For the cubic, a "light fitting" method in the phrase of Hastie et al. (2009, §7.11), the picture is the textbook one. Training error and the naive bootstrap are optimistic, the leave-one-out bootstrap is pessimistic by 13%, and the .632 and .632+ estimators correct it almost exactly, with slightly less variance than 10-fold cross-validation.

For 1-nearest-neighbor regression the corrections go wrong. The training error is zero, so the .632 estimate is just 0.632 times the leave-one-out bootstrap, 35% too low. The .632+ estimator helps only a little, because the relative overfitting rate is far below 1: the leave-one-out bootstrap error, about 0.19, is much smaller than the no-information error, so the formula judges the overfitting to be moderate and applies little correction. Meanwhile the leave-one-out bootstrap itself is nearly unbiased here, since the error of 1-nearest-neighbor regression changes little with the size of the training set. In the simulation of Cross-Validation, 2-fold cross-validation, whose models are fitted to 20 points, averaged 0.195 against an expected error of 0.184 with 40 points. The .632 family is built for one shape of learning curve, and a method with a different shape defeats it.

The no-information classification example of Hastie et al. (2009, §7.11), 1-nearest-neighbor classification with class labels independent of the inputs, comes out close to the values they derive (0.184 for the naive bootstrap, 0.316 for the .632 estimator and 0.5, the true error, for the leave-one-out bootstrap): over 200 datasets of 50 cases with five irrelevant inputs, the naive bootstrap averaged 0.184, the .632 estimator 0.319, the leave-one-out bootstrap 0.505 and the .632+ estimator 0.466. The .632+ estimator is right when $\hat{R} = 1$; in datasets where the leave-one-out bootstrap came out slightly below 0.5 by chance, $\hat{R}$ fell below 1 and the estimate dropped with it.

The practical lesson is the one Hastie et al. (2009, §7.11.1) draw from their own comparisons: in their examples, cross-validation and the bootstrap selected models about equally well and estimated the error of the chosen model about equally well. Cross-validation is simpler to reason about and does not depend on how a method overfits, which is why it is the more common choice. The bootstrap's strength lies in the first half of this article, measuring the uncertainty of an estimate, where cross-validation has nothing to offer.

The diabetes data

For the least-squares regression of disease progression on all ten inputs of the 442 diabetes patients (the model of Cross-Validation, whose training MSE is 2,859.7), 200 bootstrap rounds gave out-of-bag sets of 140 to 181 patients (mean 162.9). The out-of-bag MSE averaged 3,081.3 over the rounds, with a standard deviation of 255.6; the leave-one-out bootstrap estimate is 3,074.2, every patient having been out of bag in at least 53 rounds. Both are above the 10-fold cross-validation estimate of 2,985.2 and the leave-one-out value of 3,001.8 from Cross-Validation, as expected from models fitted to about 280 distinct patients rather than 398 or 441. The .632 estimate, $0.368 \times 2{,}859.7 + 0.632 \times 3{,}074.2 = 2{,}995.3$, lands between the 10-fold and leave-one-out values.

The spread of the per-round errors needs careful reading. Their 2.5th and 97.5th percentiles, 2,503 and 3,557, show how much a single round's estimate varies, each from about 160 patients and one bootstrap model. They are not a 95% confidence interval for the model's error. The leave-one-out bootstrap averages over all the rounds and is much less variable than any one of them; an interval for it would need a further layer of resampling.

In practice

The defaults below summarize this article's measurements and the sources it cites. Each line names the section that supports it.

  • Number of resamples. $B = 200$ gives a bootstrap standard error to within about 5% (relative Monte Carlo error $1/\sqrt{2(B - 1)}$, Worked problem 2). Percentile and BCa intervals depend on the tails and need $B$ in the thousands; 2,000 is used throughout here. SciPy's scipy.stats.bootstrap uses 9,999 by default.
  • Which interval. scipy.stats.bootstrap returns BCa unless method="percentile" or "basic" is given. Small samples from a skewed population are the hard case. Here the percentile interval covered the mean of 10 exponential values only 85% of the time (the section on coverage of percentile intervals). Bootstrap Confidence Intervals compares the kinds, and on C-reactive protein none of them reaches 95%.
  • Regression. Resample whole cases (pairs) unless the errors are known to have constant variance. For the diabetes slope, pairs resampling agreed with the heteroskedasticity-robust standard error to within 1% (the section on the regression slope).
  • Dependent data. Resample the independent units: patients, clusters or blocks of a time series, not single observations (Resampling Dependent and Clustered Data).
  • Model selection. Repeat any variable selection or tuning inside each bootstrap sample, or the standard errors ignore the search (the section on where the bootstrap fails).
  • Do not bootstrap extremes. For the sample maximum, the bootstrap distribution has a spike at the observed maximum, with probability $1 - (1 - 1/n)^n \approx 0.632$, and never goes beyond it, while the true sampling distribution is continuous (the section on where the bootstrap fails, Worked problem 3). The same holds for the minimum.
  • Prediction error. 10-fold cross-validation is the safer default. The .632 and .632+ estimators matched it for a cubic fit but were 35% and 30% too low for 1-nearest-neighbor regression, which fits its training data exactly. Out-of-bag error from bagged models (oob_score=True) applies the same idea, predicting each case only with the models that did not see it.
  • Code. The section "In Python" shows the resampling by hand with NumPy and with SciPy; tools/experiments/data-science/bootstrap-method.py in the site's repository computes every number here.

Worked problems

The problems extend the article on the diabetes resamples and its simulations. The review-pass block of the article's script checks every number, in exact fractions where possible.

Problem 1 (how often each patient appears). In the first bootstrap sample of the 442 patients, 156 did not appear, 179 appeared once, 74 twice, 21 three times and 12 four or more times. What counts should be expected, and is this sample typical?

Solution. Each of the 442 draws picks a given patient with probability $1/442$, independently, so the number of times that patient appears is binomial with $n = 442$ and $p = 1/442$ (The Binomial Distribution). The probability of appearing $j$ times is $\binom{442}{j} (1/442)^j (441/442)^{442 - j}$, which is within 0.001 of the Poisson probability $e^{-1}/j!$ for $j = 0$ to 3: 0.368, 0.368, 0.184 and 0.061. That closeness is expected: Le Cam's bound, quoted in The Poisson Distribution, puts the total variation distance between $\text{Bin}(n, p)$ and $\text{Poisson}(np)$ at no more than $np^2$, here $1/442 = 0.0023$. Multiplying by 442 gives expected counts of 162.4, 162.8, 81.4, 27.1 and, for four or more, 8.3. The expected number of distinct patients is $442\,[1 - (441/442)^{442}] = 279.6$, the "about 280 distinct patients" of the diabetes section. The first sample's counts differ from these by amounts a chi-squared statistic measures at 5.52 on 4 degrees of freedom ($p = 0.24$), so it is an ordinary draw. Each patient's count is binomial, but the 442 counts are not independent: they must add to 442 draws, and jointly they are multinomial with 442 equal cell probabilities. So the five category counts above are not a multinomial sample of 442 independent patients, and the chi-squared reference is an approximation.

Problem 2 (why the Monte Carlo error falls like $1/\sqrt{2B}$). Derive the relative standard deviation of a bootstrap standard error computed from $B$ replicates, assuming the replicates are roughly normal, and compare it with the table of the section on how many resamples.

Solution. The bootstrap standard error is the sample standard deviation $s$ of $B$ replicates. If the replicates are normal with standard deviation $\sigma$, then $(B - 1) s^2/\sigma^2$ has a chi-squared distribution with $B - 1$ degrees of freedom, whose variance is $2(B - 1)$ (both facts are proved in The Chi-Squared and t Distributions), so $\operatorname{Var}(s^2) = 2\sigma^4/(B - 1)$. The delta method turns this into the variance of $s = \sqrt{s^2}$: the derivative of $\sqrt{v}$ at $v = \sigma^2$ is $1/(2\sigma)$, so $\operatorname{Var}(s) \approx \operatorname{Var}(s^2)/(4\sigma^2) = \sigma^2/[2(B - 1)]$, and the relative standard deviation is about $1/\sqrt{2(B - 1)}$. For $B$ = 25, 50, 100, 200 and 1,000 this gives 14.4%, 10.1%, 7.1%, 5.0% and 2.2%, against the observed 14.4%, 10.7%, 7.5%, 4.9% and 2.4%. The differences, at most 6.5% of the formula's value on the unrounded figures (7.3% on the table's rounded 2.4% at $B = 1{,}000$), are of the size expected from the precision of the table itself: each observed entry is a standard deviation of 200 repetitions, which by the same formula has a relative error of about $1/\sqrt{398} = 5\%$. Three of the five lie above the formula and one matches it to three decimals, which is also the direction expected if the slope replicates have somewhat heavier tails than the normal distribution the formula assumes. The formula gives a rule for choosing $B$: to report a standard error to within about 5%, $B = 200$ suffices, which agrees with the body's advice that standard errors need far fewer resamples than percentile intervals.

Problem 3 (the bootstrap of a maximum does not depend on the data). For 50 values from a uniform distribution on $[0, 1]$, compute the bootstrap probabilities that the resampled maximum equals the largest, second-largest and third-largest observed value, and compare with the true sampling distribution of the maximum.

Solution. A bootstrap sample's maximum is at most the $j$-th largest value $x_{(n - j + 1)}$ exactly when all $n$ draws avoid the $j - 1$ larger values, which has probability $((n - j + 1)/n)^n$. Differencing, with $n = 50$:

$$P^{*}\bigl(M^{*} = x_{(50)}\bigr) = 1 - \Bigl(\tfrac{49}{50}\Bigr)^{50} = 0.6358, \quad P^{*}\bigl(M^{*} = x_{(49)}\bigr) = \Bigl(\tfrac{49}{50}\Bigr)^{50} - \Bigl(\tfrac{48}{50}\Bigr)^{50} = 0.2343,$$

and $P^{*}(M^{*} = x_{(48)}) = 0.0846$. Together the top three order statistics take 95.5% of the bootstrap distribution, with the same probabilities whatever the data are, provided the three largest values are distinct (true with probability 1 for a continuous population; ties at the top merge the atoms). The true sampling distribution is quite different: the maximum $M$ is continuous, $P(M = 1) = 0$, and $P(n(1 - M) > t) = (1 - t/n)^n$, which tends to $e^{-t}$, an exponential distribution for the gap below 1. The bootstrap has no way to see the gap between $x_{(50)}$ and the population's upper limit, because no resample can exceed $x_{(50)}$. This is the failure of the plug-in step that The Plug-In Principle and Why the Bootstrap Works explains: the maximum is not a smooth function of the empirical distribution.

Open questions

  • Does BCa fix the coverage of the mean of an exponential population? The percentile interval covered the mean in 85.4% of samples of 10. Rerunning the coverage simulation with SciPy's default BCa method and with the studentized interval, at the same sizes and seed, would show how much of the shortfall each correction recovers here; Bootstrap Confidence Intervals reports the same comparison on C-reactive protein, where none of the intervals reaches 95%.
  • Can the .632+ estimator be repaired for 1-nearest-neighbor regression? Its no-information error was built for classification. Defining $\hat{\gamma}$ for regression as the error of predicting each outcome from a randomly paired input, and checking the bias in the article's simulation, would show whether a better $\hat{\gamma}$ closes the gap of $-0.056$ or whether the .632 family cannot fit a flat learning curve.
  • How does the bootstrap standard error of the median compare with the density-based formula? The large-sample standard error of a median is $1/[2 f(m)\sqrt{n}]$, which needs an estimate of the density at the median. Comparing it, with a kernel density estimate, against the bootstrap's 0.215 for the median BMI, and both against the truth in the exponential simulation at $n = 25$, would show which is more reliable at small $n$.

Where it leads

The bootstrap estimates a standard error by resampling the sample, and its percentile interval reads the interval off the resampled values. It works for smooth statistics and fails for extremes, and its estimates of prediction error need the out-of-bag correction and, for most methods, the .632 or .632+ weighting. The last article of the unit, Model Selection, uses these estimates and cross-validation to choose among models.

In Python

import numpy as np
from scipy import stats
from sklearn.datasets import load_diabetes

X, y = load_diabetes(return_X_y=True, scaled=False)
bmi = X[:, 2]
rng = np.random.default_rng(0)   # seed 0; the article's 0.215 and 0.607 come from seed 742,
                                 # and differences of this size are Monte Carlo error

# by hand: B bootstrap samples of the row indices
idx = rng.integers(0, len(y), size=(2000, len(y)))
med = np.median(bmi[idx], axis=1)
print(med.std(ddof=1), np.percentile(med, [2.5, 97.5]))   # 0.217 [25.35 26.2]

def slope(i):
    x, t = bmi[i], y[i]
    return np.cov(x, t)[0, 1] / np.var(x, ddof=1)

print(np.std([slope(i) for i in idx], ddof=1))            # 0.612

# SciPy: percentile or BCa intervals for any statistic
res = stats.bootstrap((bmi,), np.median, n_resamples=2000, method="percentile", rng=rng)
print(res.standard_error, res.confidence_interval)      # 0.214, (25.35, 26.2)

The code was run with SciPy 1.17.1; the rng argument of scipy.stats.bootstrap appeared in SciPy 1.15, and older versions take random_state. Drawing indices rather than rows keeps the cases together: the same idx resamples patients for any statistic computed from their BMI and progression jointly, as the slope is. scikit-learn's sklearn.utils.resample(X, y, replace=True, random_state=...) does the same for arrays and data frames, and the out-of-bag cases are those whose indices do not appear in the sample. For bagged models, oob_score=True computes out-of-bag error during fitting (see Random Forests). The numbers in this article are computed by tools/experiments/data-science/bootstrap-method.py in the site's repository.

References

  • Efron, B. (1979). Bootstrap methods: Another look at the jackknife. The Annals of Statistics, 7(1), 1–26. record · 3 pages
  • Efron, B. (1983). Estimating the error rate of a prediction rule: Improvement on cross-validation. Journal of the American Statistical Association, 78(382), 316–331. record
  • Efron, B., and Tibshirani, R. (1997). Improvements on cross-validation: The .632+ bootstrap method. Journal of the American Statistical Association, 92(438), 548–560. record
  • Hastie, T., Tibshirani, R., and Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.). Springer. record · 39 pages
  • James, G., Witten, D., Hastie, T., and Tibshirani, R. (2021). An Introduction to Statistical Learning with Applications in R (2nd ed.). Springer. record · 39 pages
  • White, H. (1980). A heteroskedasticity-consistent covariance matrix estimator and a direct test for heteroskedasticity. Econometrica, 48(4), 817–838. record · 3 pages

Reviewed: verified, 23 Nov 2026 · second opinion, 23 Nov 2026 · citations checked, 23 Nov 2026 · editorial review, 23 Nov 2026 · 10 revisions