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.

Resample whole run differences

Original run differences (ms)

Run 1-8
Run 2-11
Run 3-5
Run 4-13
Run 5-9
Run 6-3
Run 7-12
Run 8-7

One resample, with replacement (ms)

Run 1-8
Run 1-8
Run 3-5
Run 4-13
Run 5-9
Run 8-7
Run 8-7
Run 2-11
One illustrated resample of the eight invented independent run differences. Sampling with replacement repeats run IDs and keeps the resample size at eight. Repeated copies are not new experiments. The Python below generates 4,000 resamples.

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

Editor tools
About Python ↗

Ctrl+Enter or ⌘+Enter runs the code.

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.

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?

Choose an answer

Hints for this question
  1. Find the treatment assignment unit.
  2. A resampling method should mimic the relevant sources of repeated-experiment variation.
Your notes