TactivergeLite

Lite / Independent Engineering Research / Week 34

The bootstrap: uncertainty from your own data

Your metric is a median of skewed settling times. There is no neat formula for its standard error. Can the data tell you instead?

About 45 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

Real engineering metrics are often medians, percentiles, ratios or success rates with no tidy SE formula. The bootstrap gives you an honest interval for almost any statistic, using only computation you already know how to do.

Predict

When you resample 12 values with replacement, what typically happens?

  1. You get the same 12 values in a new order
  2. Some values appear more than once and some not at all
  3. You get 12 new measurements
  4. The mean is always unchanged
Guess first, then reveal

On average only about 63% of the original values appear in a resample; the rest are duplicates. That variation is what mimics sampling a new dataset.

Discover

Do one resample and read the ×counts. Then +1000. Compare the bootstrap SE of the mean with the formula s/√n. Switch to the median: what does the histogram look like now? Reset with a new seed: how stable is the interval?

What the interactive shows (text version)

The bootstrap resampler shows the original values, how many times each was drawn in the latest resample, and a histogram of resampled means or medians with the observed value and the 95% percentile interval marked. Buttons add 1, 100 or 1000 resamples.

You can also open the interactive on the full site when you have a faster connection.

Watch (optional)

Watch for: Follow the three steps (resample, compute, repeat) and notice what the video says the histogram is for.

Builds the bootstrap from scratch: resample your own data with replacement, recompute the statistic, and read its spread as uncertainty.

“Bootstrapping Main Ideas!!!” by StatQuest with Josh Starmer (opens YouTube; streaming video uses a lot of data)

The video is optional. Everything you need is in this lesson's text.

Understand

Resample, recompute, repeat

Treat your sample as a stand-in for the population. Draw n values from it with replacement, compute the statistic, and repeat a thousand times. The histogram of results shows how uncertain the statistic is. For a mean it agrees closely with s/√n; for medians and ratios it gives answers formulas cannot.

Comparing two methods

For a difference, resample each group separately (or resample paired seeds together), compute the difference each time, and take the 2.5% and 97.5% quantiles. Record the bootstrap seed: bootstrap intervals are random too, and should be reproducible.

Where it fails

The bootstrap assumes runs are independent and the sample represents the population. With very small n (under about 10), heavy tails or dependent runs (time series), the interval can be too narrow. It never corrects a biased sample or a confounded design.

Explain it another way

Intuitive

Your data are a small mirror of the world. Shaking the mirror and looking again shows how much the picture could change.

Technical

The nonparametric bootstrap estimates the sampling distribution of a statistic by Monte Carlo sampling from the empirical distribution.

Mathematical

SE_boot = √(Σ(θ̂_b − θ̄)²/(B − 1)); percentile CI = [q₀.₀₂₅(θ̂), q₀.₉₇₅(θ̂)].

Applied

Success rates of a gripper across 20 objects, median rover errors, 95th-percentile latency: all are natural bootstrap candidates.

Derivation: The bootstrap idea
  1. We want the sampling distribution of a statistic θ̂ (e.g. the median): how it would vary over new datasets of size n.

  2. We cannot draw new datasets from the true population F.

  3. Plug-in principle: replace F by the empirical distribution F̂ that puts mass 1/n on each observed value.

  4. Drawing n values from F̂ = resampling the data with replacement. Compute θ̂* on each resample.

  5. Repeat B times (B ≈ 1000–10,000). The spread of the θ̂* estimates the spread of θ̂: SE_boot = SD(θ̂*).

  6. Percentile interval: the 2.5% and 97.5% quantiles of θ̂*. Assumes the sample represents the population; it cannot fix bias or a tiny n.

Worked example 1

1000 bootstrap medians, sorted: the 25th is 2.18 s and the 975th is 2.52 s. Interval?

Percentile 95% CI ≈ [2.18, 2.52] s (the 2.5% and 97.5% quantiles of 1000 values sit near positions 25 and 975).

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

Practice 1. Why must bootstrap resampling be WITH replacement?

Practice 3. When is a bootstrap interval least trustworthy?

N

Practice 5. Should you record the bootstrap's random seed?

Apply it

Write a bootstrap function for your capstone's primary metric difference (with a recorded seed). Check it against the formula SE on a mean, then use it for your real metric.

Reflect

Which statistic in your project has no formula you trust, and what would a bootstrap interval tell you about it?

Write your answer on paper or in your own notes. Lite never stores what you write.

← Module check: forking paths and multiple comparisonsConfounders and alternative explanations →