Tutorials › Introduction to Statistics › Why Two-Group ANOVA Matches a Two-Sample T Test

One-Way ANOVA · Tutorial 867 of 996

Why Two-Group ANOVA Matches a Two-Sample T Test

Learn how the two-group ANOVA and pooled two-sample t test use the same within-group variation and produce equivalent two-sided tests.

Intermediate 12 min read

What You'll Learn

  • Derive the two-group between-group sum of squares from the difference in sample means.
  • Show algebraically why the ANOVA F statistic equals the pooled two-sample t statistic squared.
  • Verify the identity with balanced and unequal group sizes.
  • Connect the two-sided t-test p-value to the upper-tail F-test p-value.
  • Identify why the result does not apply to Welch’s unequal-variance t test.

Why Compare Two Groups in Two Ways?

A one-way ANOVA is often introduced as a method for comparing the means of several groups, while a two-sample t test is introduced for comparing two means. When there are exactly two groups, however, the classical one-way ANOVA and the pooled two-sample t test are not competing methods: they are two ways to express the same comparison. Their test statistics satisfy \(F=t^2\).

This identity is useful for understanding both procedures. The t statistic keeps track of the direction of the observed difference: it is positive or negative depending on the order in which the groups are subtracted. The F statistic is nonnegative and records the size of the difference relative to within-group variation. Squaring the t statistic removes its sign, leaving precisely the F statistic.

The result concerns the standard one-way ANOVA and the pooled two-sample t test, which use a common within-group variance estimate. Before using either test for inference, suppose the observations are independent, each group is reasonably described by a normal population, and the two populations have the same variance. The hypotheses for the comparison are \(H_0:\mu_1=\mu_2\) against \(H_a:\mu_1\ne\mu_2\). In examples below, these assumptions are stipulated as part of the hypothetical model; the arithmetic identity itself follows from the formulas.

Theorem: For two groups with sample sizes \(n_1\) and \(n_2\), let \(N=n_1+n_2\), let \(SSB\) be the between-group sum of squares, and let \(SSW\) be the within-group sum of squares. The one-way ANOVA statistic is \(F=MSB/MSW\), with \(MSB=SSB\) and \(MSW=SSW/(N-2)\). The pooled two-sample t statistic is \(t=(\bar{x}_1-\bar{x}_2)/\sqrt{MSW(1/n_1+1/n_2)}\). Then \(F=t^2\), with ANOVA degrees of freedom \(1\) and \(N-2\), and t-test degrees of freedom \(N-2\).

The Algebra Behind the Identity

Let \(\bar{x}_1\) and \(\bar{x}_2\) be the sample means, and let \(\bar{x}\) be the grand mean across all \(N\) observations. The grand mean is the sample-size-weighted average of the two group means:

$$ \bar{x}=\frac{n_1\bar{x}_1+n_2\bar{x}_2}{N}. $$

For two groups, the between-group sum of squares is \(SSB=n_1(\bar{x}_1-\bar{x})^2+n_2(\bar{x}_2-\bar{x})^2\). Subtracting the grand mean from each group mean gives \(\bar{x}_1-\bar{x}=\frac{n_2}{N}(\bar{x}_1-\bar{x}_2)\) and \(\bar{x}_2-\bar{x}=-\frac{n_1}{N}(\bar{x}_1-\bar{x}_2)\). Substitute these expressions into \(SSB\):

$$ \begin{aligned} SSB &=n_1\left(\frac{n_2}{N}\right)^2(\bar{x}_1-\bar{x}_2)^2 +n_2\left(\frac{n_1}{N}\right)^2(\bar{x}_1-\bar{x}_2)^2\\ &=\frac{n_1n_2(n_1+n_2)}{N^2}(\bar{x}_1-\bar{x}_2)^2\\ &=\frac{n_1n_2}{N}(\bar{x}_1-\bar{x}_2)^2. \end{aligned} $$

There are two groups, so the between-group degrees of freedom are \(2-1=1\); hence \(MSB=SSB\). The within-group degrees of freedom are \(N-2\), so \(MSW=SSW/(N-2)\). Now square the pooled t statistic. Since \(1/n_1+1/n_2=N/(n_1n_2)\), its squared denominator contains the reciprocal factor needed to match the expression for \(SSB\):

