27/36
Part 5 of 6 · The worked exampleLearn

A worked example

Run every method on the six cities from the start.

Six cities of four users, with their residuals and city totals

CityUsersMeanResidualsEgE_g
A1, 4, 2, 53-5, -2, -4, -1-12
B8, 4, 7, 562, -2, 1, -10
C7, 10, 11, 891, 4, 5, 212
D5, 8, 4, 76-4, -1, -5, -2-12
E10, 7, 11, 891, -2, 2, -10
F14, 10, 13, 11125, 1, 4, 212

These are the six cities from the start: A, B and C are control, and D, E and F are treated. The residuals are each user's value minus their arm's mean, 6 for control and 9 for treated. EgE_g is their total. The estimate is 9−6=39 - 6 = 3.

All the lesson's functions agree:

y6 = np.array([1.0, 4, 2, 5, 8, 4, 7, 5, 7, 10, 11, 8,
               5, 8, 4, 7, 10, 7, 11, 8, 14, 10, 13, 11])
t6 = np.repeat([0.0, 1.0], 12)
c6 = np.repeat(np.arange(6), 4)
print(f"estimate    {diff_in_means(y6, t6):.3f}")
print(f"naive SE    {naive_se(y6, t6):.3f}")
print(f"clustered   {cluster_se(y6, t6, c6):.3f}")
print(f"city means  {city_means_test(y6, t6, c6)[1]:.3f}")
estimate    3.000
naive SE    1.243
clustered   2.240
city means  2.449
Predict

Six cities: the naive test gives p = 0.025. What do you expect from the clustered test?

Pick an answer above to see the rest