The naive standard error counts every user as independent evidence
Now the standard error the usual formula gives.
def fit(y, treat): X = np.column_stack([np.ones(len(y)), treat]) XtX_inv = np.linalg.inv(X.T @ X) beta = XtX_inv @ X.T @ y return X, XtX_inv, beta, y - X @ betadef diff_in_means(y, treat): return fit(y, treat)[2][1]def naive_se(y, treat): X, XtX_inv, _, resid = fit(y, treat) n, k = X.shape s2 = resid @ resid / (n - k) return np.sqrt(s2 * XtX_inv[1, 1])b, se = diff_in_means(y, treat), naive_se(y, treat)print(f"estimate {b:.3f} naive SE {se:.3f}")print(f"naive 95% interval: {b - 1.96 * se:.2f} to {b + 1.96 * se:.2f}")
Predict
The practice data was built with a true effect of 0.5. Does the naive 95% interval cover it?
Pick one to see what it prints.
X is the design matrix: one row per user, holding a 1 for the intercept and the user's treatment flag. beta solves the normal equations, β^=(X⊤X)−1X⊤y, which give the least-squares fit. beta[0] is the control mean, and beta[1] the difference in means. fit also returns the residuals, y - X @ beta.
naive_se is this formula:
SEnaive=s2(NT1+NC1),s2=N−K∑ie^i2
In words: e^i is user i's residual, its value minus its arm's mean. NT and NC count the users in each arm. K=2 counts the fitted coefficients, the intercept and the treatment effect. In the code, the treatment's diagonal entry of (X⊤X)−1, XtX_inv[1, 1], is exactly 1/NT+1/NC.
The formula assumes N independent draws. So it counts a city's 50 copies of bg as 50 pieces of evidence.