$$ \begin{aligned} t^2 &=\frac{(\bar{x}_1-\bar{x}_2)^2} {MSW\left(\frac{1}{n_1}+\frac{1}{n_2}\right)}\\ &=\frac{(\bar{x}_1-\bar{x}_2)^2} {MSW\left(\frac{N}{n_1n_2}\right)}\\ &=\frac{\frac{n_1n_2}{N}(\bar{x}_1-\bar{x}_2)^2}{MSW}\\ &=\frac{SSB}{MSW} =\frac{MSB}{MSW} =F. \end{aligned} $$

This is an algebraic identity, not an approximation. It holds whether the group sizes are equal or unequal. Because the tests use the same denominator \(MSW\), neither needs a separate estimate of within-group variance.

Worked Example: Balanced Groups

Consider hypothetical measurements from two independent groups of five observations each. Suppose the values are \(8, 9, 10, 11, 12\) in Group 1 and \(10, 11, 12, 13, 14\) in Group 2. For inference, assume the observations are independent and the two groups arise from normal populations with equal variances. Compare the ANOVA and pooled t statistics.

The group means are \(\bar{x}_1=10\) and \(\bar{x}_2=12\). In each group, the deviations from its mean are \(-2,-1,0,1,2\), whose squared deviations sum to \(10\). Thus \(SSW=10+10=20\), and

$$ MSW=\frac{SSW}{N-2}=\frac{20}{10-2}=2.5. $$

Using the two-group formula, the between-group sum of squares is

$$ SSB=\frac{n_1n_2}{N}(\bar{x}_1-\bar{x}_2)^2 =\frac{5(5)}{10}(10-12)^2=10. $$

There is one between-group degree of freedom, so \(MSB=10\), and

$$ F=\frac{MSB}{MSW}=\frac{10}{2.5}=4. $$

For the pooled t test, the standard error of the difference is \(\sqrt{MSW(1/n_1+1/n_2)}\). Substitution gives

$$ SE=\sqrt{2.5\left(\frac{1}{5}+\frac{1}{5}\right)}=1, \qquad t=\frac{10-12}{1}=-2, \qquad t^2=(-2)^2=4. $$

The negative t value indicates that Group 1’s sample mean is lower than Group 2’s. The ANOVA statistic is \(4\), exactly the square of the t statistic. Both procedures have within-group degrees of freedom \(10-2=8\).

Unequal Group Sizes Still Give the Same Result

Equal sample sizes are not required. The grand mean weights each group mean according to its sample size, which is why the factor in \(SSB\) is \(n_1n_2/N\), not simply one of the group sizes. That factor matches the reciprocal of \(1/n_1+1/n_2\) in the t statistic.

Worked Example: Unequal Group Sizes

Suppose hypothetical independent observations are \(18,19,20,21,22\) in Group 1 and \(19,20,21,22,24,25,26,27\) in Group 2. Assume for inference that the group populations are normal with a common variance. The group sizes are \(n_1=5\) and \(n_2=8\); the sample means are \(\bar{x}_1=20\) and \(\bar{x}_2=23\).

The sum of squared deviations from the first group mean is \(10\). In Group 2 the deviations from \(23\) are \(-4,-3,-2,-1,1,2,3,4\), whose squared deviations sum to \(60\). Therefore \(SSW=10+60=70\), \(N=13\), and

$$ MSW=\frac{70}{13-2}=\frac{70}{11}\approx6.363636. $$

The between-group sum of squares and ANOVA statistic are

$$ SSB=\frac{5(8)}{13}(20-23)^2=\frac{360}{13}\approx27.692308, \qquad F=\frac{360/13}{70/11} =\frac{396}{91}\approx4.351648. $$

For the pooled t test, the standard error is

$$ SE=\sqrt{\frac{70}{11}\left(\frac{1}{5}+\frac{1}{8}\right)} =\sqrt{\frac{91}{44}} \approx1.438118. $$

Consequently,

$$ t=\frac{20-23}{\sqrt{91/44}}\approx-2.08606, \qquad t^2=\frac{396}{91}\approx4.351648. $$

The exact expressions, evaluated before rounding, agree. The displayed rounded value of \(t\) is only an approximation; squaring a rounded display can produce a slightly different last digit. Here both procedures have within-group degrees of freedom \(11\), and \(F\approx t^2\approx4.352\) to four significant figures.

What the Identity Means for a Test

