Practice in Lab: Bootstrap independent groups rather than correlated rows →
Bootstrap independent groups rather than correlated rows
Repeated measurements from one customer are correlated. Resampling individual rows can make a large customer's repeated events look like independent evidence. This exercise first averages each independent group, then bootstraps those means. Its estimand gives customers equal weight; it is deliberately different from an event-weighted business metric. Group identities are sorted before seeded sampling so input row order does not change the result. Independence remains a domain assumption, and a narrow interval from two synthetic customers is not evidence for a rollout.
from collections import defaultdict
buckets = defaultdict(list)
for group, delta in [('a',1),('a',3),('b',0)]:
buckets[group].append(delta)
means = [sum(v)/len(v) for v in buckets.values()]
print(sum(means)/len(means))Review the design
Defend the independent unit, weighting and interval method. A bootstrap does not repair biased logging, nonstationarity or unrepresentative evaluation cases.
Your task
Compute each string group's mean paired difference; give groups equal weight. With random.Random(seed), resample that list of means with replacement, drawing the same number of groups per repetition. Return estimate, low, high and groups. The 95% percentile bounds linearly interpolate sorted bootstrap estimates at positions (R-1).025 and (R-1).975. Require at least two groups, aligned nonempty finite deltas and integer repetitions>=2.
The explanation opens here once every check passes.