11/25
Part 3 of 5 · UnbiasedLearn

Check CUPED in 10,000 simulated tests

Check the claim the way you'd check any function: simulate it.

rng = np.random.default_rng(0)
raw, adj = [], []
for _ in range(10_000):
    # before the test
    x = rng.normal(10, 1, 1_000)
    y = 5 + 0.7 * (x - 10) + rng.normal(0, np.sqrt(0.51), 1_000)
    # random assignment
    t = rng.random(1_000) < 0.5
    # true effect: 0.1
    y = y + 0.1 * t
    # one call, both arms
    y_adj, _ = cuped(y, x)
    raw.append(y[t].mean() - y[~t].mean())
    adj.append(y_adj[t].mean() - y_adj[~t].mean())

print(f"average, raw and CUPED: {np.mean(raw):.2f} {np.mean(adj):.2f}")
print(f"variance, CUPED over raw: {np.var(adj) / np.var(raw):.2f}")
Predict

10,000 simulated tests at ρ = 0.7, true effect 0.10. Do the raw and CUPED estimates average the same?

Pick one to see what it prints.
Pick an answer above to see the rest