Foundations to Frontier
Tests
A. Mathematical Foundations › A5 Statistics › Descriptive and inferential statistics

Bootstrap and Resampling

When there is no formula for a standard error, simulate one from the data you have. The bootstrap resamples the observed sample with replacement, recomputes the statistic each time, and reads its uncertainty off the spread: SEs and confidence intervals for medians, trimmed means, ratios, robust aggregates of benchmark scores, anything. You will learn percentile and basic intervals, why bootstrap samples contain about 63% of the data, stratified and block bootstraps for structured and correlated data, where the bootstrap fails (maxima, tiny samples), and its relatives: the jackknife, cross-validation and bagging.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Making more experiments out of one

You timed a robot 40 times and found a median of 2.7 minutes. How precise is that median? Ideally you’d repeat the whole 40-run experiment many times and see how much the median moves. You can’t afford that. The bootstrap pretends your 40 runs are the population. It draws 40 runs from them at random, with repeats allowed, computes the median, and does that a thousand times. The spread of those medians estimates how much your real median would wobble.

It sounds like cheating, but it works remarkably well for most statistics, and it needs no formula at all.

Pull yourself up by your bootstraps: resample the data you have
statistic:
observed median 2.646 · bootstrap SE 0.250 (true SE 0.374) · 95% percentile CI [2.103, 3.011]
Orange: the bootstrap distribution, from 1500 resamples of the one observed sample. Grey dashed: the true sampling distribution from fresh samples, which you normally can't see. Green: the observed statistic. Shaded: the percentile interval. For smooth statistics (mean, median, trimmed mean) the bootstrap spread tracks the truth with no formula needed. For the max it piles up at the observed value (about 63%) and can't see beyond it: the bootstrap fails for extremes.
Why engineers care

Uncertainty for a median latency, a 95th-percentile error, a ratio of two rates, an interquartile-mean score across RL tasks, or a model’s accuracy on a test set: most real statistics have no textbook SE. The bootstrap gives one in a few lines of code.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A bootstrap resample is drawn…
  2. 2. The spread of bootstrap statistics estimates…
  3. 3. Does the bootstrap need a formula for the SE?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The plug-in principle

The unknown population distribution FF is replaced by the empirical distribution F^n\hat F_n, which puts mass 1/n1/n on each observation. Sampling from F^n\hat F_n means resampling the data with replacement (Efron, 1979).

Algorithm:

  1. For b=1,…,Bb = 1, \dots, B, draw x∗bx^{*b} by resampling nn points with replacement, and compute θ^∗b=T(x∗b)\hat\theta^{*b} = T(x^{*b}).
  2. SE: SE⁡^=sd⁡(θ^∗1,…,θ^∗B)\widehat{\operatorname{SE}} = \operatorname{sd}(\hat\theta^{*1}, \dots, \hat\theta^{*B}).
  3. Percentile CI: the α/2\alpha/2 and 1−α/21 - \alpha/2 quantiles of the θ^∗\hat\theta^*.

Use B≈1000B\approx1000–50005000 for intervals. A few hundred is enough for an SE.

Facts worth knowing

  • Each resample contains about 1−(1−1/n)n→1−1/e≈63.2%1 - (1 - 1/n)^n\to1 - 1/e\approx63.2\% of the distinct original points. The remainder are “out-of-bag”.
  • For the mean, the bootstrap SE is ≈s/n\approx s/\sqrt n, so it agrees with theory where theory exists.
📝 Quick check (Level 1)
0/3 answered
  1. 1. About what fraction of original points appear in a bootstrap sample?
  2. 2. The percentile interval uses…
  3. 3. The bootstrap replaces F with…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Interval flavours

  • Percentile: [qα/2∗,q1−α/2∗][q^*_{\alpha/2}, q^*_{1-\alpha/2}]. Simple, and transformation-respecting.
  • Basic (reverse percentile): [2θ^−q1−α/2∗,2θ^−qα/2∗][2\hat\theta - q^*_{1-\alpha/2}, 2\hat\theta - q^*_{\alpha/2}]. It assumes the distribution of θ^−θ\hat\theta - \theta resembles that of θ^∗−θ^\hat\theta^* - \hat\theta.
  • BCa (bias-corrected and accelerated): adjusts the percentiles for bias and skewness. It’s more accurate (second-order correct) and the standard choice when it matters (Efron, 1987).
  • Studentized bootstrap-t: bootstrap (θ^∗−θ^)/SE⁡^∗(\hat\theta^* - \hat\theta)/\widehat{\operatorname{SE}}^*. It’s also second-order accurate, but needs an SE for each replicate.

Respect the data’s structure

  • Stratified: with runs × tasks, resample runs within each task. Don’t mix tasks.
  • Clustered / hierarchical: resample whole clusters (robots, days, users), not individual measurements.
  • Time series: the i.i.d. bootstrap destroys autocorrelation and badly understates the SE. The moving block bootstrap resamples contiguous blocks of length ℓ∼n1/3\ell\sim n^{1/3} (Künsch, 1989).
  • Regression: resample (x, y) pairs, or residuals from a fitted model.

When the bootstrap fails

  • Extremes: for the sample maximum, about 63% of replicates equal the observed max, and the bootstrap distribution can’t extend beyond it.
  • Tiny samples: with n=5n = 5, F^n\hat F_n is a poor stand-in for FF, and intervals under-cover.
  • Heavy tails without a variance, statistics at the edge of the parameter space, and non-smooth functionals.
🐍 Exercise 1: bootstrap SEs and intervals
Implement a vectorized bootstrap, its SE, and the percentile and basic intervals. Check that the SE of the mean matches s/√n, and that percentile intervals for the median of skewed (lognormal) task times cover about 95%.
📝 Quick check (Level 2)
0/3 answered
  1. 1. For a correlated time series, use…
  2. 2. The bootstrap is unreliable for…
  3. 3. Measurements from several robots should be resampled…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Why it works (and when)

