Two-way ANOVA setup (balanced 2×3 with replication)
A two-way anova analyzes one quantitative response under two categorical factors and tests: (1) the main effect of factor A, (2) the main effect of factor B, and (3) the A×B interaction. The example below is a balanced factorial design with \(a=2\) levels of A, \(b=3\) levels of B, and \(r=3\) replicates per cell.
Context (example): Plant height under two factors
- Factor A: Fertilizer (A1 = none, A2 = new)
- Factor B: Light (B1 = low, B2 = medium, B3 = high)
- Response: Height (cm)
Standard conditions: independent observations, approximately normal errors within each cell, and constant variance across cells.
| Factor A \ Factor B | B1 (low) | B2 (medium) | B3 (high) |
|---|---|---|---|
| A1 (none) | 9, 10, 11 | 13, 14, 15 | 17, 18, 19 |
| A2 (new) | 11, 12, 13 | 18, 19, 20 | 21, 22, 23 |
Model and hypotheses
With response \(y_{ijk}\) at A level \(i\), B level \(j\), replicate \(k\), a common fixed-effects model is:
\[ y_{ijk}=\mu+\alpha_i+\beta_j+(\alpha\beta)_{ij}+\varepsilon_{ijk}, \quad \varepsilon_{ijk}\sim N(0,\sigma^2). \]
Three hypothesis tests in two-way ANOVA:
- Main effect A: \(H_0:\alpha_1=\alpha_2=\cdots=\alpha_a=0\)
- Main effect B: \(H_0:\beta_1=\beta_2=\cdots=\beta_b=0\)
- Interaction A×B: \(H_0:(\alpha\beta)_{ij}=0\) for all \(i,j\)
Step 1: Cell means, marginal means, and grand mean
In a balanced design, computations are cleanly expressed using cell means \(\bar{y}_{ij\cdot}\), factor means \(\bar{y}_{i\cdot\cdot}\), \(\bar{y}_{\cdot j \cdot}\), and the grand mean \(\bar{y}_{\cdot\cdot\cdot}\).
| Cell mean \(\bar{y}_{ij\cdot}\) | B1 | B2 | B3 | Row mean \(\bar{y}_{i\cdot\cdot}\) |
|---|---|---|---|---|
| A1 | 10.0 | 14.0 | 18.0 | 14.0 |
| A2 | 12.0 | 19.0 | 22.0 | 17.6667 |
| Column mean \(\bar{y}_{\cdot j \cdot}\) | 11.0 | 16.5 | 20.0 | — |
Grand mean: \[ \bar{y}_{\cdot\cdot\cdot}=\frac{10+14+18+12+19+22}{6}=15.8333\ldots \]
Step 2: Sums of squares (balanced two-way ANOVA)
With \(a=2\), \(b=3\), \(r=3\), total \(N=a\cdot b\cdot r=18\).
Between-factor (main effect) sums of squares
\[ SS_A=b\cdot r \cdot \sum_{i=1}^{a}\left(\bar{y}_{i\cdot\cdot}-\bar{y}_{\cdot\cdot\cdot}\right)^2, \quad SS_B=a\cdot r \cdot \sum_{j=1}^{b}\left(\bar{y}_{\cdot j \cdot}-\bar{y}_{\cdot\cdot\cdot}\right)^2. \]
Using \(b\cdot r=9\) and \(a\cdot r=6\): \[ SS_A=60.5, \qquad SS_B=247.0. \]
Interaction sum of squares
\[ SS_{AB}=r\cdot \sum_{i=1}^{a}\sum_{j=1}^{b} \left(\bar{y}_{ij\cdot}-\bar{y}_{i\cdot\cdot}-\bar{y}_{\cdot j \cdot}+\bar{y}_{\cdot\cdot\cdot}\right)^2. \]
For this dataset: \[ SS_{AB}=7.0. \]
Error and total sums of squares
\[ SS_E=\sum_{i=1}^{a}\sum_{j=1}^{b}\sum_{k=1}^{r}\left(y_{ijk}-\bar{y}_{ij\cdot}\right)^2, \qquad SS_T=SS_A+SS_B+SS_{AB}+SS_E. \]
Each cell \((9,10,11)\), \((13,14,15)\), … has within-cell squared deviations summing to 2, so \[ SS_E=6\cdot 2=12, \qquad SS_T=60.5+247.0+7.0+12.0=326.5. \]
Step 3: Degrees of freedom
\[ df_A=a-1=1,\quad df_B=b-1=2,\quad df_{AB}=(a-1)(b-1)=2,\quad df_E=a\cdot b\cdot (r-1)=12,\quad df_T=N-1=17. \]
Step 4: ANOVA table and F tests
Mean squares are \(MS=\dfrac{SS}{df}\). Each effect is tested by \(F=\dfrac{MS_{\text{effect}}}{MS_E}\).
| Source | SS | df | MS | F | p-value (approx.) |
|---|---|---|---|---|---|
| Factor A | 60.5 | 1 | 60.5 | 60.5 | < 0.001 |
| Factor B | 247.0 | 2 | 123.5 | 123.5 | < 0.001 |
| Interaction A×B | 7.0 | 2 | 3.5 | 3.5 | 0.064 |
| Error | 12.0 | 12 | 1.0 | — | — |
| Total | 326.5 | 17 | — | — | — |
Decisions at \(\alpha=0.05\):
- Factor A: reject \(H_0\) (strong evidence of an A main effect).
- Factor B: reject \(H_0\) (strong evidence of a B main effect).
- Interaction A×B: do not reject \(H_0\) (interaction not significant at 0.05 for this example).
When the interaction is significant, interpretation typically emphasizes simple effects (comparisons within levels) rather than main effects alone.
Visualization: interaction plot of cell means
The interaction plot connects the mean response across B levels for each A level. Non-parallel lines indicate a potential interaction; nearly parallel lines indicate weak interaction.