Two-way ANOVA analyses a numeric response measured under every combination of two categorical factors. It tests three separate questions: does factor A matter on average, does factor B matter on average, and does the effect of one factor depend on the level of the other (the interaction). The interaction is the reason to run a two-factor design rather than two separate one-way analyses.
Model and degrees of freedom
Let factor A have $a$ levels, factor B have $b$ levels, and each of the $ab$ cells have $r$ replicates (a balanced design). For replicate $k$ in cell $(i,j)$:
Here $\alpha_i$ and $\beta_j$ are main effects and $(\alpha\beta)_{ij}$ is the interaction, each constrained to sum to zero across its levels. The tests are $H_{0,A}:\alpha_i=0$, $H_{0,B}:\beta_j=0$, and $H_{0,AB}:(\alpha\beta)_{ij}=0$ for all cells. Writing $\bar{y}$ for the grand mean, $\bar{y}_{i\cdot\cdot}$ and $\bar{y}_{\cdot j\cdot}$ for the level means, and $\bar{y}_{ij}$ for the cell means, the balanced sums of squares are:
| Source | Sum of squares | df | Mean square | F |
|---|---|---|---|---|
| Factor A | $SS_A$ | $a-1$ | $MS_A=SS_A/(a-1)$ | $MS_A/MS_E$ |
| Factor B | $SS_B$ | $b-1$ | $MS_B=SS_B/(b-1)$ | $MS_B/MS_E$ |
| A × B | $SS_{AB}$ | $(a-1)(b-1)$ | $MS_{AB}=SS_{AB}/[(a-1)(b-1)]$ | $MS_{AB}/MS_E$ |
| Error | $SS_E$ | $ab(r-1)$ | $MS_E=SS_E/[ab(r-1)]$ | — |
| Total | $SS_T$ | $abr-1$ | — | — |
In a balanced fixed-effects design, $SS_T=SS_A+SS_B+SS_{AB}+SS_E$. Each F-statistic is compared with an $F$ distribution whose numerator df is the row's df and whose denominator df is $ab(r-1)$.
Worked example
A process runs at two temperatures (A: Low, High) with two gas mixtures (B: X, Y), with $r=3$ wafers per cell, so $a=b=2$ and $N=12$. The cell responses are Low/X $=10,12,11$; Low/Y $=14,16,15$; High/X $=13,15,14$; High/Y $=25,27,26$. The cell means are $11,\,15,\,14,\,26$, the temperature means are $13$ (Low) and $20$ (High), the mixture means are $12.5$ (X) and $20.5$ (Y), and the grand mean is $16.5$.
Then $SS_A=6[(13-16.5)^2+(20-16.5)^2]=147$ and $SS_B=6[(12.5-16.5)^2+(20.5-16.5)^2]=192$. The four interaction residuals $\bar{y}_{ij}-\bar{y}_{i\cdot\cdot}-\bar{y}_{\cdot j\cdot}+\bar{y}$ are $2,-2,-2,2$, so $SS_{AB}=3(4+4+4+4)=48$. Each cell has within-cell sum of squares $2$, so $SS_E=8$, and the total is $147+192+48+8=395$. With $MS_E=8/8=1$, the F-statistics are $F_A=147$, $F_B=192$, and $F_{AB}=48$, each on $(1,8)$ degrees of freedom, with p-values of approximately $2.0\times10^{-6}$, $7.1\times10^{-7}$ and $1.2\times10^{-4}$.
Reading an interaction
The interaction here is real: switching from mixture X to mixture Y raises the mean by $15-11=4$ at Low temperature but by $26-14=12$ at High temperature. The difference between those simple effects is $8$, and the interaction $F$-test says that gap is too large to be noise. When an interaction is significant, do not summarise a factor by its average effect alone. Compare levels of one factor within each level of the other, using planned contrasts or adjusted simple-effect tests.
Assumptions and design cautions
- Observations must be independent, with residuals roughly normal and similar variance across cells. Check residuals by cell.
- Replication is required to separate interaction from error. With $r=1$ there is no within-cell variation, so $SS_E$ has $0$ df and the interaction cannot be tested without a further assumption such as a negligible interaction.
- The sums-of-squares identity above holds for balanced data. With unequal cell counts, Type I, II and III sums of squares can give different answers, so state which was used.
- The formulas shown are for fixed factors. If a factor is random, such as lots or tools sampled from a larger population, some F-tests use a different denominator mean square.
- Report cell means, an effect size such as partial $\eta^2$, and confidence intervals for the contrasts that matter. A significant F-test alone does not show that the difference is large enough to matter in production.