Welch's t-Test for Two Means

medium
Unit 12 · Statistics IV0/2 to milestone

Did the new checkout flow change average order value? For continuous metrics, compare means with Welch's t-test, which, unlike Student's t-test, doesn't assume the two groups have equal variance.

With sample means aˉ,bˉ\bar a, \bar b, sample variances sa2,sb2s_a^2, s_b^2 (with ddof=1) and sizes na,nbn_a, n_b:

t=aˉ−bˉsa2/na+sb2/nb,ν=(sa2/na+sb2/nb)2(sa2/na)2na−1+(sb2/nb)2nb−1t = \frac{\bar a - \bar b}{\sqrt{s_a^2/n_a + s_b^2/n_b}}, \qquad \nu = \frac{\left(s_a^2/n_a + s_b^2/n_b\right)^2}{\frac{(s_a^2/n_a)^2}{n_a - 1} + \frac{(s_b^2/n_b)^2}{n_b - 1}}

Implement welch_t(a, b) returning (t, df). Raise ValueError if either group has fewer than 2 values. Then implement mean_diff_ci(a, b, z=1.96), an approximate 95% confidence interval for aˉ−bˉ\bar a - \bar b using the same standard error: (low, high).

#statistics#hypothesis-testing#experimentation2 visible + 3 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Welch's t-Test for Two Means · TechGradify