Bootstrap a median delivery-time interval
In this article (6 sections)
Bootstrap a median by repeatedly resampling the observed units with replacement, calculating the median of each resample and applying a stated interval method. The result estimates uncertainty under assumptions about how the observed sample represents the target population.
Resampling cannot create information about unobserved customer groups or automatically correct dependent observations. A reproducible interval still needs an appropriate sampling design.
Inspect the small delivery sample
The analyst statistics lab contains eight synthetic durations in minutes: 10, 20, 20, 25, 30, 40, 100 and 240. The observed median is 27.5 minutes and the mean is 60.625 minutes.
The long tail is deliberate. The exercise estimates uncertainty about the population median, not the average duration or the next individual delivery.
import numpy as np
from scipy import stats
from build_and_verify import DELIVERIES
result = stats.bootstrap((DELIVERIES,), np.median, method='percentile',
confidence_level=.95, n_resamples=10000,
rng=np.random.default_rng(151))
low, high = result.confidence_interval
assert np.median(DELIVERIES) == 27.5
assert np.allclose([low, high], [20, 100])
assert np.isfinite(result.bootstrap_distribution).all()
assert len(result.bootstrap_distribution) == 10000
print({'sample_n': len(DELIVERIES), 'median_minutes': 27.5,
'percentile95_minutes': [float(low), float(high)],
'bootstrap_standard_error': float(result.standard_error)})The recorded percentile interval is 20 to 100 minutes. It is wide because the tiny sample permits substantial variation in resampled medians. The SciPy bootstrap reference documents interval methods, resampling and random-generator control.
Explain the resampling unit
This example assumes each duration is an independent draw from the relevant delivery population. If several deliveries share one route, driver or disruption, resampling individual rows may understate dependence.
Choose a cluster or time-block approach when justified by the design, and explain what the resampled unit represents. Changing the resampling unit changes the uncertainty calculation.
For paired before/after delivery data, preserve pairs during resampling. Independently resampling the two columns would destroy the observed relationship.
Distinguish interval methods
The percentile method uses quantiles of the bootstrap statistic distribution. Other methods, including basic and BCa intervals, make different adjustments and can behave differently with small, discrete or degenerate samples.
The article selects percentile explicitly to keep the teaching calculation transparent. It does not claim that this method has accurate 95% coverage for every eight-observation skewed population.
Increasing the number of resamples reduces simulation noise in the bootstrap calculation. It does not increase the original sample size from eight to ten thousand independent deliveries.
Inspect instability instead of hiding it
Try several seeds and larger resample counts to assess Monte Carlo variation. More importantly, inspect how the result changes when individual observations are removed or when plausible dependence is considered.
With a very small sample, the empirical distribution has limited support. Repeated medians and coarse endpoints are expected. Reporting many decimal places would imply more precision than the evidence supports.
Communicate the estimand and limitation
A useful statement is that the observed median is 27.5 minutes, with a percentile bootstrap interval of 20–100 minutes under independent resampling of this synthetic sample. It is not a promise that 95% of deliveries arrive within that range.
If the decision concerns service-level compliance, define a tail probability or percentile relevant to that decision and obtain enough representative data to estimate it. A median interval answers a different question.
Exercise: run 1,000 and 50,000 resamples with documented seeds. Compare endpoint stability, then explain why neither run repairs a source that omitted the slowest delivery routes.
NeuraPath's Data Analytics with Generative AI course connects resampling code with careful uncertainty interpretation. A useful bootstrap analysis makes the resampling unit, method and evidence limits explicit.
Continue learning
This article is part of the Statistics for analytical decisions sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Sampling bias in a customer satisfaction survey.
- Continue with Effect size versus statistical significance for analysts.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Data Analytics with Generative AI programme — 3–4 months. The full analyst stack — Excel, SQL, Power BI and Python pipelines — then a generative-AI layer you can prove is right.
Explore Data Analytics with Generative AI