The bootstrap
| Problem | Estimate the standard error, bias and confidence interval of any statistic, without a formula for its sampling distribution |
| Devised by | Maurice Quenouille (1949) and John Tukey (1958), the jackknife; Bradley Efron (1979), the bootstrap; Efron (1987), the bias-corrected and accelerated (BCa) interval |
| Accuracy | Percentile intervals are first-order accurate (coverage error ); BCa intervals second-order (). Both under-cover for small, skewed samples (table below) |
| Cost | evaluations of the statistic on resamples of size (typically to ), plus jackknife evaluations for BCa |
| Read first | Descriptive statistics, Pseudo-random number generators |
| API | bootstrap, BootstrapResult (percentile_interval, bca_interval) |
Overview
The uncertainty of a statistic is described by its sampling distribution: how it would vary over repeated samples from the population. For a mean, theory gives the answer ; for a median, a correlation, a ratio or the output of a complicated procedure, there may be no usable formula. The bootstrap replaces the unknown population by the sample itself. Draw values with replacement from the data, recompute the statistic, repeat times, and treat the spread of the replicates as an estimate of the sampling distribution.
Where it is used
The bootstrap gives uncertainty estimates when there is no formula.
- Engineering and science. Confidence intervals for a median, a correlation, a ratio or a fitted parameter from a modest number of measurements.
- Machine learning. Bagging (the basis of random forests) averages models trained on bootstrap resamples.
- Model checking. Estimating the bias and variance of any estimator by simulation, with no assumption about the underlying distribution.
History
Maurice Quenouille (1949) introduced the jackknife to reduce bias, recomputing a statistic with each observation left out in turn, and John Tukey (1958) used it to estimate variances and named it after a rough-and-ready tool. Bradley Efron’s “Bootstrap methods: another look at the jackknife” (1979) generalised the idea to resampling with replacement, and the cheapness of computing made it practical. Efron (1987) introduced the bias-corrected and accelerated interval, and the second-order theory of bootstrap intervals was developed by Peter Hall (1988, 1992), Thomas DiCiccio and others. Efron and Robert Tibshirani’s An Introduction to the Bootstrap (1993) brought the method into everyday practice.
The idea
Resampling and the plug-in principle
Why should resampling the data we already have tell us anything about samples we never took?
The sampling distribution of is determined by the population distribution : if we knew , we could simulate as many fresh samples as we liked and watch how varies. We do not know , but we have an estimate of it. The empirical distribution puts probability on each observation, and for a reasonably large sample it resembles . The plug-in principle is to use wherever is needed. Drawing a sample of size from means choosing of the observations at random, with replacement, since each draw is independent and may pick the same observation again.
So the bootstrap is a simulation of the sampling process with standing in for . From the replicates :
- the standard error of is estimated by the standard deviation of the replicates;
- the bias is estimated by , the amount by which the replicates, on average, overshoot the value for the sample they were drawn from.
A resample is not a copy of the data. The chance that a given observation is missed by all draws is , so a resample contains on average of the distinct observations, some of them repeated. That variation in which observations are included is what mimics the variation between real samples.
Percentile intervals
A confidence interval at level is a range computed from the data that contains the true value in a fraction of repeated experiments; that fraction is its coverage. The simplest bootstrap interval reads the range straight off the replicates: it runs from their quantile to their quantile. For a 90% interval, sort the replicates and cut off the lowest 5% and the highest 5%.
The percentile interval is exactly right when some monotone transformation of has a normal, unbiased sampling distribution. Otherwise it inherits whatever bias and skewness the bootstrap distribution has, and its actual coverage differs from the nominal by an error of order .
The BCa interval
Efron’s bias-corrected and accelerated (BCa) interval uses the same replicates but reads off different quantiles, adjusted for two defects of the percentile interval.
Bias correction. If the statistic were unbiased in the median sense, half the replicates would fall below . The actual fraction measures the bias, expressed as a normal quantile:
which is zero when exactly half fall below.
Acceleration. The percentile interval assumes that the standard error of is the same whatever the true is. Often it is not: the standard error of a standard deviation, for instance, grows with the standard deviation itself. The acceleration measures how fast the standard error changes with . It is estimated from the jackknife values , the statistic recomputed with observation left out, through their skewness:
where is the mean of the jackknife values.
The interval. With , the endpoints are the replicate quantiles at the levels
When and this reduces to , that is and : the percentile interval. Otherwise both ends shift, in the direction that compensates for the bias and the skewness. BCa intervals are transformation-respecting (the interval for is applied to the interval for ) and second-order accurate: their coverage error is instead of .
How well do they cover?
Table 10.10. Coverage of bootstrap confidence intervals.
| statistic (true value) | interval | percentile | BCa | |
|---|---|---|---|---|
| mean (1) | 10 | 0.858 | 0.813 | 0.819 |
| mean (1) | 30 | 0.873 | 0.855 | 0.858 |
| mean (1) | 100 | 0.882 | 0.881 | 0.884 |
| standard deviation (1) | 10 | — | 0.562 | 0.605 |
| standard deviation (1) | 30 | — | 0.725 | 0.776 |
| standard deviation (1) | 100 | — | 0.810 | 0.830 |
Fraction of 1000 exponential samples whose nominal 90% interval (1000 resamples) contains the true value; the Monte Carlo standard error is about 0.01.
For the mean of exponential data, all three intervals under-cover at and approach 90% as grows; the bootstrap intervals are slightly narrower than the interval because the bootstrap divides by rather than and ignores the extra uncertainty of estimating the variance. For the standard deviation, a statistic driven by the few largest values of a skewed sample, coverage is poor: 56–61% at , still 81–83% at , with BCa consistently better than percentile. The bootstrap cannot invent information about tails the sample has not seen.
Figure 10.4. Bootstrap replicates.
The replicates of the standard deviation from one sample of 30 are lumpy, because the result depends mainly on how many copies of the largest observation a resample contains. The BCa interval is shifted to the right of the percentile one, correcting for the skewness, and covers the true value.
Algorithm
Input: the data, a function that computes the statistic, the number of replicates and a confidence level .
- Compute the statistic on the original data.
- Resample. For : draw indices uniformly from with replacement, form the resample from those observations, and evaluate the statistic on it to get .
- Standard error and bias. The standard error is the standard deviation of the replicates. The bias estimate is their mean minus .
- Percentile interval. Sort the replicates and take their and quantiles.
- BCa interval.
- Compute from the fraction of replicates below .
- Compute the jackknife values, each the statistic with one observation left out, and from them the acceleration .
- Compute the two adjusted levels from , and , and take the replicate quantiles at those levels.
The cost is evaluations of the statistic, plus more for the jackknife if the BCa interval is requested.
Implementation
/// Resamples `data` with replacement `resamples` times and evaluates `statistic` on each.
pub fn bootstrap<S: Fn(&[f64]) -> f64>(data: &[f64], statistic: S, resamples: usize, seed: u64) -> Result<BootstrapResult, ErrorsJSL> {
if data.len() < 2 || resamples < 2 {
return Err(ErrorsJSL::InvalidInputRange("Need at least two observations and two resamples."));
}
let n = data.len();
let mut rng = UniformRNG::from_seed(seed);
let mut sample = vec![0.0; n];
let replicates: Vec<f64> = (0..resamples)
.map(|_| {
for s in sample.iter_mut() {
*s = data[((rng.next_f64() * n as f64) as usize).min(n - 1)];
}
statistic(&sample)
})
.collect();
let estimate = statistic(data);
let m = replicates.iter().sum::<f64>() / resamples as f64;
let standard_error = (replicates.iter().map(|r| (r - m).powi(2)).sum::<f64>() / (resamples - 1) as f64).sqrt();
Ok(BootstrapResult { estimate, replicates, standard_error, bias: m - estimate })
}
/// The bias-corrected and accelerated (BCa) interval of Efron: the percentile levels are
/// shifted by the bias correction `z₀ = Φ⁻¹(#{θ* < θ̂}/B)` and the acceleration `a` from the
/// jackknife skewness of `statistic` on `data` (the same data and statistic as the
/// bootstrap). Second-order accurate, unlike the percentile interval.
pub fn bca_interval<S: Fn(&[f64]) -> f64>(&self, data: &[f64], statistic: S, confidence: f64) -> (f64, f64) {
let s = self.sorted();
let below = s.iter().filter(|&&r| r < self.estimate).count() as f64;
let z0 = normal_quantile((below / s.len() as f64).clamp(1e-10, 1.0 - 1e-10), 0.0, 1.0);
let n = data.len();
let jackknife: Vec<f64> = (0..n).map(|i| statistic(&[&data[..i], &data[i + 1..]].concat())).collect();
let jm = jackknife.iter().sum::<f64>() / n as f64;
let (num, den) = jackknife.iter().fold((0.0, 0.0), |(a, b), &t| (a + (jm - t).powi(3), b + (jm - t).powi(2)));
let acceleration = if den > 0.0 { num / (6.0 * den.powf(1.5)) } else { 0.0 };
let level = |z: f64| normal_cdf(z0 + (z0 + z) / (1.0 - acceleration * (z0 + z)), 0.0, 1.0);
let z = normal_quantile((1.0 + confidence) / 2.0, 0.0, 1.0);
(quantile_of_sorted(&s, level(-z)), quantile_of_sorted(&s, level(z)))
}
bootstraptakes a seed, so results are reproducible; the statistic is anyFn(&[f64]) -> f64.bca_intervalneeds the original data and statistic again, for the jackknife.
In practice
//! Bootstrap confidence intervals for a median and a ratio of means.
use lib_jsl_statistics::bootstrap::bootstrap;
use lib_jsl_statistics::descriptive::median;
fn main() {
// Response times in milliseconds, right-skewed.
let times = [112.0, 98.0, 143.0, 87.0, 251.0, 104.0, 133.0, 96.0, 178.0, 121.0, 92.0, 310.0, 118.0, 101.0, 145.0, 89.0, 127.0, 166.0, 109.0, 95.0];
let statistic = |x: &[f64]| median(x).unwrap();
let b = bootstrap(×, statistic, 5000, 42).unwrap();
println!("median = {:.1} ms, bootstrap standard error = {:.1}, bias = {:+.2}", b.estimate, b.standard_error, b.bias);
let (lo, hi) = b.percentile_interval(0.95);
println!("95% percentile interval: [{lo:.1}, {hi:.1}]");
let (lo, hi) = b.bca_interval(×, statistic, 0.95);
println!("95% BCa interval: [{lo:.1}, {hi:.1}]");
// The coefficient of variation, a statistic with no simple standard-error formula.
let cv = |x: &[f64]| {
let m = x.iter().sum::<f64>() / x.len() as f64;
(x.iter().map(|v| (v - m).powi(2)).sum::<f64>() / (x.len() - 1) as f64).sqrt() / m
};
let b = bootstrap(×, cv, 5000, 7).unwrap();
let (lo, hi) = b.bca_interval(×, cv, 0.95);
println!("coefficient of variation = {:.3}, 95% BCa interval [{lo:.3}, {hi:.3}]", b.estimate);
}
median = 115.0 ms, bootstrap standard error = 9.9, bias = +0.84
95% percentile interval: [99.5, 138.0]
95% BCa interval: [98.0, 133.0]
coefficient of variation = 0.426, 95% BCa interval [0.262, 0.582]
Strengths
- Works for any statistic, however complicated, with no derivation.
- BCa intervals correct for bias and skewness, with second-order accuracy.
Weaknesses
- Under-covers for small samples and for statistics that depend on the tails; it cannot do better than the sample.
- Fails for some statistics: the maximum, and statistics of heavy-tailed data with infinite variance.
- Independent observations only; dependent data (time series) need block resampling, which is not implemented.
- evaluations of the statistic can be expensive.
Exercises
- Show that the probability that a given observation is absent from a resample tends to .
- Compute the exact bootstrap distribution of the mean of the sample by enumerating all 27 resamples.
- Show that the bootstrap variance of the mean is , and compare with .
- Show that the bootstrap fails for the sample maximum of a uniform distribution: what is the probability that the maximum of a resample equals the sample maximum?
- Compare the coverage of percentile and BCa intervals for the correlation coefficient of bivariate normal data with , .
Hints and answers
- A given observation is missed by each of the draws with probability , so it is absent with probability .
- The 27 resamples give sums with counts for sums . The bootstrap mean is the sum divided by 3, with expectation and variance .
- with , giving . This is times . For the bootstrap variance is while .
- The resample maximum equals the sample maximum whenever the largest observation appears at least once: probability . The bootstrap distribution therefore has a large atom at the sample maximum, which the true distribution (continuous) does not have.
- Simulate many data sets, compute each interval, and count how often it contains ; BCa usually has coverage closer to the nominal level than the percentile interval for such a skewed statistic with .
Further reading
- B. Efron, “Bootstrap methods: another look at the jackknife”, Annals of Statistics 7 (1979) 1–26.
- B. Efron, “Better bootstrap confidence intervals”, Journal of the American Statistical Association 82 (1987) 171–185.
- B. Efron and R. J. Tibshirani, An Introduction to the Bootstrap, Chapman and Hall, 1993.
- T. J. DiCiccio and B. Efron, “Bootstrap confidence intervals”, Statistical Science 11 (1996) 189–228.
- A. C. Davison and D. V. Hinkley, Bootstrap Methods and their Application, Cambridge University Press, 1997.