Week 10 · Bootstrap and permutation inference

Match the resampling operation to the question and unit of analysis.

← Week 9 · Subject contents · Week 11 →

Match the resampling operation to the question and unit of analysis.

Work through the problem

A bootstrap samples observations with replacement to approximate the sampling variation of an estimator. For waits [1, 2, 3, 4, 10], the median is 3. One resample [1, 1, 3, 10, 10] still has median 3. Resample intact users when each user contributes multiple related observations.

A permutation test reassigns labels according to the original randomized design under a sharp no-effect null. For outcomes [1, 2, 7, 8], there are six assignments of two observations to treatment. The largest absolute mean difference is 6, attained by two assignments, so the exact two-sided p-value is 2/6.

Run the Python lab

from itertools import combinations
import numpy as np
rng = np.random.default_rng(8)
sample = [1, 2, 3, 4, 10]
medians = np.median(rng.choice(sample, (10000, 5)), axis=1)
print("Bootstrap percentiles:", np.quantile(medians, [.025, .975]))
values = np.array([1, 2, 7, 8])
null = []
for group in combinations(range(4), 2):
    mask = np.isin(np.arange(4), group)
    null.append(abs(values[mask].mean() - values[~mask].mean()))
p = np.mean(np.array(null) >= 6)
print("Permutation p:", round(p, 3))
assert np.isclose(p, 1/3)

Output from the lab

Bootstrap percentiles: [ 1. 10.]
Permutation p: 0.333

Practice

  1. Can you permute individual visits when treatment was assigned by user?

Check your reasoning

  1. Preserve the assignment unit and permute users with all their visits.

← Week 9 · Subject contents · Week 11 →

Further reading · MIT 18.650 · Statistics for Applications