MODULE 08
ANOVA Mathematics Lab
Slow down and calculate: what ANOVA compares, step by step.
Examples on this page use constructed or simulated teaching data, not empirical findings. About the data
- Research question
- Variables (trained here)
- Variable roles
- Measurement levels (trained here)
- Method choice (trained here)
- Statistical logic (trained here)
- SPSS workflow (trained here)
- Output interpretation (trained here)
- Defensible conclusion (trained here)
Understand
One question behind every method
Crosstab
Observed counts versus expected counts under independence.
χ² and Cramér’s V
Correlation
Two variables moving together, relative to their own spread.
Pearson r; Spearman ρ
ANOVA
Distance between group means, relative to variation within groups.
F; η²
Understand
First: the math behind last week’s methods
Reading the formulas
Every formula below is just a recipe. These six symbols are all you need; each step also says the recipe in words.
- “Add up”: do the calculation for every row (person or cell), then sum the results.
- The mean of x (read “x-bar”): add up the values and divide by how many there are.
- Number of cases: n in a group, N in the whole sample.
- Square: multiply a number by itself. It turns negative distances positive, so distances above and below the mean do not cancel out.
- Square root: undoes a square, bringing the result back to the original scale.
- Subscripts name a case: is person i’s value; is person i in group j.
A. From a crosstab to χ² and Cramér’s V
60 students are grouped by how intensively they studied (X) and whether they passed the exam (Y). The question: is passing associated with study intensity?
| Study intensity | Failed | Passed | Row total |
|---|---|---|---|
| Low | 12 | 8 | 20 |
| Medium | 8 | 12 | 20 |
| High | 4 | 16 | 20 |
| Column total | 24 | 36 | 60 |
Step 1: Look at the pattern: row percentages
X is in the rows, so we compute percentages within each row. That tells us what share of each study group passed.
The pass rate rises with study intensity. The rest of the calculation asks two things: could a pattern like this easily arise by chance (χ², p), and how strong is it (V)?
Step 2: Imagine there were no association: expected counts
Overall, 36 of 60 students passed (60%). If study intensity made no difference, every group would have that same pass rate: 60% of 20 = 12 passed and 8 failed in each group. These are the expected counts (E). The general recipe:
Expected counts (E) if there were no association Study intensity Failed Passed Low 8 12 Medium 8 12 High 8 12 Step 3: Measure the gap in every cell, then add up: χ²
For each cell: take observed minus expected, square it (so negative gaps do not cancel positive ones), and divide by the expected count (a gap of 4 matters more when we expected 8 than when we expected 800).
Cell O E O − E (O − E)² (O − E)² / E Low, failed 12 8 4 16 2.000 Low, passed 8 12 −4 16 1.333 Medium, failed 8 8 0 0 0.000 Medium, passed 12 12 0 0 0.000 High, failed 4 8 −4 16 2.000 High, passed 16 12 4 16 1.333 Sum = χ² 6.667 Step 4: Is χ² large enough? Degrees of freedom and p
The degrees of freedom count how many cells can vary freely once the totals are fixed. With 3 rows and 2 columns:
With df = 2, χ² values above 5.991 occur in fewer than 5% of samples when there is no association in the population. Our 6.667 is above that, so p < .05. SPSS gives the exact value (Asymptotic Significance): p = .036.
Optional: for df = 2 only, there is a shortcut that gives the exact p by hand: .
Step 5: How strong? Cramér’s V
χ² grows with the sample size: doubling every count doubles χ². Cramér’s V removes the sample size so the result always lies between 0 (no association) and 1 (perfect association). Here k is the smaller of the number of rows and columns (k = 2), so k − 1 = 1.
What we can say
B. Pearson and Spearman, one row at a time
Six students: weekly study hours (x) and exam score (y). Pearson’s r uses the original numbers; Spearman’s ρ uses only their ranks.
Step 1: Find the two means
Step 2: How far is each student from the means, and do the distances point the same way?
For each student, subtract the mean from both values. Then multiply the two distances. If a student is above average on both (or below on both), the product is positive; if above on one and below on the other, it is negative. Mostly positive products mean a positive association.
Student 1 1 50 −2.5 −10.833 +27.083 6.25 117.361 2 2 52 −1.5 −8.833 +13.250 2.25 78.028 3 3 61 −0.5 +0.167 −0.083 0.25 0.028 4 4 59 +0.5 −1.833 −0.917 0.25 3.361 5 5 68 +1.5 +7.167 +10.750 2.25 51.361 6 6 75 +2.5 +14.167 +35.417 6.25 200.694 Sum 0 0 85.5 17.5 450.833 The distances themselves always add up to 0; that is why we need products and squares.
Step 3: Put the sums into the formula
The top of the fraction is the shared movement of x and y. The bottom rescales it by how much each variable varies on its own, which forces r between −1 and +1.
Step 4: Spearman: replace values with ranks
Rank each variable separately (smallest = 1). Then take the difference between the two ranks for each student (d) and square it.
Student x rank of x y rank of y d d² 1 1 1 50 1 0 0 2 2 2 52 2 0 0 3 3 3 61 4 −1 1 4 4 4 59 3 1 1 5 5 5 68 5 0 0 6 6 6 75 6 0 0 Sum 2 Only students 3 and 4 swap places in the ranking. With no tied values, the recipe is:
With tied values, SPSS gives the tied cases the average of their ranks and computes Pearson’s r on the ranks; the result is then slightly different from this shortcut.
What we can say
Try
Now derive ANOVA from eleven observations
Group 1
45, 61, 53, 73
n = 4
Group 2
20, 14, 17
n = 3
Group 3
22, 32, 26, 21
n = 4
The step-by-step derivation
Step 1: Mean of each group
Add up the values in each group and divide by the number of people in that group.
Step 2: Grand mean: the mean of all eleven people
Add up every observation and divide by N = 11. Note this is not the average of the three group means (33.417), because the groups have different sizes.
Step 3: Two distances for every person
For each person we measure two distances and square them: from their own group mean (how far they are from people in the same group) and from the grand mean (how far they are from everyone). Adding up a squared column gives a sum of squares (SS): the first is SS Within, the second SS Total.
Group 1 45 58.00 −13.00 169 +10.091 101.826 1 61 58.00 +3.00 9 +26.091 680.736 1 53 58.00 −5.00 25 +18.091 327.281 1 73 58.00 +15.00 225 +38.091 1,450.917 2 20 17.00 +3.00 9 −14.909 222.281 2 14 17.00 −3.00 9 −20.909 437.190 2 17 17.00 0.00 0 −17.909 320.736 3 22 25.25 −3.25 10.5625 −12.909 166.645 3 32 25.25 +6.75 45.5625 −2.909 8.463 3 26 25.25 +0.75 0.5625 −8.909 79.372 3 21 25.25 −4.25 18.0625 −13.909 193.463 Sum 0 520.75 0 3,988.909 SS Within is the variation that group membership cannot explain: people differ even inside their own group. SS Total is all the variation in the data.
Step 4: Between-group variation: how far are the group means from the grand mean?
Every person in a group “carries” their group’s distance from the grand mean, so we multiply each squared distance by the group size nj.
Group 1 4 58.00 +23.091 533.190 2,132.760 2 3 17.00 −17.909 320.736 962.207 3 4 25.25 −9.659 93.298 373.192 Sum 3,468.159 Step 5: Check: the two parts add up to the total
This is the core idea of ANOVA: all variation splits into a part between the groups and a part within them.
Step 6: Degrees of freedom
Sums of squares grow simply because more numbers are added up. To compare them fairly, we divide by their degrees of freedom: the number of independent pieces of information in each part. With k = 3 groups and N = 11 people:
Step 7: Mean squares and the F ratio
A mean square (MS) is a sum of squares divided by its degrees of freedom: an average squared distance. F compares the two averages. If the groups did not differ in the population, the group means would scatter only about as much as individual noise allows, and F would be close to 1. A large F means the group means are much further apart than the within-group scatter would suggest.
Step 8: Is F large enough? The p-value
For F with df = (2, 8), values above 4.459 occur in fewer than 5% of samples if the population means are equal; values above 18.49 occur in fewer than 0.1%. Our F = 26.64 is above both, so p < .001. The exact value is p = .00029; SPSS rounds it and prints Sig. = .000, which you report as p < .001.
Step 9: Effect size: eta squared
What share of all the variation lies between the groups?
About 87% of the variation in this sample is associated with group membership. That is a description of the sample, not proof that the groups cause the differences.
| Sum of Squares | df | Mean Square | F | Sig. | |
|---|---|---|---|---|---|
| Between Groups | 3,468.159 | 2 | 1,734.080 | 26.640 | .000 |
| Within Groups | 520.750 | 8 | 65.094 | ||
| Total | 3,988.909 | 10 |
Now change the data
Move the groups. Watch the sums of squares.
The starting values reproduce the 11 observations of the ANOVA calculation video. Moving the sliders creates a teaching simulation, not new survey data.
Moves Group 1 up and Group 2 down (negative values move them towards each other).
Moves individuals towards or away from their own group mean.
Dots = observations; thick lines = group means; dashed line = grand mean (34.91).
Between SS 3,468.16, within SS 520.75, total SS 3,988.91, F 26.64 with df 2 and 8, eta squared 0.869.
Within SS
520.75
Between SS
3,468.16
F (df 2, 8)
26.64
Eta squared
0.869
| Source | SS | df | MS |
|---|---|---|---|
| Between groups | 3,468.16 | 2 | 1,734.08 |
| Within groups | 520.75 | 8 | 65.09 |
| Total | 3,988.91 | 10 | — |
Check the identity: 3,468.16 + 520.75 = 3,988.91. Separating the group means increases the between-group SS; spreading individuals around their own group mean increases the within-group SS, and F falls. This simulation does not compute p-values; the classical F test also relies on its assumptions.
Live recalculation of the original data: F = 26.640, η² = 0.869.
SPSS
Translate the calculation into an SPSS decision
- Scale outcome (Y) and one categorical group variable (X): one-way ANOVA.
- SPSS: Analyze → Compare Means → One-Way ANOVA. Request Descriptives, homogeneity of variance, and Welch.
- Check sample sizes, missing-value codes, outliers, independence and the within-group distribution.
- Use Levene as a diagnostic, not as proof of equal variances. If group variances differ materially, Welch’s ANOVA is a useful alternative.
- An omnibus significant result says at least one group mean differs; use suitable post-hoc comparisons to locate differences (e.g. Tukey for the standard setting, Games–Howell under unequal variances).
- Report the means, N, F or Welch test, degrees of freedom, p, and an appropriate effect size.
Do not mix up these four designs
Independent t-test: two independent groups, one outcome.
Paired t-test: two measurements of the same people (or matched pairs).
One-way ANOVA: one grouping factor, typically three or more independent groups (two also works).
Two-way ANOVA: two grouping factors; evaluates main effects and potentially their interaction.
Full sample vs subsamples: a stratified/control-variable analysis, not the definition of one-way versus two-way ANOVA.
A non-significant Levene test does not prove homoscedasticity. Overlapping separate 95% group-mean confidence intervals are not a reliable substitute for an adjusted pairwise comparison. Keep inference separate from effect size and causal claims.
Test yourself
Exit ticket: explain, don’t just calculate
Mastery check
Explain the calculation
The three groups have n = 4, 3, 4 and means 58, 17 and 25.25. Why is the grand mean 34.909 and not (58 + 17 + 25.25) / 3 = 33.417?
For extra interactive exercises, revisit crosstabs, correlation, or t-tests.