Sampling and Estimation
Bootstrap Mean (Small)
Estimate the sampling distribution of the mean by averaging B given
resamples. Each resample is a fixed literal list (values drawn with
replacement from the original), making results deterministic without relying
on RNG agreement between naive and library. Nested loops: outer over B=3
resamples, inner computes each resample mean; a final loop averages the
resample means. Library: np.mean per resample then np.mean of those
means, on identical data.
By hand
With the library
np.mean is applied per resample via a list comprehension, then np.mean
averages those means. Same resamples as naive; the resample means are shown
for comparison.
original = [2, 4, 6]
resamples = [[2, 2, 4], [4, 6, 6], [6, 4, 2]]
B = len(resamples)
means = []
for rs in resamples:
total = 0.0
for v in rs:
total = total + v
means.append(total / len(rs))
boot_mean = 0.0
for m in means:
boot_mean = boot_mean + m
boot_mean = boot_mean / B
print('RESULT:', round(boot_mean, 4))
import numpy as np
from dalib.display import set_display
set_display()
original = [2, 4, 6]
resamples = [[2, 2, 4], [4, 6, 6], [6, 4, 2]]
B = len(resamples)
resample_means = [float(np.mean(rs)) for rs in resamples]
boot_mean = float(np.mean(resample_means))
print('B:', B)
print('resample means:', [round(m, 4) for m in resample_means])
print('RESULT:', round(boot_mean, 4))
B: 3
resample means: [2.6667, 5.3333, 4.0]
RESULT: 4.0
Honesty
This lesson shows the computation exactly, on a tiny pinned sample. The arithmetic is correct and reproducible, but with a sample this small the result is not a valid statistical finding — it demonstrates the mechanism, not evidence. Real inference needs an adequate sample size and assumption checks (e.g. B≥1000 resamples and an adequate original n); the bootstrap estimate here should be read as "how the resampling is computed," not as a conclusion about a population.
Implementation notes
- RNG parity rule: resamples are given as fixed literals rather than
generated at runtime. Python's
randomand numpy's RNG produce different sequences even with the same integer seed, so live draws would break parity. - In practice B is typically 1000–10000. Here B=3 is enough to show the structure without exceeding the 60-event trace budget.
- Bootstrap does not require knowing the population distribution. The resample variability estimates the sampling variability directly from the data.
- Cross-reference:
seeded-sample-mean(this chapter) for the mean computation each resample iteration applies;standard-error(this chapter) for the analytic SE that bootstrap approximates empirically.