Algorithm Search⌘K

Algorithmcore

Welch's t-test

Also called unequal variances t-test, Welch-Satterthwaite approximation.

Compares two normal means without assuming equal variances, using separate variance estimates and Welch-Satterthwaite degrees of freedom. Approximate, not exact. O(m + n).

Time
Θ(m + n) worst · best
Space
Θ(1) extra
Where
m = the size of the first sample; n = the size of the second sample
Properties
deterministicnot exactofflineiterative
Origin
Bernard Lewis Welch, Franklin E. Satterthwaite, 1947

Welch's t-test is a statistical hypothesis test for the difference of the means of two independent normal samples whose variances may differ. It divides the difference of the sample means by the square root of SX2/m+SY2/nS_X^2/m + S_Y^2/n, where each sample variance has its own divisor m−1m - 1 or n−1n - 1, and it refers the result to a t distribution with the Welch-Satterthwaite degrees of freedom, a real number between min⁡(m,n)−1\min(m, n) - 1 and m+n−2m + n - 2. The test is approximate: its size is not exactly α\alpha, but it stays close to α\alpha in cases where the pooled Student t-test fails badly.

In plain words

You compare the averages of two separate groups, and the two groups may scatter by different amounts. The pooled t-test assumes equal scatter and mixes the two scatters into one. When the small group is the noisy one, that mixed value is too small, the test sees differences that are only noise, and it cries "significant" far too often. Welch's test keeps the two scatters apart and adds up the uncertainty of each average separately. The cost is that the exact law of the resulting count is unknown. Welch and Satterthwaite matched it to the closest t law, with a number of degrees of freedom computed from the data. The match is not perfect, but it is good in most practical cases.

The problem

Model and hypotheses. X1,…,XmX_1, \dots, X_m iid N(μX,σX2)N(\mu_X, \sigma_X^2) and Y1,…,YnY_1, \dots, Y_n iid N(μY,σY2)N(\mu_Y, \sigma_Y^2), the two samples independent, m,n≥2m, n \ge 2, with μX,μY,σX,σY\mu_X, \mu_Y, \sigma_X, \sigma_Y unknown and σX≠σY\sigma_X \ne \sigma_Y allowed. H0:μX−μY=δ0H_0: \mu_X - \mu_Y = \delta_0 against H1:μX−μY≠δ0H_1: \mu_X - \mu_Y \ne \delta_0 (two-sided), >δ0> \delta_0 ("greater") or <δ0< \delta_0 ("less"). The two variances are nuisance parameters. This is the Behrens-Fisher problem.

Statistic. With the means Xˉ,Yˉ\bar X, \bar Y and the sample variances SX2,SY2S_X^2, S_Y^2 (divisors m−1m - 1 and n−1n - 1),

T=Xˉ−Yˉ−δ0SX2/m+SY2/n,ν^=(SX2/m+SY2/n)2(SX2/m)2m−1+(SY2/n)2n−1.T = \frac{\bar X - \bar Y - \delta_0}{\sqrt{S_X^2/m + S_Y^2/n}}, \qquad \hat\nu = \frac{\big(S_X^2/m + S_Y^2/n\big)^2}{\dfrac{(S_X^2/m)^2}{m - 1} + \dfrac{(S_Y^2/n)^2}{n - 1}} .

Null distribution. Approximate: under H0H_0, TT is treated as tν^t_{\hat\nu}. The numerator is exactly normal, but the denominator is the root of a weighted sum of two independent chi-square variables, which is not a scaled chi-square, and the exact law of TT depends on σX2/σY2\sigma_X^2/\sigma_Y^2. The degrees of freedom ν^\hat\nu match the first two moments of the denominator to those of a scaled chi-square (the Welch-Satterthwaite approximation, below). The law of TT tends to tm−1t_{m-1} exactly when σY→0\sigma_Y \to 0, and TT tends to N(0,1)N(0, 1) as m,n→∞m, n \to \infty for any populations with finite variances, by the central limit theorem and Slutsky's theorem.

Rejection rule and size. Reject when ∣T∣≥t(ν^,1−α/2)|T| \ge t_{(\hat\nu, 1-\alpha/2)} (two-sided), T≥t(ν^,1−α)T \ge t_{(\hat\nu, 1-\alpha)} ("greater") or T≤−t(ν^,1−α)T \le -t_{(\hat\nu, 1-\alpha)} ("less"), where t(ν,p)t_{(\nu, p)} is the lower pp quantile of tνt_\nu for real ν>0\nu > 0. The size is close to α\alpha but not equal to it; the table in the Example measures it.

p-value. With Fˉν(t)=P(Tν>t)\bar F_\nu(t) = P(T_\nu > t): p=Fˉν^(t)p = \bar F_{\hat\nu}(t) ("greater"), Fˉν^(−t)\bar F_{\hat\nu}(-t) ("less") and 2Fˉν^(∣t∣)2\bar F_{\hat\nu}(|t|) (two-sided). It is an approximate p-value: under H0H_0 it is only approximately uniform.

Sensitivity and power. The test reacts to a shift μX−μY−δ0\mu_X - \mu_Y - \delta_0 relative to σX2/m+σY2/n\sqrt{\sigma_X^2/m + \sigma_Y^2/n}. Its power is close to that of the pooled test when the variances are equal and the sizes are similar, and lower when one sample is very small, because ν^\hat\nu is then small.

The algorithm

  1. WELCH-T-TEST(x[1..m], y[1..n], δ₀, alternative) ▷ m, n ≥ 2
  2. 1(x̄, S²_X) ← the mean of x and its variance with divisor m − 1, by two passes
  3. 2(ȳ, S²_Y) ← the mean of y and its variance with divisor n − 1, by two passes
  4. 3a ← S²_X / m; b ← S²_Y / n
  5. 4t ← (x̄ − ȳ − δ₀) / √(a + b)
  6. 5ν ← (a + b)² / (a² / (m − 1) + b² / (n − 1))
  7. 6return (t, ν, T-P-VALUE(t, ν, alternative))

