Skip to content
mlmentorship

Bootstrap and resampling

Estimate uncertainty by resampling the observed units. Preserve pairing and dependence, report the resampling unit, and know when the bootstrap can fail.

Published · 9 min read ·Core ·Intermediate

Visual quick review

Identify the independent sampling unit and keep every dependent observation attached to it when constructing a bootstrap replicate.

Resampling unit

Resample users with all their paired events, not isolated rows

Repeated users bring their paired events with themSampling users preserves within-user event pairing. Resampling isolated rows would answer a different uncertainty question.Sample the user; carry both pairedeventsOriginal user clusters: A, B, CAa1a2Bb1b2Cc1c2One bootstrap sample: A, C, AAa1a2Cc1c2Aa1a2A is repeated as a whole; B isabsent.
Read it this way: Sampling users preserves within-user event pairing. Resampling isolated rows would answer a different uncertainty question. Which events travel together when user A is sampled twice?
Full explanation 9 min read
Reading depth

Summary

The bootstrap recomputes a statistic after drawing observed sampling units with replacement. Its empirical resampling distribution can approximate sampling uncertainty under appropriate sampling, dependence, and estimator conditions. Choose the target population and independent unit first; more simulated replicates cannot repair missing population information.

Choose the resampling unit

The independent unit may be larger than one row.

Data structureResampling unit
Independent examplesexample
Many events per useruser
Documents split into passagesdocument
Queries with many candidatesquery
Time seriestime block
Multi-seed training studyseed or complete run

For a mechanics fixture, independent users U1, U2, and U3 have paired model differences respectively. Each user has two perfectly correlated events with that same difference; the target is the equal-user mean, zero. Draw U3, U1, U3 and carry both events and both model outcomes whenever a user is selected. The replicate user mean is .

Resampling unit

Valid user-level bootstrap compared with invalid event-row bootstrap

Valid user-level bootstrap compared with invalid event-row bootstrap The source dataset contains users U1, U2, and U3, each enclosing two event rows with paired model A and B outcomes. A valid bootstrap replicate draws U3, U1, and U3, carrying both events and both model outcomes whenever a user is selected. An invalid replicate samples detached event rows from across users and is crossed out because it breaks within-user dependence. SOURCE DATA · USERS ARE THE INDEPENDENT UNITS U1 U2 U3 event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B VALID REPLICATE · DRAW U3, U1, U3 U3 U1 U3 again event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B each draw carries the whole user cluster INVALID FOR THIS DATA · DRAW DETACHED EVENTS U3 event 2 A + B U1 event 1 A + B U2 event 2 A + B breaks within-user dependence → uncertainty can look too small
draw a user and carry the entire cluster. U3 can repeat and U2 can be omitted. Keep both models' paired outcomes attached to every selected event. The original graphic follows Efron, SciPy, and Bootstrap Methods and Their Application.
Check: Which records must travel together when U3 is drawn twice?
Reference drawing

Resampling unit

Resample users with all their paired events, not isolated rows

Repeated users bring their paired events with themSampling users preserves within-user event pairing. Resampling isolated rows would answer a different uncertainty question.Sample the user; carry both pairedeventsOriginal user clusters: A, B, CAa1a2Bb1b2Cc1c2One bootstrap sample: A, C, AAa1a2Cc1c2Aa1a2A is repeated as a whole; B isabsent.
Derivation
Valid user-level bootstrap compared with invalid event-row bootstrap The source dataset contains users U1, U2, and U3, each enclosing two event rows with paired model A and B outcomes. A valid bootstrap replicate draws U3, U1, and U3, carrying both events and both model outcomes whenever a user is selected. An invalid replicate samples detached event rows from across users and is crossed out because it breaks within-user dependence. SOURCE DATA · USERS ARE THE INDEPENDENT UNITS U1 U2 U3 event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B VALID REPLICATE · DRAW U3, U1, U3 U3 U1 U3 again event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B event 1 · A + B event 2 · A + B each draw carries the whole user cluster INVALID FOR THIS DATA · DRAW DETACHED EVENTS U3 event 2 A + B U1 event 1 A + B U2 event 2 A + B breaks within-user dependence → uncertainty can look too small
draw a user and carry the entire cluster. U3 can repeat and U2 can be omitted. Keep both models' paired outcomes attached to every selected event. The original graphic follows Efron, SciPy, and Bootstrap Methods and Their Application.
Check: Which records must travel together when U3 is drawn twice?
Read it this way: Sampling users preserves within-user event pairing. Resampling isolated rows would answer a different uncertainty question. Which events travel together when user A is sampled twice?

