Compare two eval runs with Welch's t-test statistic
Two prompt versions score differently on an eval. Welch's t-test asks whether the gap is bigger than the noise, without assuming equal variances.
Write welch_t(a, b) for two 1D samples with at least 2 values each. Use sample variances with ddof=1. Return (t, df) where t = (mean_a - mean_b) / sqrt(va / na + vb / nb) and df is the Welch-Satterthwaite degrees of freedom: (va/na + vb/nb)^2 / ((va/na)^2 / (na - 1) + (vb/nb)^2 / (nb - 1)).
def welch_t(a, b)Example
a = [1, 2, 3], b = [4, 5, 6] gives t = -3.674 and df = 4.
Understand the idea
Two prompt versions get different average eval scores. Is the gap real or just noise? Welch's t statistic divides the difference in means by its standard error, and does not assume the two samples have equal variance. The degrees of freedom formula then tells you which t distribution to compare against. Worked example: a = [2, 4, 6], b = [1, 1, 1, 4]. Mean a = 4, sample variance (n - 1 divisor) = 8 / 2 = 4. Mean b = 1.75, variance = 6.75 / 3 = 2.25. va / na = 1.3333 and vb / nb = 0.5625, sum 1.8958. t = (4 - 1.75) / sqrt(1.8958) = 2.25 / 1.3769 = 1.634. df = 1.8958^2 / (1.3333^2 / 2 + 0.5625^2 / 3) = 3.594 / 0.9944 = 3.61. Rule: t = (mean_a - mean_b) / sqrt(va / na + vb / nb) with ddof = 1 variances; df = (va / na + vb / nb)^2 / ((va / na)^2 / (na - 1) + (vb / nb)^2 / (nb - 1)). Using ddof = 0 shrinks variances and inflates t. Used to compare A/B eval runs and prompt variants.