T-P-VALUE is the procedure of Student's t-test: the upper tail of tνt_\nu, doubled for the two-sided test. It works for real ν\nu, because the shared helper evaluates Fˉν(t)=12Iν/(ν+t2)(ν/2,1/2)\bar F_\nu(t) = \tfrac12 I_{\nu/(\nu + t^2)}(\nu/2, 1/2) by the continued fraction of the regularized incomplete beta function, which does not need an integer ν\nu. If both samples are constant, a+b=0a + b = 0 and the code raises an error. If only one is constant, ν^\hat\nu is the degrees of freedom of the other sample and the test is the one-sample t-test of that sample against the constant.

Example

Two independent groups: x=13,19,10,22,16x = 13, 19, 10, 22, 16 (m=5m = 5) and y=11,12,10,13,11,12,11,12y = 11, 12, 10, 13, 11, 12, 11, 12 (n=8n = 8). Test H0:μX=μYH_0: \mu_X = \mu_Y against H1:μX≠μYH_1: \mu_X \ne \mu_Y at α=0.05\alpha = 0.05.

line value
L1: xˉ\bar x, ∑(xi−xˉ)2\sum (x_i - \bar x)^2, SX2=90/4S_X^2 = 90/4 1616, 9090, 22.522.5
L2: yˉ\bar y, ∑(yj−yˉ)2\sum (y_j - \bar y)^2, SY2=6/7S_Y^2 = 6/7 11.511.5, 66, 0.8571430.857143
L3: a=22.5/5a = 22.5/5, b=0.857143/8b = 0.857143/8 4.54.5, 0.1071430.107143
L4: a+b\sqrt{a + b} 2.1464262.146426
L4: t=4.5/2.146426t = 4.5/2.146426 2.09652.0965
L5: ν=4.6071432/(5.0625+0.001640)\nu = 4.607143^2/(5.0625 + 0.001640) 4.19144.1914
L6: p=2Fˉ4.1914(2.0965)p = 2\bar F_{4.1914}(2.0965) 0.10090.1009

The critical value is t(4.1914,0.975)=2.7272t_{(4.1914, 0.975)} = 2.7272, and 2.0965<2.72722.0965 < 2.7272, so the test does not reject. Almost all the uncertainty comes from the small noisy group, so ν^\hat\nu is close to its m−1=4m - 1 = 4. The dual 95% interval for μX−μY\mu_X - \mu_Y is 4.5±2.7272×2.146426=[−1.354,10.354]4.5 \pm 2.7272 \times 2.146426 = [-1.354, 10.354].

The pooled test on the same data uses Sp2=96/11=8.7273S_p^2 = 96/11 = 8.7273 (divisor m+n−2=11m + n - 2 = 11), the standard error 8.7273(1/5+1/8)=1.6842\sqrt{8.7273(1/5 + 1/8)} = 1.6842, t=2.6720t = 2.6720 with 11 degrees of freedom and p=0.0217p = 0.0217, and rejects. The quiet group of 8 dominates Sp2S_p^2 and makes the standard error too small; the table below shows that the pooled test rejects a true null far too often in exactly this situation.

Size under the model. Monte Carlo with r=20000r = 20000 replications at level 0.05, two-sided, normal data with equal means, seed 11, the same simulated data for both tests (standard error of an estimated size near 0.05: 0.0015):

mm, σX\sigma_X nn, σY\sigma_Y Welch size pooled size
5, 3 25, 1 0.0530 0.2998
5, 1 25, 3 0.0485 0.0012
5, 1 25, 1 0.0577 0.0505
3, 1 3, 1 0.0354 0.0508
3, 3 3, 1 0.0499 0.0734
2, 1 20, 1 0.1191 0.0475
2, 5 20, 1 0.0895 0.5489
10, 2 10, 1 0.0490 0.0529
4, 1 4, 10 0.0511 0.0855

Where the variances differ, the Welch size stays within 0.004 of 0.05 in every row with both sizes at least 3, while the pooled size ranges from 0.001 to 0.55. Where the variances are equal, the pooled test is exact and Welch is off: slightly with m=5m = 5, conservative with m=n=3m = n = 3, and badly with m=2m = 2, where ν^\hat\nu can be as low as 1 and its randomness matters most.

Correctness

