#82Bootstrap Confidence Interval (Percentile)MediumStatisticsAsked atMeta · Google · Microsoft
Bootstrap Confidence Interval (Percentile)
Background
The percentile bootstrap is the universal confidence-interval tool: resample your data with replacement, recompute the statistic each time, take the quantiles of the bootstrap distribution. No parametric assumptions, no closed form needed.
Problem statement
Implement bootstrap_ci(data, stat_fn, n_bootstrap=2000, alpha=0.05, seed=0). For each bootstrap iteration, sample values from data with replacement, apply stat_fn, collect statistics, and return at the and percentiles.
Input
data- sequence of values.stat_fn- function taking a sequence -> scalar.n_bootstrap-int >= 100.alpha-floatin (default for a 95% CI).seed- RNG seed.
Output
(lo, hi)- tuple of plain Python floats.
Examples
Input: data=[1,2,3,4,5,6,7,8,9,10], stat_fn=mean
Output: CI roughly around mean ~ 5.5 with bounds about (4, 7)
Constraints
- Reproducible via
seed. - Return Python floats.
Notes
- Why percentile, not normal. No assumption that the statistic is normally distributed. Works for medians, quantiles, ratios, anything.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Mean CI on 1..10 (example)
- •Median CI on 1..20 (reference)
- •Mean CI at the 90% level (sample)