The bootstrap approximates the unknown distribution of n(θ^−θ)\sqrt n(\hat\theta - \theta) under FF by the computable distribution of n(θ^∗−θ^)\sqrt n(\hat\theta^* - \hat\theta) under F^n\hat F_n. By Glivenko–Cantelli (A4.3-4), F^n→F\hat F_n\to F uniformly. If the functional TT is smooth (Hadamard differentiable), the delta method in function space carries this convergence through to the statistic. So the bootstrap is consistent for means, medians, quantiles, trimmed means and smooth functions of moments (Bickel and Freedman, 1981; van der Vaart, 1998). The maximum is not smooth at the boundary, and the argument breaks.

P(observed max is repeated)

The maximum x(n)x_{(n)} appears in a resample unless all nn draws miss it: P=1−(1−1/n)n→1−1/eP = 1 - (1 - 1/n)^n\to1 - 1/e. So the bootstrap distribution of n(x(n)−x(n)∗)n(x_{(n)} - x^*_{(n)}) has an atom of mass 0.63 at 0, while the true limiting distribution (for example exponential, A4.3-8) has none.

Jackknife, cross-validation and bagging

  • Jackknife: leave one out at a time. Bias ≈(n−1)(θˉ(⋅)−θ^)\approx(n - 1)(\bar\theta_{(\cdot)} - \hat\theta) and SE⁡2≈n−1n∑(θ^(i)−θˉ(⋅))2\operatorname{SE}^2\approx\frac{n-1}n\sum(\hat\theta_{(i)} - \bar\theta_{(\cdot)})^2. It’s a linear approximation to the bootstrap, and it fails for the median.
  • Cross-validation: resampling used to estimate prediction error, not the variance of a statistic.
  • Bagging and random forests: average models trained on bootstrap resamples to reduce variance. The out-of-bag points give a free error estimate (Breiman, 1996, 2001).
Exercise 3.1: Show that the bootstrap SE of the mean is s·√((n − 1)/n)/√n

Under F^n\hat F_n, a single draw has variance σ^2=1n∑(xi−xˉ)2\hat\sigma^2 = \frac1n\sum(x_i - \bar x)^2. The mean of nn i.i.d. draws has variance σ^2/n\hat\sigma^2/n. As B→∞B\to\infty, the bootstrap SE converges to σ^/n=s(n−1)/n/n\hat\sigma/\sqrt n = s\sqrt{(n-1)/n}/\sqrt n.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Bootstrap consistency for smooth statistics follows from…
  2. 2. The jackknife fails for…
  3. 3. Bagging averages models trained on…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Honest uncertainty for benchmark scores

Deep-RL results are often a few seeds per task across many tasks, with occasional collapsed runs. Agarwal et al. (2021) recommend the interquartile mean (IQM) across all runs and tasks as a robust aggregate, reported with a stratified bootstrap confidence interval: resample seeds within each task. With 10 tasks × 5 seeds, the honest interval is wide, and it covers a little below 95% because each task has only 5 runs. That’s a reason to run more seeds, not to drop the interval. The same recipe applies to robot success rates across environments and to model accuracy across data shards.

🐍 Exercise 2 (research): stratified bootstrap CIs for an interquartile mean
Simulate 10 tasks × 5 seeds with occasional collapses. Compute the IQM and its stratified-bootstrap 95% CI, check coverage against the population IQM, and show that the bootstrap fails for the sample maximum (P(max* = max) ≈ 1 − (1 − 1/n)ⁿ).

Resampling in AI, robotics and aerospace

  • Model evaluation. Bootstrap CIs on test accuracy, AUC or calibration error. Paired bootstrap for comparing two models on the same test set (Koehn, 2004, for MT; widely used across ML).
  • Ensembles and uncertainty. Bagged ensembles and bootstrapped DQN use resampling to represent epistemic uncertainty and drive exploration (Osband et al., 2016).
  • Particle filters resample particles by weight (A4.3-4), a different “bootstrap”: Gordon, Salmond and Smith (1993) called it the bootstrap filter.
  • Reliability and dispersion analysis. Bootstrap CIs for percentiles of Monte Carlo outputs, and block bootstraps for correlated simulation output.
  • Robotics benchmarks. Cluster bootstraps by robot or by environment avoid treating repeated runs as independent.

References

  1. B. Efron (1979). “Bootstrap methods: another look at the jackknife.” Annals of Statistics, 7(1).
  2. B. Efron (1987). “Better bootstrap confidence intervals.” JASA, 82(397).
  3. B. Efron, R. Tibshirani (1993). An Introduction to the Bootstrap. Chapman & Hall.
  4. A. Davison, D. Hinkley (1997). Bootstrap Methods and Their Application. Cambridge University Press.
  5. P. Bickel, D. Freedman (1981). “Some asymptotic theory for the bootstrap.” Annals of Statistics, 9(6).
  6. H. Künsch (1989). “The jackknife and the bootstrap for general stationary observations.” Annals of Statistics, 17(3).
  7. L. Breiman (1996). “Bagging predictors.” Machine Learning, 24.
  8. R. Agarwal, M. Schwarzer, P. Castro, A. Courville, M. Bellemare (2021). “Deep reinforcement learning at the edge of the statistical precipice.” NeurIPS.
  9. I. Osband, C. Blundell, A. Pritzel, B. Van Roy (2016). “Deep exploration via bootstrapped DQN.” NeurIPS.
  10. N. Gordon, D. Salmond, A. Smith (1993). “Novel approach to nonlinear/non-Gaussian Bayesian state estimation.” IEE Proceedings F, 140(2).