Bootstrap Resampling (2D)

Resample one sample thousands of times and see the standard error and confidence interval appear.

Switch to 3D
The science

What is modelled

You hold one sample of n numbers drawn from a population you cannot see. The bootstrap treats the sample as a stand-in for the population: it draws n values with replacement from the sample (a "resample"), computes the statistic, and repeats B times. The spread of those B values estimates how much the statistic would vary from sample to sample, with no formula for its distribution.

Equations

  • Resample: x*i = xJ(i), J(i) uniform on {1..n}. Statistic θ* = T(x*) (mean or median).
  • Bootstrap standard error: SEboot = sd(θ*1..θ*B).
  • Percentile interval: the α/2 and 1-α/2 quantiles of the sorted θ* values (linear interpolation between order statistics).
  • Closed form for the mean: when T is the mean, the exact (B→∞) bootstrap SE is sqrt(Σ(xi - x̄)²) / n = s/√n · √((n-1)/n), the textbook s/√n with the plug-in (divide by n) variance. Monte Carlo noise in SEboot is about 1/√(2B) relative.

Checks run in this page

  • SE check: 4000 fresh resamples (separate random stream) must reproduce the closed form within 3.5 standard errors of the Monte Carlo estimate (width computed from the measured kurtosis of the resampled means).
  • Coverage check: 400 new samples are drawn from the known population, a percentile interval is built from each (400 resamples), and the fraction that contains the true value is compared with the nominal level, with a binomial standard error. For the mean, the exact Student-t interval is run on the same kind of samples as an independent reference (its critical value comes from an incomplete-beta bisection, not from the bootstrap).

Honest simplifications

  • The percentile interval is the simplest bootstrap interval. It tends to under-cover for small n and for skewed data (try "Tiny n=8" or "Skewed, n=15": coverage lands visibly below nominal). BCa or bootstrap-t intervals correct part of that; they are not implemented here.
  • The bootstrap cannot invent information that the sample does not contain: with n=8 the sample may miss the tail entirely, and no number of resamples fixes that.
  • The median of a small sample takes few distinct values, so its bootstrap distribution is lumpy; this is real behaviour, not a bug.
  • Populations are made-up textbook distributions with fixed parameters; coverage numbers carry Monte Carlo error (shown) and are not universal constants.
  • Pseudo-random numbers come from a seeded generator, so a preset is exactly repeatable.
Bootstrap SE settles on the exact value as B grows
Coverage experiment: intervals from 60 fresh samples
Made with 🟠 Blender