GARETH GRANTTECHNOLOGY · DATA · INNOVATION
Explore

25 / Inference

Bootstrap uncertainty from resampling

The bootstrap approximates how a statistic might vary across repeated samples by repeatedly resampling the observed data. It can support practical uncertainty analysis for statistics such as medians, but it inherits the limits of the original sample and the sampling design.

IntermediateLive exploration + Python

The business question

How uncertain is a median, cost estimate or other statistic when a simple textbook interval is awkward?

  • Estimate uncertainty around a typical invoice, turnaround median or contribution statistic.
  • Compare uncertainty for a statistic whose sampling formula is difficult to derive.
  • Explore how sample size and influential observations affect an operational conclusion.

How the method works

An ordinary nonparametric bootstrap treats the observed sample as an empirical approximation to the population. Draw the same number of observations with replacement, calculate the target statistic, and repeat. Some original observations appear several times in a resample and others do not appear. This recreates sampling variation around what the available data can describe.

The simplest percentile interval takes lower and upper quantiles of the bootstrap statistics. Other interval methods, including basic and bias-corrected accelerated intervals, address different aspects of bias and asymmetry. The example uses a labelled percentile method because its steps are easy to inspect; it should not be assumed to have reliable nominal coverage in every small or difficult dataset.

Ten thousand resamples are ten thousand rearrangements of the same observed information, not ten thousand new customer observations. Resampling reduces simulation noise when estimating the bootstrap distribution, but it cannot repair a biased sample or reveal unobserved rare losses. Time series need a dependence-aware design, paired comparisons need pairs kept together, and clustered customers need an appropriate cluster bootstrap.

The calculation

For b=1,…,B: sample n rows with replacement and calculate θ*_b; percentile interval = [quantile_0.025(θ*), quantile_0.975(θ*)]
Read the symbols
SymbolMeaning
nNumber of original observational units.
BNumber of bootstrap resamples.
θStatistic of interest, such as a median.
θ*_bThe statistic calculated from bootstrap resample b.

A worked business example

ILLUSTRATIVE SCENARIO

Illustrative service invoices used to describe a typical completed job rather than forecast total revenue.

Inputs

  • Eight invoice values: R180, R220, R250, R270, R300, R340, R420 and R700.
  • Target statistic: the sample median.
  • Use 10,000 ordinary resamples, percentile endpoints and NumPy random seed 42.

Work through the numbers

  1. Sort the original observations; the middle values are 270 and 300, giving median R285.
  2. Draw eight values with replacement for each resample and calculate its median.
  3. Repeat 10,000 times and sort or quantile the resulting medians.
  4. With the stated seed and implementation, the 2.5th and 97.5th percentiles are approximately R220 and R420.
The illustrative percentile bootstrap interval is R220–R420 around a sample median of R285.

The wide interval reflects limited information in eight invoices. It is not an interval covering 95% of individual future invoices, nor a guarantee of exact 95% coverage for the population median.

Explore the decision

Resample a sample mean. The live explorer has its own example inputs; it is separate from the worked calculation above.

Enable JavaScript to use this calculator. The worked example and executable Python remain available.

Apply it at work

  1. Choose the statistic and define the independent observational unit before resampling.
  2. Inspect the sample and ensure that its coverage, missingness and unusual cases are understood.
  3. Choose an appropriate resampling structure and interval method, fix a seed and check Monte Carlo stability.
  4. Report the estimate, interval, sample size, method and what additional data would improve the decision.

Check these assumptions

  • The observed data reasonably represent the population or process of interest.
  • The resampling design preserves relevant pairing, clustering or time dependence.
  • The statistic and sample contain enough information for the bootstrap approximation to be useful.
  • Any cleaning and selection rules are defensible and documented rather than chosen to tighten the interval.

Common mistakes and how to avoid them

  • Increasing resamples cannot compensate for biased observations or an unrepresentative business period.
  • Naively resampling individual rows from a dependent series can make the interval too narrow.
  • A discrete small-sample median may give unstable or degenerate intervals; compare methods and collect more observations.

How this can help the business

  • An owner can see whether a typical-price estimate is precise enough for a quoting policy or needs more data.
  • An analyst can communicate the uncertainty of a complex summary rather than presenting a single figure as settled.
A decision rule to adapt

Use bootstrap uncertainty as an input to a decision only when the sampling design and method are credible; widen the evidence base when the interval spans materially different actions.

When to use another approach

Use a suitable analytical interval when available, an order-statistic interval for a median, a block or cluster bootstrap for dependence, or a parametric model justified by the process.

Reproduce the worked example in Python

The code is self-contained for this example. Dependencies and run instructions are included with the downloadable notebook.

Show executable code and recorded output
import numpy as np
rng = np.random.default_rng(42)
invoices = np.array([180,220,250,270,300,340,420,700])
medians = []
for repeat in range(10000):
    sample = rng.choice(invoices, size=len(invoices), replace=True)
    medians.append(np.median(sample))
low, high = np.quantile(medians, [0.025, 0.975])
print("Sample median (R):", round(np.median(invoices), 2))
print("Percentile bootstrap 95% CI (R):", round(low, 2), round(high, 2))
print("Resamples:", len(medians))

Recorded output

Sample median (R): 285.0
Percentile bootstrap 95% CI (R): 220.0 420.0
Resamples: 10000
Download all worked examples

Sources and further reading

Concepts are linked to primary teaching or technical sources. The business examples are illustrative applications, not reported client results.