17/36
Part 3 of 6 · The clustered SELearn

On a design with no true effect, count how often each test finds one

Check the clustered standard error the way you'd check any function: simulate it.

rng = np.random.default_rng(0)
G, m = 40, 50
city = np.repeat(np.arange(G), m)
half = np.r_[np.ones(G // 2), np.zeros(G // 2)]
naive_hits = clustered_hits = 0
for _ in range(2000):
    t = rng.permutation(half)[city]
    yy = rng.normal(0, 1.5, G)[city] + rng.normal(0, 2, G * m)
    b = diff_in_means(yy, t)
    naive_hits += abs(b / naive_se(yy, t)) > 1.96
    clustered_hits += abs(b / cluster_se(yy, t, city)) > 2.023
print(f"naive test:     {naive_hits / 2000:.2%} significant")
print(f"clustered test: {clustered_hits / 2000:.2%} significant")
Predict

No true effect at all, 40 cities of 50 users. How often does the naive 5% test call the result significant?

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