17 One-Way ANOVA
By the end of this chapter you will be able to:
- Explain what a significant omnibus F does — and does not — tell you.
- Run a one-way ANOVA in R and read the output, including computing η².
- Explain why post-hoc tests are needed, and run Tukey HSD.
- Identify when one-way ANOVA is not appropriate (e.g., a within-subjects design).
Three sections of the same course: one taught by lecture, one by discussion, one by lab. The same final goes out, and three different averages come back. You could run three separate t-tests — lecture vs. discussion, lecture vs. lab, discussion vs. lab — but every extra test is another chance of a false alarm. ANOVA asks the question once: do these three means differ by more than chance can explain?
ANOVA — Analysis of Variance — generalizes the t-test to three or more groups. A one-way ANOVA tests whether a single categorical variable with three or more levels produces differences in a continuous outcome.
Despite the name, ANOVA compares means. It’s called Analysis of Variance because it does so by comparing two kinds of variability — between-group variance vs. within-group variance.
Before the formal machinery below, work through the ANOVA preview activity — the same “why not three separate t-tests” question above, answered start to finish with a real dataset, before F, df, or η² are ever named.
17.1 When to use it
Use one-way ANOVA when you have:
- One continuous outcome variable.
- One categorical predictor (factor) with three or more levels.
- Groups that are independent of each other.
Examples:
- Do exam scores differ across three teaching methods (lecture, discussion, lab)?
- Does reaction time differ across four caffeine doses?
- Does student satisfaction differ across freshman, sophomore, junior, senior?
If you have only two groups, use the independent t-test (Chapter 15). One-way ANOVA on two groups reproduces the equal-variance (Student’s) t-test exactly — but this book’s default is Welch’s t, which does not assume equal variances, so the two will not match to the decimal.
If you have two categorical predictors, use two-way ANOVA (Chapter 18).
If the same people are measured under all three conditions (for example, each participant is tested with no, low, and high caffeine), the groups are not independent, so one-way ANOVA is the wrong test. Each person’s scores are linked across conditions, just as in a paired t-test. Use repeated-measures ANOVA (Chapter 19).
17.2 Hypotheses
- \(H_0\): All group means are equal (\(\mu_1 = \mu_2 = \mu_3 = \ldots\)).
- \(H_1\): At least one group mean differs.
A significant ANOVA tells you that at least one group differs from at least one other group. It does not tell you which groups differ. For that, follow up with post-hoc tests.
17.3 Key terms
| Term | Meaning |
|---|---|
| Between-group variance | Variability between group means — what your predictor explains |
| Within-group variance | Variability within each group — random noise |
| F-statistic | Between / within. Big F → groups differ relative to noise |
| p-value | Probability of seeing an F at least this large if \(H_0\) were true |
| \(\eta^2\) (eta-squared) | Proportion of total variance explained by the factor |
17.4 Where F comes from
Pick any student’s score and ask how far it is from the grand mean, the average of all 30 students. That distance splits into two pieces:
- Between: how far that student’s group mean is from the grand mean. This is the part the teaching method explains.
- Within: how far the student is from their own group’s mean. This is the part the method doesn’t explain: ordinary person-to-person noise.
Square those distances and add them up across all students, and the pieces add up exactly:
\[ \text{SS}_\text{total} = \text{SS}_\text{between} + \text{SS}_\text{within} \]
In the worked example below: 1257.0 = 360.9 + 896.1. That’s the Sum Sq column in R’s table (R labels the within row Residuals).
Why square. Raw distances cancel: scores above the grand mean and below it add to exactly 0, every time. Squaring makes every distance count, and squared distances are the version that splits cleanly into between + within. It’s the same reason variance is the average squared distance from the mean (Chapter 3).
Why divide by df. A sum gets bigger just from having more pieces in it. Dividing each SS by its df turns it into an average, the Mean Sq, so the between and within rows can be compared fairly.
Why F is near 1 when nothing is going on. If teaching method does nothing, the group means still differ a little, just from noise. Then the between Mean Sq and the within Mean Sq are both measuring the same noise, and their ratio lands near 1. F grows only when the group means are further apart than that noise can explain. Here F = 180.43 / 33.19 = 5.44: the between variation is about five and a half times what noise alone would produce.
η² uses the same pieces. η² = SSbetween / SStotal = 360.9 / 1257.0 = .29: teaching method accounts for 29% of all the variation in scores.
Coming up in regression. The same split returns in Chapter 22. There, a line replaces the group means: “explained” is how far the line’s predictions are from the mean, and “leftover” is how far each score is from the line.
17.5 Assumptions
- Independence. Observations are independent within and between groups.
- Normality of residuals. The residuals from the ANOVA model should be approximately normal. Check after fitting the model. See Chapter 10 for why this is residuals, not raw data.
- Homogeneity of variance. Groups have similar spread. Levene’s test checks this formally,
car::leveneTest(score ~ method, data = data); the diagnosticplot(model)shows it visually. - Continuous outcome. Interval or ratio scale.
Before running the model, try the Rossman/Chance randomization test for multiple groups.
Predict first: looking at your group means, which group do you expect to differ most from the others? If group labels were randomly shuffled across participants, how often would you expect an F statistic as large as the one you observe? Run the simulation and check.
17.6 R syntax
The core command:
model <- aov(outcome ~ group, data = data)
summary(model)aov() fits the model; summary() produces the ANOVA table with the F-test.
17.6.1 Worked example
You compare exam scores across three teaching methods, 10 students each.
# Step 0: Load the data
data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch17_teaching_methods.csv")
# Step 1: Inspect
str(data)
table(data$method) # group sizes
data$method <- as.factor(data$method) # ensure factor
# Step 2: Visualize
boxplot(score ~ method, data = data)
library(ggplot2)
ggplot(data, aes(x = method, y = score)) +
geom_boxplot() +
geom_jitter(width = 0.1, alpha = 0.5)
# Step 3: Fit the model
model <- aov(score ~ method, data = data)
# Step 4: Check assumptions
shapiro.test(residuals(model))
plot(model, which = 2) # Q-Q plot of residuals
# Step 5: Read the ANOVA table
summary(model)
# Step 6: Descriptives
aggregate(score ~ method, data = data, FUN = mean)
aggregate(score ~ method, data = data, FUN = sd)
# Step 7: If significant, follow up with Tukey HSD
TukeyHSD(model)17.6.2 Reading the ANOVA table
Df Sum Sq Mean Sq F value Pr(>F)
method 2 360.9 180.43 5.437 0.0104 *
Residuals 27 896.1 33.19
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
methodrow — between-group source.Df = 2— degrees of freedom for the factor (number of groups minus 1).Sum Sq = 360.9— sum of squared deviations explained by the factor.Mean Sq = 180.43—Sum Sq / Df. The between-group variance estimate.
Residualsrow — within-group source.Df = 27— total n minus number of groups.Mean Sq = 33.19— within-group variance estimate.
F value = 5.437— ratio of the two mean squares (180.43 / 33.19).Pr(>F) = 0.0104— the p-value. Significant at \(\alpha = .05\).
Report the F statistic as \(F(\text{between df}, \text{within df}) = F\). Here: \(F(2, 27) = 5.44\).
A significant one-way ANOVA tells you that at least one group mean differs from at least one other. It does not tell you which groups differ, or how many pairs are different. Two groups could drive the entire effect while the third is indistinguishable from both. You need post-hoc tests (Tukey HSD) to identify which specific comparisons are significant. Reporting “all three groups differed significantly” based solely on F is not justified.
Open ANOVA: Signal, Noise, and Interaction — Part A. Make the Step 1 prediction before moving the three group means and the within-group spread, then watch SSbetween, SSwithin, F, p, \(\eta^2\), and the Tukey intervals update together. The opening case is deliberately significant overall even though only one pairwise interval excludes 0.
Read this output carefully. The R code that produced it is not shown.
Df Sum Sq Mean Sq F value Pr(>F)
diet 3 1104 368.0 11.24 3.48e-06 ***
Residuals 76 2488 32.7
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
- How many diet groups are being compared? How do you know from the output?
- What is the F-statistic, and what does it represent conceptually?
- Is the result statistically significant at α = .05? What is the appropriate next step?
- Calculate \(\eta^2\) from the values in the table. Show your work.
- Interpret that effect size. Is it small, medium, or large by convention?
- Write one APA 7 sentence reporting this result.
- A classmate says “since F is significant, all four diets produce different weight loss from each other.” What is wrong with this conclusion?
17.7 Effect size: eta-squared (\(\eta^2\))
\(\eta^2\) is the proportion of total variance explained by the factor:
\[ \eta^2 = \frac{\text{SS}_\text{between}}{\text{SS}_\text{total}} \]
library(effectsize)
eta_squared(model)Interpretation:
| \(\eta^2\) | Effect size |
|---|---|
| 0.01 | Small |
| 0.06 | Medium |
| 0.14 | Large |
(Sometimes you’ll see partial eta-squared (\(\eta_p^2\)) reported instead. In a one-way ANOVA they’re identical. In multi-factor ANOVA, partial eta-squared is conventional — see Chapter 18.)
17.8 Post-hoc tests: Tukey HSD
A significant ANOVA tells you some groups differ. To find which, run Tukey’s Honestly Significant Difference test:
TukeyHSD(model)Tukey compares every pair of groups. With three groups, that’s three comparisons (A vs. B, A vs. C, B vs. C). Each test at α = .05 has a 5% chance of a false positive. Run three of them and the chance that at least one is a false positive climbs to about 14%. Tukey fixes this by making each comparison a little stricter (wider confidence intervals, larger p-values), so the chance of any false positive across the whole set stays at 5%. That’s what “95% family-wise confidence level” at the top of the output means.
Output for the worked example:
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = score ~ method, data = data)
$method
diff lwr upr p adj
B-A 3.1 -3.287943 9.487943 0.4615338
C-A 8.4 2.012057 14.787943 0.0081826
C-B 5.3 -1.087943 11.687943 0.1180510
Each row is a pairwise comparison. diff is the mean difference; lwr and upr are the 95% CI; p adj is the p-value adjusted for multiple comparisons. With Tukey HSD you don’t need to apply additional corrections — the test does it for you.
Notice the pattern: the omnibus F was significant, but only one of the three pairs (C vs. A) differs significantly. B sits between A and C and is not distinguishable from either. This is exactly the misconception box above in action — a significant F does not mean every group differs from every other.
17.9 Reporting
A one-way ANOVA revealed a significant effect of teaching method on exam scores, F(2, 27) = 5.44, p = .010, \(\eta^2\) = .29 (large effect). Tukey HSD comparisons showed that method C (M = 76.60, SD = 6.00) scored significantly higher than method A (M = 68.20, SD = 5.87; p = .008). Method B (M = 71.30, SD = 5.40) did not differ significantly from either A (p = .462) or C (p = .118).
If non-significant — from the Baby Dataset (after the Chapter 7 prep script), mothers’ height by age group, aov(height ~ age_group, data = babies):
A one-way ANOVA indicated no significant difference in mothers’ height across the three age groups, F(2, 1210) = 0.14, p = .867, \(\eta^2\) < .01 (negligible).
Effect size reporting: APA 7 recommends reporting \(\eta^2\) regardless of whether the result is significant — the magnitude of an effect matters whether or not it clears a significance threshold. Some instructors and courses use a convention of omitting \(\eta^2\) for non-significant results; this course follows APA 7 and expects effect sizes to be reported in all cases.
17.10 When assumptions are violated
| Problem | Fix |
|---|---|
| Non-normal residuals | Transform the outcome (Chapter 12), or use Kruskal-Wallis (Chapter 13) |
| Unequal variances | oneway.test(score ~ method, data = data) — Welch’s ANOVA |
| Severe outliers | Inspect; consider robust ANOVA or non-parametric |
| Small sample sizes | Lean on the visual; consider Kruskal-Wallis |
17.11 Common mistakes
| Wrong | Right |
|---|---|
Running aov() with groups coded as numbers (1, 2, 3) — R fits a straight line with 1 df and gives no warning |
Convert to factor first: data$group <- as.factor(data$group) |
| Checking normality of the raw outcome | Check residuals: shapiro.test(residuals(model)) |
| Running separate t-tests for every pair instead of ANOVA + Tukey | Always do the omnibus ANOVA first, then post-hoc |
| Forgetting to correct for multiple comparisons | Use TukeyHSD() (auto-corrects), not pairwise.t.test(..., p.adjust.method = "none") |
| Reporting “the means differ” without the F statistic | Report F(df1, df2) = value, p = value |
17.12 Quick reference
| Element | R code |
|---|---|
| Fit ANOVA | model <- aov(y ~ group, data = data) |
| ANOVA table | summary(model) |
| Tukey post-hoc | TukeyHSD(model) |
| Effect size | library(effectsize); eta_squared(model) |
| Welch’s ANOVA (unequal var.) | oneway.test(y ~ group, data = data) |
| Non-parametric alternative | kruskal.test(y ~ group, data = data) |
| Group descriptives | aggregate(y ~ group, data = data, FUN = mean) |
17.13 The same test, different disciplines
One-way ANOVA applies whenever you are comparing a continuous outcome across three or more independent groups — regardless of what those groups represent.
| Discipline | Typical comparison | Outcome variable |
|---|---|---|
| Psychology | Three or more treatment, condition, or diagnostic groups | Depression score, memory accuracy, reaction time |
| Biology | Three or more species, strains, or treatment levels | Growth rate, enzyme activity, body mass |
| Sociology | Three or more demographic, occupational, or regional groups | Income, years of education, reported wellbeing |
Next: adding a second factor.
Core idea: One-way ANOVA tests whether any group means differ across three or more groups. A significant F-test tells you something differs — not which groups. Post-hoc tests (Tukey HSD) answer the follow-up question.
You should understand:
- Why you cannot use multiple t-tests instead of ANOVA (inflated Type I error)
- What the F-statistic is: between-group variance divided by within-group variance
- Why a significant omnibus F must precede post-hoc comparisons
- What η² measures: the proportion of total variance explained by group membership
You should be able to do in R:
- Fit the model:
model <- aov(score ~ group, data = data) - Results table:
summary(model) - Post-hoc:
TukeyHSD(model) - Effect size:
library(effectsize); eta_squared(model) - Check normality:
shapiro.test(residuals(model))
Plain-language check: ANOVA gives F(2, 57) = 4.32, p = .018. Can you conclude that all three groups differ from each other? What is the correct next step?
The one mistake to avoid: Running Tukey post-hoc tests without first checking whether the omnibus F is significant. Post-hoc tests are only valid as follow-ups to a significant overall effect.
Practice: A researcher tests four teaching methods (lecture, discussion, flipped, online) on exam performance with 15 students per group. The ANOVA gives p = .03. Write the next two lines of R code and explain what each one tells you.
Key terms from this chapter are defined in the Glossary.
Practice the skills from this chapter using real data: Assignment 4 — One-Way ANOVA
A worked walkthrough plus five practice problems: ANOVA in R: A Beginner’s Guide.