Bootstrapping

Bootstrapping

How resampling the data with replacement many times estimates the uncertainty of almost any statistic, giving standard errors and confidence intervals without relying on formulas or normality.

What it is

The bootstrap, introduced by Bradley Efron in 1979, is a resampling method for estimating how much a statistic would vary if the study were repeated. Instead of deriving a formula for the uncertainty, the analyst treats the observed sample as a stand-in for the population and draws many new samples from it, each the same size as the original and taken with replacement, so a value can appear several times in one resample and not at all in another. The statistic is recalculated for every resample, and the spread of those values estimates the standard error, bias and confidence interval of the statistic. It is used in nearly every field that analyzes data, particularly where theory is hard or assumptions doubtful.

It answers questions such as: How uncertain is this median, ratio, correlation, regression coefficient or machine-learning accuracy? What is a 95% confidence interval when the data are skewed or the sample small? Is a difference between two groups larger than chance? How stable is a clustering, phylogenetic tree or selected variable set? The bootstrap needs only computing time, not a derivation for each new statistic.

Fundamentals

The bootstrap principle

The unknown population distribution F is replaced by the empirical distribution F̂, which puts probability 1/n on each observation. Sampling from F̂ mimics sampling from F: the relationship between a bootstrap statistic θ̂* and the sample statistic θ̂ approximates the relationship between θ̂ and the unknown true θ. The procedure is: for b = 1, …, B, draw a resample x*b of size n with replacement and compute θ̂*b. Then the bootstrap standard error is SEboot = √[Σ(θ̂*b − mean θ̂*)2/(B − 1)], and the bias estimate is mean(θ̂*) − θ̂. Typical B is 1,000 for standard errors and 5,000–10,000 for confidence intervals, and B should be increased until results are stable; B does not add information beyond the n data, only reduces Monte Carlo error.

Confidence intervals

  • Normal interval: θ̂ ± zα/2 SEboot, valid if the sampling distribution is roughly normal.
  • Percentile interval: the 2.5th and 97.5th percentiles of the θ̂* values, simple and transformation-respecting but can be biased and too narrow for small samples.
  • Basic (pivotal) interval: [2θ̂ − q97.5, 2θ̂ − q2.5], reflecting the percentiles around the estimate.
  • BCa (bias-corrected and accelerated): adjusts the percentiles for bias (z0) and skewness (acceleration a, estimated by jackknife), is second-order accurate and is usually the best general choice.
  • Bootstrap-t (studentized): resamples a t-like statistic using the standard error from each resample, accurate but requiring an SE for each resample (often by a nested bootstrap).

Variants for different data structures

The simple (nonparametric) bootstrap assumes independent, identically distributed observations. For other situations use: parametric bootstrap, simulating from a fitted model (such as a normal or Weibull with estimated parameters) when a model is trusted; residual bootstrap in regression, resampling residuals and adding them to the fitted values (when the model is correct and fixed design), versus case (pairs) bootstrap, resampling entire rows (more robust to heteroscedasticity); block bootstrap (moving, stationary) for time series, resampling blocks of consecutive values to preserve dependence; cluster bootstrap, resampling whole subjects or sites in hierarchical data; stratified bootstrap, resampling within groups; and the wild bootstrap for heteroscedastic regression. The permutation test is a related resampling method that shuffles labels (without replacement) to test the null hypothesis, and the jackknife (leave-one-out) is an older, more limited relative. Bootstrap hypothesis tests resample under the null (for example, by centering each group on a common mean).

Applications in modeling and machine learning

Bootstrap resampling is used for confidence intervals of nonlinear fit parameters (see nonlinear curve fitting), for the stability of selected variables, clusters or principal components, and for node support in phylogenetic trees (bootstrap percentages). Bagging (bootstrap aggregating) trains models on bootstrap samples and averages them, the basis of random forests. Estimates of prediction error can be corrected for optimism with the .632 and .632+ bootstrap, or by bootstrapping the whole modeling pipeline, including feature selection. Mediation effects (products of coefficients) are routinely tested with bootstrap intervals (see structural equation modeling). In meta-analysis and uncertainty analysis it propagates input uncertainty to results. Software: R (boot, bootstrap, rsample), Python (scipy.stats.bootstrap, arch, scikit-learn resample), MATLAB (bootstrp), Stata (bootstrap).

When the bootstrap fails

The bootstrap is not magic. It fails or performs poorly for: very small samples (below about 10–20, where the empirical distribution poorly represents the population), statistics depending on extreme values (the sample maximum or minimum, extreme quantiles), heavy-tailed distributions with infinite variance, non-smooth statistics at boundaries, dependent data analyzed with the simple bootstrap (leading to intervals that are too narrow), and biased sampling (it cannot fix a nonrepresentative sample). The bootstrap reproduces sampling variability, not the bias from measurement error or flawed design. When n is small, results should be reported with caution, and a parametric model or exact method should be considered.

Typical applications and limits

Applications include confidence intervals for medians, ratios, correlations, effect sizes and model performance; standard errors for complicated estimators; and checking assumptions. Limits are noted above, together with computing cost for large models and the need for judgment about the resampling scheme.

Basic operation

  1. Define the statistic. Write a function that computes the quantity of interest from a dataset.
  2. Choose the resampling scheme. Pick case, residual, block, cluster or parametric resampling to match the data structure.
  3. Resample. Draw B resamples (such as 5,000) with a fixed random seed.
  4. Compute the statistic for each. Store all B values.
  5. Inspect the distribution. Plot a histogram, and look for skewness, bias and outliers.
  6. Calculate the interval and standard error. Prefer BCa or studentized intervals for general use.
  7. Check stability. Repeat with different B or seeds to confirm Monte Carlo error is small.
  8. Collect the output. You obtain a standard error and confidence interval; choosing intervals and block lengths is covered in the video.

Good practice

  • Resample at the right level. Resample independent units (subjects), not repeated measurements.
  • Use enough resamples. At least 1,000, more for tail intervals.
  • Prefer BCa for intervals. Plain percentile intervals can undercover.
  • Set and report the seed. It makes results reproducible.
  • Be careful with small samples and extremes. The bootstrap may mislead.
  • Include the whole pipeline. Repeat variable selection and tuning inside each resample, and do not present bootstrap intervals as a cure for unrepresentative or biased data.

Key terms

  • Resampling with replacement — drawing observations so that each can be chosen more than once.
  • Empirical distribution — the distribution placing equal probability on each observed value.
  • Bootstrap standard error — the standard deviation of the statistic across resamples.
  • Percentile / BCa interval — bootstrap confidence intervals from resampled statistics, with BCa correcting bias and skewness.
  • Block bootstrap — resampling blocks of consecutive data points to preserve time dependence.
  • Bagging — averaging models trained on bootstrap samples.
  • Out-of-bag sample — the observations not drawn in a particular resample.

Video coming soon

About five minutes on Bootstrapping: how it works in detail, how the data is acquired, and how it is analyzed.

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping