Mathwords logoMathwords

Two-Way ANOVA — Definition, Formula & Example

Two-Way ANOVA is a test that compares group means when each observation is classified by two factors at once. It tells you whether each factor matters on its own and whether the effect of one factor changes depending on the level of the other.

For factor AA with aa levels, factor BB with bb levels, and nn observations per cell, two-way ANOVA partitions the total sum of squares as SST=SSA+SSB+SSAB+SSE\text{SST} = \text{SS}_A + \text{SS}_B + \text{SS}_{AB} + \text{SSE}, with degrees of freedom a−1a-1, b−1b-1, (a−1)(b−1)(a-1)(b-1), and ab(n−1)ab(n-1). It tests three null hypotheses: all αi=0\alpha_i = 0, all βj=0\beta_j = 0, and all (αβ)ij=0(\alpha\beta)_{ij} = 0. Each uses the statistic F=MSeffect/MSEF = \text{MS}_{\text{effect}}/\text{MSE}, which follows an F-distribution under its null hypothesis when the errors are independent and normal with equal variance.

Key Formula

yijk=μ+αi+βj+(αβ)ij+εijky_{ijk} = \mu + \alpha_i + \beta_j + (\alpha\beta)_{ij} + \varepsilon_{ijk}
Where:
  • yijky_{ijk} = The k-th observation in the cell with level i of factor A and level j of factor B
  • μ\mu = The overall (grand) mean
  • αi\alpha_i = Main effect of level i of factor A
  • βj\beta_j = Main effect of level j of factor B
  • (αβ)ij(\alpha\beta)_{ij} = Interaction effect: the extra shift for that specific combination of levels
  • εijk\varepsilon_{ijk} = Random error, assumed independent and normal with mean 0 and constant variance

Worked Example

Problem: Students study with flashcards (FC) or practice tests (PT) for 1 hour or 3 hours, then take a 25-point quiz. Each cell has two students. FC, 1 hr: 9, 11. FC, 3 hr: 9, 11. PT, 1 hr: 11, 13. PT, 3 hr: 19, 21. Test both main effects and the interaction at α=0.05\alpha = 0.05.
Step 1: Find the means. The cell means are 10, 10, 12, and 20. Here a=b=n=2a = b = n = 2. Average across rows, across columns, and overall.
yˉFC=10,yˉPT=16,yˉ1 hr=11,yˉ3 hr=15,yˉ=13\bar{y}_{\text{FC}} = 10,\quad \bar{y}_{\text{PT}} = 16,\quad \bar{y}_{1\text{ hr}} = 11,\quad \bar{y}_{3\text{ hr}} = 15,\quad \bar{y} = 13
Step 2: Compute the sums of squares. The interaction term for each cell is cell mean minus row mean minus column mean plus grand mean. For these data it is ±2\pm 2 in every cell. Each score sits 1 point from its cell mean, so SSE is 8 with ab(n−1)=4ab(n-1) = 4 degrees of freedom.
SSA=4[(−3)2+32]=72,SSB=4[(−2)2+22]=32,SSAB=2[4⋅22]=32,MSE=84=2\text{SS}_A = 4[(-3)^2 + 3^2] = 72,\quad \text{SS}_B = 4[(-2)^2 + 2^2] = 32,\quad \text{SS}_{AB} = 2[4 \cdot 2^2] = 32,\quad \text{MSE} = \frac{8}{4} = 2
Step 3: Each effect has 1 degree of freedom, so each mean square equals its sum of squares. Divide by MSE and compare each ratio to the critical value F1,4, 0.05=7.71F_{1,4,\,0.05} = 7.71.
FA=722=36,FB=322=16,FAB=322=16F_A = \frac{72}{2} = 36,\quad F_B = \frac{32}{2} = 16,\quad F_{AB} = \frac{32}{2} = 16
Answer: All three F-statistics exceed 7.71, so you reject all three null hypotheses. The significant interaction is the key finding. Extra study time raised practice-test scores by 8 points (12 to 20) but did not change flashcard scores at all (10 to 10). So you cannot describe the effect of study time without naming the method.

Why It Matters

Experiments in psychology, agriculture, and medicine often vary two treatments together, such as drug and dosage or fertilizer and watering schedule. Two-way ANOVA is the standard method for these factorial designs in a college statistics or experimental design course. Its interaction test is the standard way to detect that a treatment works for one group but not another.

Common Mistakes

Mistake: Reporting the main effects as the headline result when the interaction is significant.
Correction: A main effect averages over the other factor. In the example, the 4-point study-time effect is an average of 0 and 8, and it fits neither method. When the interaction is significant, compare the cell means within each level of the other factor instead.

Related Terms