STAT 200 · Statistics for Economics
Analysis of Variance in Plain English
ANOVA compares three or more group averages at once by asking whether groups differ more than the usual wobble inside each group.
Key takeaways
- ANOVA tests whether three or more group averages are all equal, using one test instead of many.
- It splits the total variation into variation between groups and variation within groups.
- The F statistic is the between-group variation divided by the within-group variation, each scaled by its degrees of freedom.
- A large F means the group averages are spread out far more than the noise inside the groups would explain.
- A significant ANOVA says at least one group differs, not which one. A follow-up comparison finds the pairs.
Picture three food stalls at the same night market: Taco Corner, Noodle Nook and Waffle Wagon. Over three evenings each, a student records the average tips per hour the staff earned. Taco Corner's numbers look low, Waffle Wagon's look high, and Noodle Nook sits in the middle. Do the stalls really differ in tips, or is this the kind of spread you would get by chance from three random piles of numbers?
You already know a tool for two groups, the t test from the lesson on t tests. With three groups, the obvious plan is to run three t tests: A against B, A against C, B against C. That plan has a hidden flaw, which this lesson explains. The fix is a method called analysis of variance, or ANOVA. Despite the name, it compares averages. It does so by comparing two kinds of variation.
Why not many t tests?
With three groups there are three pairs. Each t test at the 5% level has a 5% false alarm chance if the null is true. Run three of them and the chance that at least one gives a false alarm climbs to about 1 − 0.95³ = 1 − 0.857 = 0.143, near 14%. (The three tests are not fully independent, so this is a rough guide.) With four groups there are six pairs, and the chance climbs to about 26%.
This is the problem of many tests we met in the lesson on p-values. ANOVA fixes it by asking just one question for the whole set: "Could all these groups share the same true average?" One question, one test, one 5% false alarm risk.
The big idea: two kinds of variation
Suppose you have tips-per-hour numbers for three stalls. Notice that the numbers vary for two different reasons.
- Within a group, the three evenings at one stall differ from each other. That is ordinary day-to-day noise: weather, crowds, luck.
- Between groups, the stall averages differ from each other. That might be noise too. Or it might be a real difference between stalls.
Here is the whole trick. If the stalls were truly identical, the differences between stall averages would be about as big as the ordinary noise would make them. If the stalls truly differ, the averages would be spread out much more than the noise predicts. So ANOVA compares:
- the variation between group averages, with
- the variation within the groups.
If between is much larger than within, the groups probably differ for real.
The test asks whether the first kind is much bigger than the second.
Worked example: three stalls, three evenings each
Here are the average tips per hour, in dollars, for three evenings at each stall.
| Stall | Evening 1 | Evening 2 | Evening 3 | Group average |
|---|---|---|---|---|
| Taco Corner | 10 | 12 | 14 | 12 |
| Noodle Nook | 14 | 16 | 18 | 16 |
| Waffle Wagon | 18 | 20 | 22 | 20 |
There are 9 numbers in all, and the overall (grand) average is (12 + 16 + 20) ÷ 3 = 16. The null hypothesis says all three true averages are equal. The alternative says at least one is different.
Each stall's three dots stay close together (the noise within a group is modest), while the stalls sit at clearly different heights (the signal between groups looks large). Now we measure both.
Step 1: variation between groups. For each group, take its average's distance from the grand average, square it, and multiply by the number of values in the group (3).
Taco: 3 × (12 − 16)² = 3 × 16 = 48
Noodle: 3 × (16 − 16)² = 3 × 0 = 0
Waffle: 3 × (20 − 16)² = 3 × 16 = 48
Between-group sum of squares = 96 Step 2: variation within groups. For each value, take its distance from its own group's average, square it, and add up everything.
Taco: (10−12)² + (12−12)² + (14−12)² = 4 + 0 + 4 = 8
Noodle: (14−16)² + (16−16)² + (18−16)² = 4 + 0 + 4 = 8
Waffle: (18−20)² + (20−20)² + (22−20)² = 4 + 0 + 4 = 8
Within-group sum of squares = 24 As a check, the total variation of all 9 numbers around the grand average of 16 is 56 + 8 + 56 = 120, and 96 + 24 = 120. The pieces add up to the whole, which is where the name "analysis of variance" comes from.
Example with made-up numbers.
Step 3: scale by degrees of freedom. Raw sums depend on how many groups and values you have, so we turn each into an average, called a mean square.
- Between groups: there are 3 groups, so df = 3 − 1 = 2. Mean square = 96 ÷ 2 = 48.
- Within groups: there are 9 values and 3 groups, so df = 9 − 3 = 6. Mean square = 24 ÷ 6 = 4.
Step 4: the F statistic. Divide signal by noise.
F = mean square between ÷ mean square within = 48 ÷ 4 = 12 An F near 1 says the between-group spread is no bigger than the noise. Ours is 12.
Step 5: compare to the cutoff. The F curve depends on two df numbers, here 2 and 6. A table (or software) gives the 5% cutoff for F with (2, 6) degrees of freedom as 5.14. Since 12 is far larger than 5.14, we reject the null. The three stalls do not all share the same true average tips.
Large F means the groups differ by more than the noise predicts.
A few other cutoffs, to see the pattern. At 5%, with 2 and 12 df, it is 3.89. With 3 and 20 df, it is 3.10. More data in the denominator lowers the bar.
What a significant ANOVA does and does not say
Our rejection says "not all three averages are equal." It does not say which stall differs from which. Maybe Taco Corner trails the others. Maybe all three differ. To find out, researchers run a follow-up, such as Tukey's test, which compares pairs while keeping the overall false alarm rate under control. That is the proper cure for the "three t tests" problem: do the one overall test first, then the careful pair checks.
ANOVA also does not explain why. If Waffle Wagon staff earn more, the reason might be location, price, hours or sweet-toothed customers. As in the chi-square lesson, a test can flag a pattern but cannot name its cause.
A second look: how noise changes the answer
To see why F works, change the story. Keep the three stall averages at 12, 16 and 20, but make the evenings far more jumpy. Suppose Taco Corner's three values are 4, 12 and 20, Noodle Nook's are 8, 16 and 24, and Waffle Wagon's are 12, 20 and 28. The group averages are the same as before, so the between-group sum of squares is still 96, and the mean square between is still 48.
But now each stall's values sit 8 away from the average on each side. Each group's within sum of squares is 64 + 0 + 64 = 128, and the three groups total 384. With 6 degrees of freedom, the mean square within is 384 ÷ 6 = 64. Then F = 48 ÷ 64 = 0.75. That is below 1, and far below the 5.14 cutoff. We would fail to reject.
Same stall averages, opposite verdict. The lesson is that a gap between averages means little until you know how noisy the data are. With steady numbers, a 4-dollar gap is striking. With wild numbers, the same gap is easy to get by luck. This is the same idea as the standard error in the t test: a gap is judged against the noise around it. ANOVA is a close cousin of the t test. In fact, with only two groups, F is exactly the square of t.
Notice, too, what happens to F as you gather more data per group. The noise in each group's average shrinks, as the central limit theorem lesson explained, so real gaps become easier to see. That is the same power story as in the lesson on power. A study with only three evenings per stall has little power. A study with thirty evenings per stall would catch much smaller differences.
When you read a research paper, the ANOVA is often shown as a small table with rows for "between," "within" and "total," and columns for the sum of squares, degrees of freedom, mean square, F and the p-value. Now you know what every number in that table means, and you can check the arithmetic yourself.
A common mistake: ignoring the assumptions
ANOVA works best under three conditions. The observations should be independent, such as separate evenings, not the same person counted twice. Each group's values should be roughly bell shaped. And the spread inside each group should be roughly the same. Our three stalls fit that last rule perfectly, with each one's within-group sum of squares equal to 8. If one stall's tips swung wildly and another's hardly moved, the pooled "noise" figure would misdescribe both.
A related slip is to run ANOVA on very small groups and trust the result. Our 3 evenings per stall are only a classroom size. Real studies use more, and with such small groups a few unusual evenings could swing the result. The method, however, is the same at any size. Economists use it to compare average earnings across several industries, average prices across several regions, or average test scores across several teaching methods.
Words to know
Analysis of variance (ANOVA) a test of whether three or more group averages could all be equal.
Between-group variation how far the group averages sit from the overall average.
Within-group variation how far individual values sit from their own group's average.
Sum of squares the total of squared distances, used to measure variation.
Mean square a sum of squares divided by its degrees of freedom.
F statistic the mean square between divided by the mean square within.
Follow-up test a comparison of specific pairs after a significant ANOVA, such as Tukey's test.
Check yourself
- Why is running three separate t tests on three groups a problem?
- In the stall example, what does it mean that the within-group sum of squares is 24?
- Compute the F statistic if the between-group sum of squares is 60 with 3 groups, and the within-group sum of squares is 36 with 9 values in total.
- What do the two degrees of freedom numbers equal in question 3?
- An ANOVA is significant. A classmate says, "So every group differs from every other group." Explain why this is not justified.
- If all group averages were exactly equal, what would the between-group sum of squares be, and what would F be?
Show the answers
- Each test carries its own 5% false alarm risk, so with three tests the chance of at least one false alarm grows to about 14%; ANOVA asks one question with one risk.
- It totals the squared distances of the 9 evening values from their own stall's average, so it measures the ordinary day-to-day noise inside the stalls.
- Between df = 3 − 1 = 2, so MS between = 60 ÷ 2 = 30; within df = 9 − 3 = 6, so MS within = 36 ÷ 6 = 6; F = 30 ÷ 6 = 5.
- The two numbers are 2 (groups minus 1) and 6 (values minus groups).
- A significant ANOVA only says the averages are not all equal; one group might differ while the others match, and a follow-up test is needed to find which pairs differ.
- Every group average would sit on the grand average, so the between-group sum of squares would be 0 and F would be 0.