Put uncertainty to workLesson 18 of 30 · 7 min
Resample the experiment you actually ran
Bootstrap a mean difference while preserving its independent units.
A bootstrap approximates sampling variation by repeatedly sampling observed units with replacement, keeping the original sample size. With replacement means a unit can appear more than once in a resample. Recalculate the statistic for every resample.
Here each value is the B-minus-A difference from one independent paired run. Resampling differences preserves those pairs. SciPy offers several ways to turn the resampled means into an interval. Compare three methods on the same invented data. Each uses the same number of resamples and seed.
A bootstrap is not assumption-free. The observed units must represent the sampling process and target population; the sample needs enough information about the statistic. It cannot repair systematic selection bias, invent unseen tail events or turn correlated readings into independent experiments. The seed makes this particular simulation reproducible.
Original run differences (ms)
One resample, with replacement (ms)
If you have eight run differences, how many values belong in each bootstrap resample?
Write a prediction (optional)
Run the prepared example
This page puts the example in the Python editor. Select Run Python with the code unchanged.
Invented data
A saved draft is open. To run the published example, open Editor tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
What to compare
Find Mean B-minus-A (ms), 95% basic bootstrap interval (ms) and Bootstrap SE (ms). Use the reference illustration to see how the resample can contain eight entries while repeating run IDs.
Your result
Result tools
Each resample has eight entries, chosen from the eight original paired-run differences. An interval method uses the variation between those resampled means in a particular way.
Published example output
The site ran the original code to produce this reference. Build environment ↗
Mean B-minus-A (ms): -8.5 95% basic bootstrap interval (ms): -10.75 -6.25 Bootstrap SE (ms): 1.149
Each resample has eight entries, chosen from the eight original paired-run differences. An interval method uses the variation between those resampled means in a particular way.
Change and run again
In the Python editor, change bootstrap_method = "basic" to bootstrap_method = "percentile" and select Run Python. Repeat with "BCa". Compare the endpoints in the interval line for each named method and the Mean B-minus-A (ms). Which changes when the interval method changes? Return to the Python editor
What this example supports. Eight invented run differences are a small teaching sample. Bootstrap interval performance can be poor with small, unrepresentative or degenerate samples.
Try a fresh case
A dataset has 12 independently treated classrooms and 20 pupils per classroom. What must a suitable resampling plan preserve?
Hints for this question
- Find the treatment assignment unit.
- A resampling method should mimic the relevant sources of repeated-experiment variation.