Under \(H_0:\mu_1=\mu_2\), and under the stated normality, independence, and equal-variance assumptions, the pooled t statistic has a t distribution with \(N-2\) degrees of freedom. The one-way ANOVA statistic under the same null has an F distribution with \(1\) and \(N-2\) degrees of freedom. Squaring a t-distributed random variable with \(N-2\) degrees of freedom gives an F-distributed random variable with \(1\) and \(N-2\) degrees of freedom. Therefore the two-sided t test and the standard upper-tail ANOVA test give the same p-value.

In detail, if the observed t statistic is \(t_{\text{obs}}\), then the two-sided t-test p-value is the probability, under the null, of a t statistic at least as extreme in absolute value: \(P(|T|\ge |t_{\text{obs}}|)\). The ANOVA p-value is the probability of an F statistic at least as large as \(F_{\text{obs}}\). Since \(F_{\text{obs}}=t_{\text{obs}}^2\), these are the same probability. The F statistic does not retain the sign of the difference, so the standard ANOVA test corresponds to a two-sided t alternative, not to a one-sided t alternative.

Worked Example: Same F Statistic, Different Sign Information

Suppose another hypothetical comparison has four observations in each group: \(4,5,7,8\) in Group 1 and \(7,8,10,11\) in Group 2. The means are \(6\) and \(9\), and each group has a within-group sum of squares of \(10\). Assume independent observations from normal populations with equal variances for the inferential comparison.

Here \(SSW=20\), \(N=8\), and \(MSW=20/(8-2)=10/3\). The between-group sum of squares is

$$ SSB=\frac{4(4)}{8}(6-9)^2=18, \qquad F=\frac{18}{10/3}=\frac{27}{5}=5.4. $$

The pooled t statistic uses

$$ SE=\sqrt{\frac{10}{3}\left(\frac{1}{4}+\frac{1}{4}\right)} =\sqrt{\frac{5}{3}}, \qquad t=\frac{6-9}{\sqrt{5/3}}\approx-2.32379. $$

Squaring before rounding gives \(t^2=9/(5/3)=27/5=5.4=F\). If the order of the groups were reversed, t would be positive instead, but \(t^2\), F, and the two-sided p-value would not change. This illustrates what is gained and lost in the F statistic: it measures evidence against equality of means but does not say which sample mean is larger.

Scope and a Common Mistake

The identity depends on using the pooled t statistic, whose variance estimate is the same \(MSW\) that appears in the classical one-way ANOVA. It does not generally apply to Welch’s two-sample t test, which allows the two population variances to differ and uses a different standard error and degrees-of-freedom calculation. Nor does this identity say that every t test and every ANOVA are interchangeable: it is specifically the two-group, one-way, equal-variance comparison.

A common mistake is to claim that the ANOVA statistic equals \(t\), then use the sign of the t statistic as though it were part of F. The correction is that \(F=t^2\): F is never negative, and it does not encode the direction of the difference. Another mistake is to compare a one-sided t-test p-value with the ANOVA p-value. The standard ANOVA test detects departures in either direction, so its p-value matches the two-sided pooled t-test p-value.

Why use ANOVA at all when there are only two groups? The t test often communicates the estimated difference and its direction more directly. The identity is still valuable because it shows that the two-group case fits coherently within the broader ANOVA framework: both statistics compare between-group separation with the same within-group variability. With more than two groups, the ANOVA F test assesses whether all group means are equal, and no single two-sample t statistic squared represents that overall comparison.

Key takeaway: In a classical one-way ANOVA with exactly two groups, \(F=t^2\) for the pooled two-sample t statistic. Both tests have \(N-2\) within-group degrees of freedom, and the upper-tail F-test p-value equals the two-sided pooled t-test p-value.

Check Your Understanding

Use the identity and its assumptions to answer these questions.

  1. For two groups of sizes \(n_1=6\) and \(n_2=9\), what are the ANOVA degrees of freedom, and what are the pooled t-test degrees of freedom?
  2. If the pooled t statistic is \(2.4\), what is the ANOVA F statistic? What information about the direction of the difference is not contained in F?
  3. Explain why \(SSB=\frac{n_1n_2}{N}(\bar{x}_1-\bar{x}_2)^2\) leads to \(F=t^2\).
  4. Why does the standard ANOVA p-value match a two-sided t-test p-value rather than a one-sided t-test p-value?
  5. Would the identity generally hold for Welch’s t test? Explain which feature of the pooled test makes the identity work.