1-sample bootstrap: confidence intervals by resampling

Updated

The 1-sample bootstrap estimates how much a statistic would vary from sample to sample by resampling the one sample you have. It draws many new samples of the same size from your data, with replacement, computes the statistic on each, and uses the spread of those results as its sampling distribution. The percentile interval takes the middle 95% of the resampled values as a 95% confidence interval. It works for statistics that have no simple formula, such as a median, a percentile or a trimmed mean, and it does not assume a normal distribution.

When to use it

  • You want a confidence interval for a median, a percentile, a ratio or another statistic without a standard formula.
  • The data are skewed, such as repair times, cycle times or particle counts, and you doubt a normal-theory interval.
  • You want to check a formula-based interval: if the bootstrap and the formula agree, either can be reported.

For a mean from roughly normal data, the 1-sample t interval is simpler and exact. For a median, the 1-sample sign test gives an exact interval from order statistics. To compare two groups, use the 2-sample bootstrap.

How it works

With a sample x₁, …, xₙ and a statistic θ̂ (say, the median):

  1. Draw n values from the sample at random with replacement. Some values appear twice or more, some not at all.
  2. Compute the statistic on this resample, θ̂*.
  3. Repeat B times; B = 10,000 is a common choice.
  4. Sort the B values. The 2.5th and 97.5th percentiles are the 95% percentile interval:
95% CI = [ θ̂*(2.5%), θ̂*(97.5%) ] bootstrap SE = SD of the B values of θ̂*

The resampling is random, so the result depends a little on the random numbers. Fixing and reporting the seed of the random number generator makes the result reproducible; repeating the run with other seeds shows how much the interval moves.

The bootstrap assumes the sample represents the process: independent observations, collected the way the claim is meant. It cannot add information. With very small samples (fewer than about 15) or statistics driven by the extremes, such as the maximum, percentile intervals can be too narrow.

Example

A packaging line records how long each unplanned stop lasts. The maintenance team wants a typical repair time for its planning, with a confidence interval. The last 20 stops (minutes), in order:

8113819412813414
14361517458326106
Duration of 20 unplanned stops02468Frequency0204060Stop duration (min)
Duration of 20 unplanned stops

The data are right-skewed: median 12.5 minutes, mean 16.0 minutes, standard deviation 13.9 minutes, with one stop of 58 minutes. The team bootstraps the median with B = 10,000 resamples, using NumPy's default generator with seed 2026 (numpy.random.default_rng(2026)).

Bootstrap distribution of the median, 10,000 resamples01000200030004000Number of resamples4–66–88–1010–1212–1414–1616–1818–2020+
Bootstrap distribution of the median, 10,000 resamples
StatisticEstimateBootstrap SE95% percentile interval
Median12.5 min2.128.0 to 16.0 min
Mean16.0 min3.0310.7 to 22.5 min

Rerunning with seeds 7 and 99 gives the same median interval, 8.0 to 16.0 minutes, and mean intervals that differ only in the first decimal (10.7 to 22.5 and 10.7 to 22.6).

How to read the results

  • A typical stop lasts between 8 and 16 minutes. That is the 95% interval for the median, the figure the team should plan around for an ordinary stop.
  • The mean answers a different question. The mean, 16.0 minutes, is pulled up by the long stops. It matters for total downtime per shift; the median matters for a typical stop.
  • The interval is not symmetric. For the mean it reaches 6.5 minutes above the estimate and 5.3 below, because a resample that picks up the 58-minute stop several times pulls the mean up. The t interval, 9.5 to 22.5 minutes, is symmetric by construction.
  • The bootstrap agrees with the exact method. The order-statistic interval for the median, from the 6th to the 15th sorted value, is 8 to 17 minutes with 95.9% confidence, close to the bootstrap result.
  • The bar chart is lumpy because a median of 20 values can only take a few distinct values. That is normal for medians of small samples.

Common mistakes

  • Not reporting the seed and B. Without them, nobody can reproduce the interval.
  • Treating the bootstrap as a cure for small samples. It only reuses the data you have. Ten values give a rough interval however many resamples you draw.
  • Resampling dependent data as if independent. Consecutive readings from a drifting process are not independent; resampling them one by one understates the uncertainty.
  • Bootstrapping the maximum or minimum. The bootstrap works poorly for statistics set by one extreme value.
  • Using too few resamples. With B = 1,000, the ends of a 95% interval rest on about 25 values each; 10,000 is a safer default.

Frequently asked questions

How many bootstrap resamples do I need?

For a standard error, 1,000 is usually enough. For the ends of a 95% percentile interval, use 10,000 or more, then check that another seed gives nearly the same interval.

Why does the bootstrap resample with replacement?

Sampling with replacement mimics drawing new units from the process, using the sample as a stand-in for it. Without replacement, every resample would be the original sample in another order.

What is the percentile interval and are there better ones?

It takes the percentiles of the bootstrap distribution directly. Refinements such as the bias-corrected and accelerated (BCa) interval, described by Efron and Tibshirani in An Introduction to the Bootstrap, adjust for bias and skew and are more accurate in small samples.

Can I use the bootstrap for a hypothesis test?

Yes, indirectly: if the 95% interval excludes a value, a test of that value would reject at about the 5% level. For comparing groups, a randomization test is often the cleaner choice.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab