Instant PDF download, name-and-email checkout. Complete bundle: every Economics and Statistics book
Statistics guide, Unit 6, step 21 of 22Previous stepNext step

Step 21: Comparing Several Means with ANOVA

SyllabusUniversity
In 30 seconds
  • Running lots of two-sample t-tests to compare several groups inflates the chance of a false alarm. ANOVA (analysis of variance) asks one question with one test: are any of these means different?
  • ANOVA compares between-group variation (signal) with within-group variation (noise). \( F = MSB \div MSW \), where \( MSB = SSB/(k-1) \) and \( MSW = SSW/(N-k) \).
  • If \( H_0 \) is true, F is near 1. A large F is evidence that at least one mean differs. The test is always right-tailed.
  • Exam point: a significant F means at least one mean differs, not that all do and not which ones. Follow up with a post hoc test, and report the effect size \( \eta^2 = SSB/SST \).
Video lesson coming soonA short animated lesson for this step will appear here.

Why not just run lots of t-tests?

A school tries three teaching methods on three groups of students. Method A averages 70 in the exam, method B 78 and method C 86. The obvious plan is to compare them in pairs with the two-sample t-test: A against B, B against C, A against C.

That plan has a hidden flaw. Each test run at \( \alpha = 0.05 \) has a 5% chance of a false alarm. Run three of them and the chance that at least one shouts “significant”, even when all three methods are identical, is roughly 14%.

With \( k \) groups, the number of pairs is \( k(k-1)/2 \). Three groups need 3 tests, five need 10, ten need 45. If the tests were independent, the chance of at least one false alarm across \( c \) comparisons would be:

\[ \text{family-wise error rate} = 1 – 0.95^{c} \]

For 3 comparisons that is \( 1 – 0.95^3 \approx 0.14 \). For 10 comparisons it is about 0.40. With six groups (15 comparisons) it passes 50%. Run enough comparisons and something will always look significant.

Key termFamily-wise error rate: the probability of making at least one Type I error (false alarm) across a whole set of tests.

ANOVA solves this by asking a single question, “are any of these means different?”, and answering it with one test at one significance level. The 5% risk stays at 5% however many groups there are.

The logic: between versus within

Why is a method for comparing means called analysis of variance? Because the way to judge whether means differ is to compare two kinds of variation.

  • Between-group variation: how far the group means sit from the overall (grand) mean. This is the signal.
  • Within-group variation: how much individuals scatter around their own group’s mean. This is background noise, present even if the groups are identical.

If the gaps between group means are large compared with the scatter inside groups, the differences look real. If the gaps are lost in the scatter, they look like chance.

Here is a striking example. Two studies both have three groups of 5 with means 68, 74 and 80. In the first, each group’s standard deviation is 2; in the second it is 9. The means are identical, yet the first study gives F = 45.0 (overwhelmingly significant) and the second gives F = 2.22 (not significant, p ≈ 0.15). The only difference is the spread inside the groups. That is why the means alone can never settle the question.

Key termGrand mean: the mean of all the observations in all the groups taken together.

Sums of squares, mean squares and F

Each kind of variation is measured with a sum of squares, just as variance was built earlier in the book:

\[ SSB = \sum n_i(\bar{x}_i – \bar{x}_{grand})^2 \qquad SSW = \sum\sum (x – \bar{x}_i)^2 \qquad SST = SSB + SSW \]

SSB adds up over a few groups, while SSW adds up over many individuals, so they cannot be compared directly. Dividing each by its degrees of freedom turns them into averages called mean squares. Their ratio is the F-statistic:

\[ MSB = \frac{SSB}{k-1} \qquad MSW = \frac{SSW}{N-k} \qquad F = \frac{MSB}{MSW} \]

Here \( k \) is the number of groups and \( N \) is the total number of observations. F is a signal-to-noise ratio. If all groups really have the same mean, MSB and MSW estimate the same background variance, so F sits near 1. As the means pull apart, MSB grows and F rises. Only large values point to a difference, so, like chi-square, the test is always right-tailed. F has two df: \( (k-1,\ N-k) \).

The ANOVA table, and a complete example

Software shows everything in a standard layout. The within-group row is sometimes labelled “Error” or “Residual”.

SourceSSdfMSF
Between groupsSSB\( k-1 \)SSB/(\( k-1 \))MSB/MSW
Within groups (error)SSW\( N-k \)SSW/(\( N-k \))
TotalSST\( N-1 \)

Two checks catch most arithmetic slips: SSB + SSW must equal SST, and \( (k-1) + (N-k) \) must equal \( N-1 \).

Worked example

Five students are taught by each method. Scores: A: 68, 72, 70, 66, 74. B: 76, 80, 78, 74, 82. C: 84, 88, 86, 82, 90. Test at \( \alpha = 0.05 \) whether the mean scores differ.

Step 1\( H_0: \mu_A = \mu_B = \mu_C \). \( H_a \): at least one mean differs. Group means 70, 78, 86; grand mean 78.
Step 2\( SSB = 5(70-78)^2 + 5(78-78)^2 + 5(86-78)^2 = 320 + 0 + 320 = 640 \)
Step 3In A the deviations from 70 are −2, 2, 0, −4, 4; squares sum to 40. B and C also give 40 each. \( SSW = 120 \), and \( SST = 640 + 120 = 760 \).
Step 4\( k = 3,\ N = 15 \): df = 2 and 12. \( MSB = 640/2 = 320 \), \( MSW = 120/12 = 10 \), \( F = 320/10 = 32.00 \).
Step 5Critical F at df (2, 12) is 3.89. \( 32.00 \gt 3.89 \), so reject \( H_0 \) (p < 0.001).

There is very strong evidence that mean exam scores differ across the three methods. The between-group variation is 32 times the within-group variation, when we would expect about 1 if the methods were equally good.

ANOVA needs three conditions:

  1. Independence: independent random samples, with observations independent within each group. This is a design matter that no plot can repair.
  2. Normality: each group roughly normal. ANOVA copes with mild departures, especially when the groups are the same size.
  3. Equal variances: a practical rule is that the largest group standard deviation should be no more than about twice the smallest.

In the teaching example every group’s standard deviation is about 3.16, so the ratio is 1.0, comfortably below 2.

What a significant F does not tell you, and how big the effect is

Common mistakeA significant F says only that at least one mean differs. It does not say all of them differ, and it does not say which ones. With three groups, a significant result fits all three being different, or two being the same and one standing apart. Writing “all three methods differed significantly” from the F-test alone is not supported.

To find where the differences are, follow a significant ANOVA with a post hoc (“after the fact”) procedure. These make pairwise comparisons, but adjust the significance level so the family-wise error rate stays at 5%. The best known are Tukey’s HSD and the simpler, more cautious Bonferroni correction, which divides \( \alpha \) by the number of comparisons. Order matters: run the overall F first, and go on to post hoc tests only if it is significant.

For the teaching methods, Bonferroni tests each of the 3 pairs at \( 0.05 \div 3 \approx 0.0167 \). Each comparison uses \( SE = \sqrt{10(1/5 + 1/5)} = 2.0 \) with df = 12. A vs B and B vs C each differ by 8, so \( t = 4.00 \) (p ≈ 0.0018); A vs C differs by 16, so \( t = 8.00 \) (p < 0.001). All are below 0.0167, so now we can say all three methods differ, with C best and A worst.

Finally, significance is not the same as importance. With large samples, a tiny spread of means can give a significant F. The usual effect size is eta-squared, the share of the total variation explained by which group you are in:

\[ \eta^2 = \frac{SSB}{SST} \]

For the teaching methods, \( \eta^2 = 640 \div 760 = 0.842 \): about 84% of the variation in scores is explained by the teaching method. A significant F with \( \eta^2 = 0.02 \) would describe a real but practically negligible difference.

One more link: with just two groups, ANOVA gives the same answer as the two-sample t-test, and \( F = t^2 \). With two groups, prefer the t-test, because it also gives a direction and an interval.

Exam tipWrite \( H_a \) as “at least one mean differs”, never “all means differ”. Show the full ANOVA table with both checks (SS and df add down), quote the critical F with both df, and conclude in context. If asked which groups differ, say a post hoc test is needed. Add \( \eta^2 \) to comment on practical importance.

Practise: 6 questions

Try each one on paper first, then check the worked answer.