Within each sample, the mean and the sample variance are independent (Helmert's transformation), so the numerator of TT is exactly normal and independent of the denominator. The denominator squared, A+BA + B with A=SX2/mA = S_X^2/m and B=SY2/nB = S_Y^2/n, has mean θ=σX2/m+σY2/n\theta = \sigma_X^2/m + \sigma_Y^2/n and variance 2(σX2/m)2/(m−1)+2(σY2/n)2/(n−1)2(\sigma_X^2/m)^2/(m - 1) + 2(\sigma_Y^2/n)^2/(n - 1). A scaled chi-square θχν2/ν\theta\chi^2_\nu/\nu with the same two moments has ν=2θ2/Var⁡(A+B)\nu = 2\theta^2/\operatorname{Var}(A + B), and replacing the unknown variances by their estimates gives ν^\hat\nu. Cauchy-Schwarz gives min⁡(m,n)−1≤ν^≤m+n−2\min(m, n) - 1 \le \hat\nu \le m + n - 2, with the top value exactly when A/(m−1)=B/(n−1)A/(m - 1) = B/(n - 1). With m=nm = n, TT equals the pooled statistic. The size tends to α\alpha when one variance tends to 0 (the test becomes the exact one-sample t-test of the other sample) and when m,n→∞m, n \to \infty. Nothing more is proved; between those limits the size is measured. The proofs are in the correctness proof below.

Proof: The Welch statistic, the Welch-Satterthwaite degrees of freedom, their bounds and the limits where the size is exactfull

We prove what is true of Welch's test and say plainly what is not. The test is approximate: we derive the degrees of freedom by moment matching, prove their bounds, prove that equal sample sizes give the pooled statistic, and prove that the size tends to α\alpha in two limits. We do not prove that the size equals α\alpha, because it does not. Throughout, X1,…,XmX_1, \dots, X_m are iid N(μX,σX2)N(\mu_X, \sigma_X^2) and Y1,…,YnY_1, \dots, Y_n are iid N(μY,σY2)N(\mu_Y, \sigma_Y^2), independent of each other, with m,n≥2m, n \ge 2, and σX,σY>0\sigma_X, \sigma_Y > 0 are unknown and may differ. SX2S_X^2 and SY2S_Y^2 are the sample variances with divisors m−1m - 1 and n−1n - 1. Write

A=SX2/m,B=SY2/n,α0=σX2/m,β0=σY2/n,θ=α0+β0=Var⁡(Xˉ−Yˉ),A = S_X^2/m, \quad B = S_Y^2/n, \quad \alpha_0 = \sigma_X^2/m, \quad \beta_0 = \sigma_Y^2/n, \quad \theta = \alpha_0 + \beta_0 = \operatorname{Var}(\bar X - \bar Y),

T=(Xˉ−Yˉ−δ0)/A+BT = (\bar X - \bar Y - \delta_0)/\sqrt{A + B} and ν(a,b)=(a+b)2/(a2/(m−1)+b2/(n−1))\nu(a, b) = (a + b)^2/\big(a^2/(m - 1) + b^2/(n - 1)\big). The code returns TT, ν^=ν(A,B)\hat\nu = \nu(A, B) and the tν^t_{\hat\nu} tail of TT.

Lemma 1 (the parts are independent). Z=(Xˉ−Yˉ−(μX−μY))/θ∼N(0,1)Z = (\bar X - \bar Y - (\mu_X - \mu_Y))/\sqrt\theta \sim N(0, 1), (m−1)SX2/σX2∼χm−12(m - 1)S_X^2/\sigma_X^2 \sim \chi^2_{m-1}, (n−1)SY2/σY2∼χn−12(n - 1)S_Y^2/\sigma_Y^2 \sim \chi^2_{n-1}, and the three are independent.

Proof. Within one normal sample, the mean and the sample variance are independent, the mean is N(μ,σ2/size)N(\mu, \sigma^2/\text{size}), and (size −1- 1) times the sample variance over σ2\sigma^2 is chi-square with size −1- 1 degrees of freedom. This is Helmert's transformation, Lemma 1 of the correctness proof of Student's t-test. The two samples are independent, so Xˉ,SX2,Yˉ,SY2\bar X, S_X^2, \bar Y, S_Y^2 are four independent variables. Xˉ−Yˉ\bar X - \bar Y is normal with mean μX−μY\mu_X - \mu_Y and variance α0+β0=θ\alpha_0 + \beta_0 = \theta. □\square

So under H0:μX−μY=δ0H_0: \mu_X - \mu_Y = \delta_0, T=Z/(A+B)/θT = Z\big/\sqrt{(A + B)/\theta} with Z∼N(0,1)Z \sim N(0, 1) independent of A+BA + B. If (A+B)/θ(A + B)/\theta were χν2/ν\chi^2_\nu/\nu for some ν\nu, TT would be tνt_\nu exactly. It is not: A+B=α0V1/(m−1)+β0V2/(n−1)A + B = \alpha_0 V_1/(m - 1) + \beta_0 V_2/(n - 1) with independent V1∼χm−12V_1 \sim \chi^2_{m-1} and V2∼χn−12V_2 \sim \chi^2_{n-1}, a weighted sum of two chi-square variables, whose law depends on the ratio α0/β0\alpha_0/\beta_0.

Lemma 2 (the first two moments). E[A+B]=θE[A + B] = \theta and Var⁡(A+B)=2α02/(m−1)+2β02/(n−1)\operatorname{Var}(A + B) = 2\alpha_0^2/(m - 1) + 2\beta_0^2/(n - 1).

Proof. A χk2\chi^2_k variable has mean kk and variance 2k2k (it is a sum of kk independent squares of standard normals, and E[Z2]=1E[Z^2] = 1, E[Z4]=3E[Z^4] = 3). So A=α0V1/(m−1)A = \alpha_0 V_1/(m - 1) has mean α0\alpha_0 and variance α02⋅2(m−1)/(m−1)2=2α02/(m−1)\alpha_0^2 \cdot 2(m - 1)/(m - 1)^2 = 2\alpha_0^2/(m - 1), and the same for BB. AA and BB are independent, so the variances add. □\square

Lemma 3 (Satterthwaite's moment matching). The scaled chi-square variable c χν2/νc\,\chi^2_\nu/\nu with the same mean and variance as A+BA + B has c=θc = \theta and ν=ν(α0,β0)\nu = \nu(\alpha_0, \beta_0).

Proof. c χν2/νc\,\chi^2_\nu/\nu has mean cc and variance 2c2/ν2c^2/\nu. Matching the mean gives c=θc = \theta. Matching the variance gives 2θ2/ν=2α02/(m−1)+2β02/(n−1)2\theta^2/\nu = 2\alpha_0^2/(m - 1) + 2\beta_0^2/(n - 1) by Lemma 2, so ν=(α0+β0)2/(α02/(m−1)+β02/(n−1))=ν(α0,β0)\nu = (\alpha_0 + \beta_0)^2/\big(\alpha_0^2/(m - 1) + \beta_0^2/(n - 1)\big) = \nu(\alpha_0, \beta_0). □\square

The unknown α0,β0\alpha_0, \beta_0 are replaced by their unbiased estimates A,BA, B, which gives ν^=ν(A,B)\hat\nu = \nu(A, B), the value of welch_df. Both steps are approximations: the law of A+BA + B is not a scaled chi-square, and ν^\hat\nu is random. Lemma 3 explains the formula; it does not give an exact null law.

Lemma 4 (bounds on ν\nu). For a,b≥0a, b \ge 0 with a+b>0a + b > 0, min⁡(m,n)−1≤ν(a,b)≤m+n−2\min(m, n) - 1 \le \nu(a, b) \le m + n - 2. The upper bound is an equality exactly when a/(m−1)=b/(n−1)a/(m - 1) = b/(n - 1), and the lower bound is approached when the variance part of the smaller sample dominates.

Proof. Let p=m−1p = m - 1 and q=n−1q = n - 1. Upper bound: by the Cauchy-Schwarz inequality for the vectors (a/p,b/q)(a/\sqrt p, b/\sqrt q) and (p,q)(\sqrt p, \sqrt q),

(a+b)2=(app+bqq)2≤(a2p+b2q)(p+q),(a + b)^2 = \Big(\frac{a}{\sqrt p}\sqrt p + \frac{b}{\sqrt q}\sqrt q\Big)^2 \le \Big(\frac{a^2}{p} + \frac{b^2}{q}\Big)(p + q),

so ν≤p+q=m+n−2\nu \le p + q = m + n - 2, with equality exactly when the vectors are proportional, that is a/p=b/qa/p = b/q. Lower bound: let k=min⁡(p,q)k = \min(p, q). Then a2/p+b2/q≤(a2+b2)/k≤(a+b)2/ka^2/p + b^2/q \le (a^2 + b^2)/k \le (a + b)^2/k, the last step because 2ab≥02ab \ge 0, so ν≥k\nu \ge k. If b=0b = 0 then ν=p\nu = p, and if a=0a = 0 then ν=q\nu = q; so ν\nu moves from the degrees of freedom of the sample that carries all the variance to p+qp + q when the two parts are balanced. □\square

Lemma 5 (equal sample sizes). If m=nm = n, the Welch statistic equals the pooled statistic Tp=(Xˉ−Yˉ−δ0)/(Sp2/n)T_p = (\bar X - \bar Y - \delta_0)/(S_p\sqrt{2/n}), and ν^≤2n−2\hat\nu \le 2n - 2 with equality exactly when SX2=SY2S_X^2 = S_Y^2.

Proof. With m=nm = n, Sp2=((n−1)SX2+(n−1)SY2)/(2n−2)=(SX2+SY2)/2S_p^2 = \big((n - 1)S_X^2 + (n - 1)S_Y^2\big)/(2n - 2) = (S_X^2 + S_Y^2)/2, so Sp2⋅2/n=(SX2+SY2)/n=A+BS_p^2 \cdot 2/n = (S_X^2 + S_Y^2)/n = A + B, and the denominators agree. The claim on ν^\hat\nu is Lemma 4 with p=qp = q: equality iff A=BA = B, that is SX2=SY2S_X^2 = S_Y^2. □\square

So with equal sizes the two tests differ only in the degrees of freedom: the pooled test uses 2n−22n - 2 and Welch's test uses a data-dependent value at most 2n−22n - 2.

Lemma 6 (one dominant variance: the size tends to α\alpha exactly). Fix mm, nn and σX\sigma_X, and let σY→0\sigma_Y \to 0. Under H0H_0, the rejection probability of each of the three rules at level α\alpha tends to α\alpha. The same holds with the roles of the samples exchanged.

Proof. Write Xˉ−Yˉ−δ0=(Xˉ−μX)−(Yˉ−μY)\bar X - \bar Y - \delta_0 = (\bar X - \mu_X) - (\bar Y - \mu_Y) under H0H_0. As σY→0\sigma_Y \to 0, Yˉ−μY∼N(0,β0)\bar Y - \mu_Y \sim N(0, \beta_0) and B=β0V2/(n−1)B = \beta_0 V_2/(n - 1) both tend to 0 in probability, while the law of (Xˉ,A)(\bar X, A) does not change. So, by Slutsky's theorem and the continuity of (u,a,b)↦u/a+b(u, a, b) \mapsto u/\sqrt{a + b} at b=0b = 0, a>0a > 0 (and A>0A > 0 almost surely), TT converges in distribution to TX=(Xˉ−μX)/AT_X = (\bar X - \mu_X)/\sqrt{A}, the one-sample t statistic of the XX sample, which is tm−1t_{m-1} by Lemma 2 of the Student proof. In the same way ν^=ν(A,B)→ν(A,0)=m−1\hat\nu = \nu(A, B) \to \nu(A, 0) = m - 1, jointly with TT. The p-value is a continuous function of (t,ν)(t, \nu) for ν>0\nu > 0 (the tνt_\nu tail is continuous in both arguments), so by the continuous mapping theorem it converges in distribution to the tm−1t_{m-1} tail of TXT_X, which is uniform on [0,1][0, 1] (Lemma 5 of the Student proof). The uniform law is continuous at α\alpha, so P(p≤α)→αP(p \le \alpha) \to \alpha. □\square

Lemma 7 (large samples: the size tends to α\alpha). Let X1,…,XmX_1, \dots, X_m be iid with mean μX\mu_X and finite variance σX2>0\sigma_X^2 > 0 and Y1,…,YnY_1, \dots, Y_n iid with mean μY\mu_Y and finite variance σY2>0\sigma_Y^2 > 0, independent, of any shape. If m,n→∞m, n \to \infty (at any relative rate), then under H0H_0 the statistic TT converges in distribution to N(0,1)N(0, 1) and the size of each rule tends to α\alpha.

Proof. Let ZX=(Xˉ−μX)/α0Z_X = (\bar X - \mu_X)/\sqrt{\alpha_0} and ZY=(Yˉ−μY)/β0Z_Y = (\bar Y - \mu_Y)/\sqrt{\beta_0}, and wX=α0/θw_X = \sqrt{\alpha_0/\theta}, wY=β0/θw_Y = \sqrt{\beta_0/\theta}, so wX2+wY2=1w_X^2 + w_Y^2 = 1 and (Xˉ−Yˉ−δ0)/θ=wXZX−wYZY(\bar X - \bar Y - \delta_0)/\sqrt\theta = w_X Z_X - w_Y Z_Y under H0H_0. By the central limit theorem, the characteristic functions φX\varphi_X of ZXZ_X and φY\varphi_Y of ZYZ_Y tend to e−s2/2e^{-s^2/2}, and by Lévy's continuity theorem the convergence is uniform for ss in compact sets. The weights stay in [0,1][0, 1], so by independence the characteristic function of wXZX−wYZYw_X Z_X - w_Y Z_Y at ss is φX(wXs)φY(−wYs)=e−wX2s2/2e−wY2s2/2+o(1)=e−s2/2+o(1)\varphi_X(w_X s)\varphi_Y(-w_Y s) = e^{-w_X^2 s^2/2}e^{-w_Y^2 s^2/2} + o(1) = e^{-s^2/2} + o(1), which gives the N(0,1)N(0, 1) limit. By the law of large numbers, A/α0=SX2/σX2→1A/\alpha_0 = S_X^2/\sigma_X^2 \to 1 and B/β0→1B/\beta_0 \to 1 in probability, so (A+B)/θ=wX2(A/α0)+wY2(B/β0)→1(A + B)/\theta = w_X^2 (A/\alpha_0) + w_Y^2 (B/\beta_0) \to 1 in probability, and Slutsky's theorem gives T→N(0,1)T \to N(0, 1) in distribution. By Lemma 4, ν^≥min⁡(m,n)−1→∞\hat\nu \ge \min(m, n) - 1 \to \infty, so the tν^t_{\hat\nu} critical values tend to the normal ones. The limit law is continuous, so the rejection probabilities tend to α\alpha. □\square

What is not proved. Between these limits the exact size of the Welch rule is a function of σX2/σY2\sigma_X^2/\sigma_Y^2, mm and nn that is not constant and not equal to α\alpha. This is the Behrens-Fisher problem. We do not prove a formula for it; the measurements on the page (for example a size of 0.119 at m=2m = 2, n=20n = 20, equal variances, α=0.05\alpha = 0.05, with r=20000r = 20000 replications and seed 11) show that it can differ from α\alpha by much more than the Monte Carlo error.

Termination. Lines L1 and L2 make two passes over each sample, L3 to L5 are a constant number of operations, and the tν^t_{\hat\nu} tail is the incomplete beta continued fraction of the shared helper, which stops after a fixed cap of iterations. So the test stops after O(m+n)O(m + n) arithmetic operations plus a bounded number of iterations.

Theorem. For independent normal samples, Welch's test returns TT and ν^=ν(A,B)\hat\nu = \nu(A, B) with min⁡(m,n)−1≤ν^≤m+n−2\min(m, n) - 1 \le \hat\nu \le m + n - 2. With m=nm = n its statistic is the pooled statistic. Its size tends to α\alpha when one of the two variances tends to 0, and, for any populations with finite positive variances, when both sample sizes grow. Elsewhere it is an approximation whose error is measured, not bounded.

Proof. Lemmas 4 and 5 for the first two claims, Lemmas 6 and 7 for the limits, and Lemma 3 with the remark after Lemma 1 for the nature of the approximation. ■\blacksquare

Complexity

On a real RAM, lines L1 and L2 make two passes over each sample, about 4(m+n)4(m + n) arithmetic operations, and L3 to L5 are a constant number of operations. So the time is Θ(m+n)\Theta(m + n) and the extra space is Θ(1)\Theta(1) besides the data. The tail Fˉν^\bar F_{\hat\nu} costs a number of continued fraction steps that does not grow with mm or nn for the values that matter. The two-pass variances avoid the catastrophic cancellation of the one-pass formula, as on the Student page.

Properties

  • Approximate. The size depends on mm, nn and the variance ratio, and in general differs from α\alpha; it tends to α\alpha as one variance dominates or as both sizes grow.
  • Degrees of freedom bounds. min⁡(m,n)−1≤ν^≤m+n−2\min(m, n) - 1 \le \hat\nu \le m + n - 2. ν^\hat\nu is a random variable, not a fixed count.
  • Same statistic as pooled at equal sizes. With m=nm = n the two statistics agree and only the degrees of freedom differ, ν^≤2n−2\hat\nu \le 2n - 2. For the sleep data of Cushny and Peebles read as two groups of 10, ∣t∣=1.8608|t| = 1.8608 for both, with ν^=17.776\hat\nu = 17.776 and p=0.0794p = 0.0794 against 18 and 0.07920.0792.
  • Invariant. TT and ν^\hat\nu do not change when both samples and δ0\delta_0 are shifted together, or when both samples are scaled by the same positive factor (with δ0\delta_0 scaled too).
  • Limited by the smaller sample. The quality of the approximation depends on the smaller sample: with m=2m = 2 the size can be more than twice α\alpha.

Variants and improvements

  • Welch-Satterthwaite approximation in general. For a combination ∑iciSi2\sum_i c_i S_i^2 of independent variance estimates with νi\nu_i degrees of freedom each, the effective degrees of freedom are (∑iciSi2)2/∑i(ciSi2)2/νi\big(\sum_i c_i S_i^2\big)^2 / \sum_i (c_i S_i^2)^2/\nu_i. The two-sample test is the case c1=1/mc_1 = 1/m, c2=1/nc_2 = 1/n. The same formula gives approximate degrees of freedom in mixed-effects models and for combined measurement uncertainties.
  • Welch interval. By test-interval duality, Xˉ−Yˉ±t(ν^,1−α/2)SX2/m+SY2/n\bar X - \bar Y \pm t_{(\hat\nu, 1-\alpha/2)}\sqrt{S_X^2/m + S_Y^2/n} is an approximate 1−α1 - \alpha interval for μX−μY\mu_X - \mu_Y; its coverage error is the size error of the test.
  • Conservative degrees of freedom. Older texts use min⁡(m,n)−1\min(m, n) - 1 in place of ν^\hat\nu. By the lower bound this gives a larger critical value at the usual levels, so it rejects less often than the Welch rule on the same data.
  • Several groups. Welch also gave an analogue of one-way ANOVA for several means with unequal variances.
  • Resampling and rank tests. The bootstrap of the Welch statistic is also approximate. The Mann-Whitney U test and the permutation test are exact only for the hypothesis that both samples have the same distribution, which includes equal variances, so they do not solve the Behrens-Fisher problem either.

When to use it

Use Welch's test to compare the means of two independent groups of roughly normal data, or of larger groups of any shape with finite variance, whenever the variances are not known to be equal. Many texts now make it the default two-sample t-test: when the variances are equal it loses little against the pooled test, and when they differ it keeps the size near α\alpha while the pooled test can have a size of 0.30 or 0.001. For paired data use the paired t-test instead. With a group of 2 or 3 observations, treat its p-value as rough.

Pitfalls

  • Treating the test as exact. It is an approximation; with m=2m = 2 and equal variances the measured size is 0.119 at nominal 0.05.
  • Rounding ν^\hat\nu to an integer before looking up a table. This is unnecessary with a tail function that accepts real ν\nu, and rounding down or up changes the p-value.
  • Choosing between pooled and Welch by a preliminary test of equal variances. The two-stage procedure does not have the nominal size, and the variance test has little power at the small sizes where the choice matters.
  • Using it on paired data. The groups must be independent; for paired measurements the test ignores the pairing and loses power.
  • Reading the degrees of freedom as a sample size. ν^\hat\nu is a property of the variance estimate and changes from sample to sample.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

stdist.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the pe1 statistics pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Normal, chi-square, t and F distribution functions in the standard library.

The incomplete gamma and beta functions return a lower tail and an upper
tail, and each tail is computed directly where it is small, so an upper tail
such as chi2_sf(200, 3) does not come from 1 - cdf and does not cancel.
Quantiles use a safeguarded bisection on the CDF (lower half) or on the upper
tail (upper half); the bracket shrinks until floating point stops it, so the
probability error is that of the CDF, below 1e-12 for moderate parameters.
"""

import math
from statistics import NormalDist

_STD = NormalDist()
_EPS = 1e-16
_TINY = 1e-300
_MAXIT = 10000


def norm_cdf(x: float) -> float:
    """P(Z <= x) for a standard normal Z."""
    return 0.5 * math.erfc(-x / math.sqrt(2.0))


def norm_sf(x: float) -> float:
    """P(Z > x), computed with erfc, so it is accurate for large x."""
    return 0.5 * math.erfc(x / math.sqrt(2.0))


def norm_ppf(p: float) -> float:
    """The lower p-quantile z_p of the standard normal, 0 < p < 1."""
    if not 0.0 < p < 1.0:
        raise ValueError("p must be in (0, 1)")
    return _STD.inv_cdf(p)


def _gamma_tails(a: float, x: float) -> tuple[float, float]:
    """(P(a, x), Q(a, x)), the regularized lower and upper incomplete gamma."""
    if a <= 0.0 or x < 0.0:
        raise ValueError("need a > 0 and x >= 0")
    if x == 0.0:
        return 0.0, 1.0
    if math.isinf(x):
        return 1.0, 0.0
    front = math.exp(-x + a * math.log(x) - math.lgamma(a))
    if x < a + 1.0:
        # Series: P = front * sum_{j >= 0} x^j / (a (a + 1) ... (a + j)).
        ap, term = a, 1.0 / a
        total = term
        for _ in range(_MAXIT):
            ap += 1.0
            term *= x / ap
            total += term
            if abs(term) < abs(total) * _EPS:
                break
        p = front * total
        return p, 1.0 - p
    # Continued fraction for Q, modified Lentz.
    b = x + 1.0 - a
    c = 1.0 / _TINY
    d = 1.0 / b
    h = d
    for i in range(1, _MAXIT):
        an = -i * (i - a)
        b += 2.0
        d = an * d + b
        if abs(d) < _TINY:
            d = _TINY
        c = b + an / c
        if abs(c) < _TINY:
            c = _TINY
        d = 1.0 / d
        step = d * c
        h *= step
        if abs(step - 1.0) < _EPS:
            break
    q = front * h
    return 1.0 - q, q


def gamma_p(a: float, x: float) -> float:
    """Regularized lower incomplete gamma P(a, x)."""
    return _gamma_tails(a, x)[0]


def gamma_q(a: float, x: float) -> float:
    """Regularized upper incomplete gamma Q(a, x) = 1 - P(a, x)."""
    return _gamma_tails(a, x)[1]


def _beta_cf(a: float, b: float, x: float) -> float:
    """The continued fraction of I_x(a, b), modified Lentz."""
    qab, qap, qam = a + b, a + 1.0, a - 1.0
    c = 1.0
    d = 1.0 - qab * x / qap
    if abs(d) < _TINY:
        d = _TINY
    d = 1.0 / d
    h = d
    for m in range(1, _MAXIT):
        m2 = 2 * m
        aa = m * (b - m) * x / ((qam + m2) * (a + m2))
        d = 1.0 + aa * d
        if abs(d) < _TINY:
            d = _TINY
        c = 1.0 + aa / c
        if abs(c) < _TINY:
            c = _TINY
        d = 1.0 / d
        h *= d * c
        aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2))
        d = 1.0 + aa * d
        if abs(d) < _TINY:
            d = _TINY
        c = 1.0 + aa / c
        if abs(c) < _TINY:
            c = _TINY
        d = 1.0 / d
        step = d * c
        h *= step
        if abs(step - 1.0) < _EPS:
            break
    return h


def _beta_tails(a: float, b: float, x: float, y: float | None = None) -> tuple[float, float]:
    """(I_x(a, b), 1 - I_x(a, b)), each computed directly where it is small.

    y is 1 - x; pass it when it is known more accurately than 1 - x.
    """
    if a <= 0.0 or b <= 0.0:
        raise ValueError("need a > 0 and b > 0")
    if y is None:
        y = 1.0 - x
    if x <= 0.0:
        return 0.0, 1.0
    if y <= 0.0:
        return 1.0, 0.0
    front = math.exp(
        math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b)
        + a * math.log(x) + b * math.log(y)
    )
    if x < (a + 1.0) / (a + b + 2.0):
        low = front * _beta_cf(a, b, x) / a
        return low, 1.0 - low
    # Symmetry: I_x(a, b) = 1 - I_(1-x)(b, a).
    up = front * _beta_cf(b, a, y) / b
    return 1.0 - up, up


def beta_inc(a: float, b: float, x: float) -> float:
    """Regularized incomplete beta function I_x(a, b)."""
    return _beta_tails(a, b, x)[0]


def chi2_cdf(x: float, k: float) -> float:
    """P(X <= x) for X chi-square with k > 0 degrees of freedom."""
    return 0.0 if x <= 0.0 else gamma_p(k / 2.0, x / 2.0)


def chi2_sf(x: float, k: float) -> float:
    """P(X > x) for X chi-square with k degrees of freedom, without 1 - cdf."""
    return 1.0 if x <= 0.0 else gamma_q(k / 2.0, x / 2.0)


def t_sf(x: float, k: float) -> float:
    """P(T > x) for T Student t with k > 0 degrees of freedom."""
    if math.isfinite(x):
        s = k + x * x
        half = 0.5 * _beta_tails(k / 2.0, 0.5, k / s, x * x / s)[0]  # P(|T| > |x|) / 2
    else:
        half = 0.0
    return half if x >= 0.0 else 1.0 - half


def t_cdf(x: float, k: float) -> float:
    """P(T <= x) for T Student t with k degrees of freedom."""
    return t_sf(-x, k)


def f_cdf(x: float, k1: float, k2: float) -> float:
    """P(F <= x) for F with (k1, k2) degrees of freedom."""
    if x <= 0.0:
        return 0.0
    return _beta_tails(k2 / 2.0, k1 / 2.0, k2 / (k2 + k1 * x), k1 * x / (k2 + k1 * x))[1]


def f_sf(x: float, k1: float, k2: float) -> float:
    """P(F > x) = I_(k2 / (k2 + k1 x))(k2 / 2, k1 / 2)."""
    if x <= 0.0:
        return 1.0
    return _beta_tails(k2 / 2.0, k1 / 2.0, k2 / (k2 + k1 * x), k1 * x / (k2 + k1 * x))[0]


def _quantile(cdf, sf, p: float, lo: float, hi: float) -> float:
    """The x with cdf(x) = p, by bisection on cdf (p <= 1/2) or on sf (p > 1/2).

    lo must satisfy cdf(lo) <= p; hi is doubled until cdf(hi) >= p.
    """
    if not 0.0 < p < 1.0:
        raise ValueError("p must be in (0, 1)")
    if p <= 0.5:
        g = lambda x: cdf(x) - p  # increasing in x
    else:
        q = 1.0 - p
        g = lambda x: q - sf(x)  # increasing in x, and no cancellation in sf
    while g(hi) < 0.0:
        lo, hi = hi, 2.0 * hi if hi > 0.0 else 1.0
    for _ in range(400):
        mid = 0.5 * (lo + hi)
        if mid <= lo or mid >= hi:
            break
        if g(mid) < 0.0:
            lo = mid
        else:
            hi = mid
    return 0.5 * (lo + hi)


def chi2_ppf(p: float, k: float) -> float:
    """The lower p-quantile chi^2_(k, p)."""
    return _quantile(lambda x: chi2_cdf(x, k), lambda x: chi2_sf(x, k), p, 0.0, max(1.0, k))


def t_ppf(p: float, k: float) -> float:
    """The lower p-quantile t_(k, p)."""
    if p == 0.5:
        return 0.0
    if p < 0.5:
        return -t_ppf(1.0 - p, k)
    return _quantile(lambda x: t_cdf(x, k), lambda x: t_sf(x, k), p, 0.0, 1.0)


def f_ppf(p: float, k1: float, k2: float) -> float:
    """The lower p-quantile F_(k1, k2, p)."""
    return _quantile(lambda x: f_cdf(x, k1, k2), lambda x: f_sf(x, k1, k2), p, 0.0, 1.0)
welch_core.py 60 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/welch-t-test/. The authors are listed in prov/C3KW5Q.jsonl.
"""Welch's two-sample t-test with the Welch-Satterthwaite degrees of freedom.

welch_t_test returns (t, nu, p): the statistic, the approximate degrees of
freedom (a real number) and the p-value for the alternative "two-sided",
"greater" (H_1: mu_x - mu_y > delta0) or "less". Both sample variances use the
divisor n - 1 and the two-pass formula. The code is in this file and not in
welch_t_test.py, because tools treat a file whose name ends in _test.py as a
test file.
"""

import math
from collections.abc import Sequence

from stdist import t_sf

ALTERNATIVES = ("two-sided", "greater", "less")


def welch_df(a: float, m: int, b: float, n: int) -> float:
    """The Welch-Satterthwaite degrees of freedom for the variance estimate a + b.

    a = S_x^2 / m and b = S_y^2 / n are the two estimated variances of the
    means, with m - 1 and n - 1 degrees of freedom.
    """
    if a < 0.0 or b < 0.0 or a + b == 0.0 or m < 2 or n < 2:
        raise ValueError("need a, b >= 0 with a + b > 0, and m, n >= 2")
    return (a + b) ** 2 / (a * a / (m - 1) + b * b / (n - 1))


def _mean_var(x: Sequence[float]) -> tuple[float, float]:
    """The mean and S^2 with divisor len(x) - 1, by two passes."""
    k = len(x)
    mean = math.fsum(x) / k
    return mean, math.fsum((v - mean) ** 2 for v in x) / (k - 1)


def welch_t_test(x: Sequence[float], y: Sequence[float], delta0: float = 0.0,
                 alternative: str = "two-sided") -> tuple[float, float, float]:
    """Test H_0: mu_x - mu_y = delta0 for independent normal samples with unequal variances."""
    m, n = len(x), len(y)
    if m < 2 or n < 2:
        raise ValueError("each sample needs at least 2 observations")
    mx, vx = _mean_var(x)  # @line L1
    my, vy = _mean_var(y)  # @line L2
    a, b = vx / m, vy / n  # @line L3
    if a + b == 0.0:
        raise ValueError("both samples are constant, so the standard error is 0")
    t = (mx - my - delta0) / math.sqrt(a + b)  # @line L4
    nu = welch_df(a, m, b, n)  # @line L5
    if alternative == "two-sided":
        p = min(1.0, 2.0 * t_sf(abs(t), nu))
    elif alternative == "greater":
        p = t_sf(t, nu)
    elif alternative == "less":
        p = t_sf(-t, nu)
    else:
        raise ValueError(f"alternative must be one of {ALTERNATIVES}")
    return t, nu, p  # @line L6
test_welch_t_test.py 118 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/welch-t-test/. The authors are listed in prov/C3KW5Q.jsonl.

import math
import random
from fractions import Fraction

import pytest

from stdist import t_sf
from welch_t_test import welch_df, welch_t_test

DRUG_1 = [0.7, -1.6, -0.2, -1.2, -0.1, 3.4, 3.7, 0.8, 0.0, 2.0]
DRUG_2 = [1.9, 0.8, 1.1, 0.1, -0.1, 4.4, 5.5, 1.6, 4.6, 3.4]
SE4 = 4.0 * math.sqrt(0.05 * 0.95 / 4000)  # four standard errors of a size near 0.05, r = 4000


def exact_parts(x: list[int], y: list[int]) -> tuple[Fraction, Fraction]:
    """(t^2, nu) in exact arithmetic, from the definitions with divisors m - 1 and n - 1."""
    m, n = len(x), len(y)
    mx, my = Fraction(sum(x), m), Fraction(sum(y), n)
    a = sum((v - mx) ** 2 for v in x) / Fraction(m - 1) / m
    b = sum((v - my) ** 2 for v in y) / Fraction(n - 1) / n
    nu = (a + b) ** 2 / (a * a / (m - 1) + b * b / (n - 1))
    return (mx - my) ** 2 / (a + b), nu


def test_degrees_of_freedom_against_fractions() -> None:
    rng = random.Random(12)
    checked = 0
    for _ in range(80):
        m, n = rng.randint(2, 9), rng.randint(2, 9)
        x = [rng.randint(-15, 15) for _ in range(m)]
        y = [rng.randint(-15, 15) for _ in range(n)]
        if len(set(x)) == 1 and len(set(y)) == 1:
            continue
        t2, nu = exact_parts(x, y)
        t, got_nu, _ = welch_t_test(x, y)
        assert abs(got_nu - float(nu)) <= 1e-12 * float(nu)
        assert abs(t * t - float(t2)) <= 1e-12 * max(1.0, float(t2))
        # Proved bounds: min(m, n) - 1 <= nu <= m + n - 2.
        assert min(m, n) - 1 <= nu <= m + n - 2
        checked += 1
    assert checked > 60


def test_degrees_of_freedom_cases() -> None:
    # Equal sizes and equal sample variances give the pooled value 2n - 2.
    assert abs(welch_df(2.0, 7, 2.0, 7) - 12.0) < 1e-12
    # The upper bound m + n - 2 holds with equality when a / (m - 1) = b / (n - 1).
    assert abs(welch_df(4.0, 5, 9.0, 10) - 13.0) < 1e-12
    # One variance much larger than the other: nu tends to that sample's n - 1.
    assert abs(welch_df(1.0, 5, 1e-12, 30) - 4.0) < 1e-9
    assert abs(welch_df(1e-12, 5, 1.0, 30) - 29.0) < 1e-9


def test_sleep_data() -> None:
    t, nu, p = welch_t_test(DRUG_1, DRUG_2)
    assert abs(t - (-1.8608134674868533)) < 1e-9
    assert abs(nu - 17.77647351617849) < 1e-9
    assert abs(p - 2.0 * t_sf(abs(t), nu)) < 1e-15
    assert abs(p - 0.07939414018735817) < 1e-9


def test_equal_sizes_give_the_pooled_statistic() -> None:
    rng = random.Random(4)
    for _ in range(20):
        n = rng.randint(2, 12)
        x = [rng.gauss(1.0, 2.0) for _ in range(n)]
        y = [rng.gauss(0.0, 0.5) for _ in range(n)]
        mx, my = sum(x) / n, sum(y) / n
        sp2 = (sum((v - mx) ** 2 for v in x) + sum((v - my) ** 2 for v in y)) / (2 * n - 2)
        pooled = (mx - my) / math.sqrt(sp2 * 2.0 / n)
        assert abs(welch_t_test(x, y)[0] - pooled) < 1e-10


def null_size(m: int, sd_x: float, n: int, sd_y: float, r: int, seed: int,
              alternative: str = "two-sided") -> float:
    rng = random.Random(seed)
    hits = 0
    for _ in range(r):
        x = [rng.gauss(5.0, sd_x) for _ in range(m)]
        y = [rng.gauss(5.0, sd_y) for _ in range(n)]
        hits += welch_t_test(x, y, alternative=alternative)[2] <= 0.05
    return hits / r


def test_size_near_alpha_with_unequal_variances_and_sizes() -> None:
    # The case where the pooled test has size 0.30. The Welch size is not exactly 0.05
    # (about 0.053 in a run with r = 20000), so allow 0.01 on top of 4 standard errors.
    assert abs(null_size(5, 3.0, 25, 1.0, 4000, 5) - 0.05) < SE4 + 0.01
    assert abs(null_size(5, 1.0, 25, 3.0, 4000, 6) - 0.05) < SE4 + 0.01


def test_one_sided_size() -> None:
    assert abs(null_size(8, 2.0, 16, 1.0, 4000, 9, "greater") - 0.05) < SE4 + 0.01


def test_limit_of_one_dominant_variance_is_exact() -> None:
    # sigma_y -> 0: the statistic tends to the one-sample t of x, nu tends to m - 1,
    # and the size tends to alpha exactly.
    assert abs(null_size(4, 1.0, 20, 1e-6, 4000, 7) - 0.05) < SE4


def test_welch_is_only_approximate() -> None:
    # With m = 2 and equal variances the size is far above 0.05 (about 0.119 with r = 20000).
    assert null_size(2, 1.0, 20, 1.0, 4000, 8) > 0.05 + SE4


def test_bad_input() -> None:
    with pytest.raises(ValueError):
        welch_t_test([1.0], [1.0, 2.0])
    with pytest.raises(ValueError):
        welch_t_test([1.0, 1.0], [2.0, 2.0])
    with pytest.raises(ValueError):
        welch_t_test([1.0, 2.0], [2.0, 3.0], alternative="both")
    with pytest.raises(ValueError):
        welch_df(0.0, 3, 0.0, 3)
welch_t_test.py 8 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/welch-t-test/. The authors are listed in prov/C3KW5Q.jsonl.
"""Entry point named after the slug. The code lives in welch_core.py, because tools treat
a file whose name ends in _test.py as a test file and skip its @line markers."""

from welch_core import ALTERNATIVES, welch_df, welch_t_test

__all__ = ["ALTERNATIVES", "welch_df", "welch_t_test"]

History

The problem of comparing two normal means with unknown and possibly unequal variances was posed by W.-U. Behrens in 1929, and R. A. Fisher gave a fiducial solution in 1935, so the problem carries both names. Neither gave a test whose size is exactly α\alpha for all variance ratios. F. E. Satterthwaite approximated the law of a linear combination of independent mean squares by a scaled chi-square with matched mean and variance, in 1941 and in the Biometrics Bulletin in 1946. B. L. Welch, in Biometrika in 1947, studied the statistic with separate variance estimates, gave the same approximate degrees of freedom for the two-sample case and higher-order corrections, and so gave the test its name.

References

  1. B. L. Welch, The generalization of 'Student's' problem when several different population variances are involved, Biometrika 34(1-2), 1947, pp. 28 to 35, The whole paper (the statistic with separate variance estimates, the approximate degrees of freedom and the higher-order corrections)
  2. F. E. Satterthwaite, An approximate distribution of estimates of variance components, Biometrics Bulletin 2(6), 1946, pp. 110 to 114, The whole paper (a linear combination of independent mean squares approximated by a scaled chi-square law with matched first two moments)
  3. George Casella and Roger L. Berger, Statistical Inference, second edition, Duxbury, 2002, Section 5.3 (sampling from the normal distribution, the chi-square and t laws used in the derivation) and Chapter 8 (two-sample tests of means)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example