7/36
Part 1 of 6 · Two unitsLearn

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 @ beta

def 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.
Pick an answer above to see the rest