EasyQ1. A study has 4 groups of 10. Find \( k \), \( N \), both df, and the number of pairwise comparisons. Show worked answer
\( k = 4 \), \( N = 40 \).
df between \( = k – 1 = 3 \); df within \( = N – k = 36 \).
Pairwise comparisons \( = 4 \times 3 \div 2 = 6 \).
EasyQ2. Fill in the gaps: Between SS = 150, df = 3. Within SS = ?, df = 36. Total SS = 550, df = ?. Then find MSB, MSW and F. Show worked answer
SSW \( = 550 – 150 = 400 \). Total df \( = 3 + 36 = 39 \).
\( MSB = 150 \div 3 = 50 \); \( MSW = 400 \div 36 = 11.11 \).
\( F = 50 \div 11.11 = 4.50 \).
Design: \( k = 4 \) groups, \( N = 40 \). Critical F at (3, 36) is about 2.87, so this is significant at 5%.
MediumQ3. SSB = 90, SSW = 810, \( k = 4 \), \( N = 40 \). Compute F and state the decision using a critical value of 2.87. Show worked answer
df = 3 and 36.
\( MSB = 90 \div 3 = 30 \); \( MSW = 810 \div 36 = 22.5 \).
\( F = 30 \div 22.5 = 1.33 \).
\( 1.33 \lt 2.87 \), so fail to reject \( H_0 \): no evidence that the means differ. F is close to 1, so signal and noise are about the same size.
MediumQ4. Four groups of 6 have means 20, 22, 25, 29, and SSW = 200. Find SSB, F and \( \eta^2 \). The critical F at (3, 20) is 3.10. Show worked answer
Grand mean \( = (20 + 22 + 25 + 29) \div 4 = 24 \) (equal group sizes).
\( SSB = 6[(-4)^2 + (-2)^2 + 1^2 + 5^2] = 6(16 + 4 + 1 + 25) = 6 \times 46 = 276 \).
df = 3 and \( 24 – 4 = 20 \). \( MSB = 276 \div 3 = 92 \); \( MSW = 200 \div 20 = 10 \).
\( F = 92 \div 10 = 9.20 \gt 3.10 \), so reject \( H_0 \).
\( SST = 276 + 200 = 476 \); \( \eta^2 = 276 \div 476 = 0.58 \): about 58% of the variation is explained by group.
MediumQ5. Group standard deviations are (a) 4, 5, 7 and (b) 2, 5, 9. Is the equal-variance condition met in each case? Show worked answer
(a) Largest ÷ smallest \( = 7 \div 4 = 1.75 \), below 2, so the condition is met.
(b) \( 9 \div 2 = 4.5 \), well above 2, so the condition is not met and the ANOVA result should not be trusted as it stands.
ExamQ6. A clinic compares recovery times under three treatments, 6 patients each. Group means are 12, 15 and 18 days (grand mean 15) and the within-group sums of squares total 90. (a) State the hypotheses. (b) Compute SSB, SSW and SST. (c) Find both df, both mean squares and F. (d) With a critical value of 3.68 at df (2, 15), conclude in context. [8 marks] Show worked answer
(a) \( H_0: \mu_1 = \mu_2 = \mu_3 \); \( H_a \): at least one mean differs [1].
(b) \( SSB = 6(12-15)^2 + 6(0)^2 + 6(18-15)^2 = 54 + 0 + 54 = 108 \) [1]; SSW = 90; SST = 198 [1].
(c) df between = 2, df within = 18 − 3 = 15 [1]. \( MSB = 108 \div 2 = 54 \); \( MSW = 90 \div 15 = 6 \) [1]; \( F = 54 \div 6 = 9.00 \) [1].
(d) \( 9.00 \gt 3.68 \), so reject \( H_0 \) [1]: there is convincing evidence that mean recovery time differs across the treatments. The test does not say which pairs differ; a post hoc test such as Tukey or Bonferroni is needed [1].

Check yourself

1. If \( H_0 \) is true, roughly what value should F take?

Both mean squares then estimate the same background variance, so their ratio is near 1.

2. An ANOVA on four diets is significant. What may you conclude?

F only shows that at least one mean differs; post hoc tests find which.

3. With a Bonferroni correction for 6 comparisons at overall \( \alpha = 0.05 \), each comparison is tested at…

Bonferroni divides \( \alpha \) by the number of comparisons: \( 0.05 \div 6 \approx 0.0083 \).

Your score: 0 out of 3

The short version

  • Many pairwise t-tests inflate the family-wise error rate (about 14% with three groups). ANOVA asks one question with one test.
  • ANOVA compares between-group signal with within-group noise: \( F = MSB/MSW \), with df \( (k-1,\ N-k) \). F near 1 supports \( H_0 \); large F rejects it.
  • SS and df both add down the ANOVA table. Conditions: independence, roughly normal groups, largest SD no more than about twice the smallest.
  • A significant F means at least one mean differs. Use Tukey or Bonferroni to find which, and report \( \eta^2 = SSB/SST \) for size.
  • With two groups, ANOVA matches the t-test (\( F = t^2 \)). The full chapter in Statistics Made Simple has over 50 practice questions with a complete answer key.
Want more questions like these, with worked answers?
The practice book has hundreds more, graded from easy to exam level.
Next: step 22 of 22A First Look at Multiple Regression