Nonparametric bootstrap

With independent units and statistic , draw unit indices with replacement and recompute . Repeat times while preserving the same estimand and within-unit structure. An original unit is omitted with probability , approaching . The familiar inclusion figure is an asymptotic expectation, not an exact count in each replicate.

The three-user fixture has equally likely ordered draws. Replicate sums have counts ; divide each sum by three. Their probability-weighted mean is zero and variance is , giving standard deviation . Equivalently, the empirical user variance is divided by three independent empirical draws. This exact conditional distribution illustrates mechanics; three users do not establish reliable interval coverage.

Standard error and confidence intervals

For randomly simulated replicates, estimate bootstrap standard error by their sample standard deviation. Exact enumeration instead uses the probability-weighted variance over all possible draws, as above. A percentile interval uses empirical quantiles, conventionally and for a nominal interval. Nominal coverage is not guaranteed; bias, skewness, dependence, and estimator irregularity matter. Increasing reduces simulation error, not the original sampling uncertainty.

Paired model comparison

For models scored on the same units, retain within every resampled unit. Breaking pairing changes the resampling distribution; it need not always widen the interval. For the fixture, incorrectly drawing six detached events gives mean variance , half the user-bootstrap variance. Decide whether prompts, raters, users, or training runs supply the independence relevant to the desired uncertainty.

Change Cluster Sizes

New task: Give U1 and U2 one event each, but U3 eight events.

Picture and change: Retain user means for equal-user performance. For event-weighted performance, divide summed event differences by selected event count.

Check: Equal-user effect remains zero; observed event-weighted effect is . For draw U3, U1, U3, those estimators give versus .

Use when: Unequal exposure changes whether the target represents a random user or a random event.

Preserve Time Dependence

New task: Resample [0,0,1,1] with dependence inside length-two blocks.

Picture and change: Draw whole blocks [0,0] and [1,1], retaining paired outcomes.

Check: Drawing both blocks gives mean ; drawing the first twice gives zero.

Use when: Relevant local dependence fits the declared block length and stationarity assumptions.

Block and cluster bootstrap

A cluster bootstrap samples whole groups. It preserves dependence within each group and assumes groups are approximately independent.

A block bootstrap samples contiguous time windows. It preserves short-range temporal dependence. The block length must be long enough to retain relevant correlation, but short enough to provide enough distinct blocks.

For hierarchical data, a multi-stage bootstrap can sample users first and events within selected users second. State the population that each stage represents.

Worked example

As a separate hypothetical decision illustration, two fixed classifiers differ by positive accuracy percentage points on one thousand examples. Suppose a suitable paired analysis reports interval points. These illustrative endpoints are not computed from the three-user fixture or unspecified per-example outcomes. The result includes possible losses; a launch still needs decision thresholds, guardrails, and an appropriate uncertainty argument.

When the bootstrap fails

The ordinary bootstrap can fail when:

  • observations are dependent but rows are resampled independently;
  • the sample is too small to represent rare outcomes;
  • the estimator changes discontinuously near a boundary;
  • extreme values dominate a heavy-tailed statistic;
  • classes or slices absent from the sample matter in deployment;
  • the data was selected by a policy that hides unobserved outcomes.

Resampling cannot create population coverage that the original sample lacks. It only reuses observed information.

In an interview

Use this order:

  1. Name the statistic and target population.
  2. Choose the independent resampling unit.
  3. Preserve model pairing.
  4. Describe the resample-and-recompute loop.
  5. Report the effect and interval.
  6. Discuss dependence, rare events, and sample coverage.

Choose replicate count from the required simulation accuracy, particularly for tail quantiles, after establishing a defensible sampling unit. Fixed-model example resampling does not by itself capture variation from retraining with different seeds or datasets.

Common mistakes

  • Resampling rows when users or documents are the independent units.
  • Breaking paired comparisons.
  • Calling the bootstrap distribution a posterior distribution.
  • Reporting an interval without the effect estimate.
  • Treating resampling as a fix for biased data.
  • Ignoring seed variation in model training.

Practice next

Apply paired resampling in hypothesis testing and confidence intervals, reproducible model comparison, and paper critique.