Two-way (factorial) ANOVA
Real studies often vary more than one thing at once: a treatment and a dose, a teaching method and a class size. A two-way (factorial) ANOVA analyses both factors together. It also answers a question no pair of one-way ANOVAs can: does the effect of one factor change depending on the other?
Three questions in one analysis
- Main effect of factor A: averaging over B, do the levels of A differ?
- Main effect of factor B: averaging over A, do the levels of B differ?
- A × B interaction: does the effect of A depend on the level of B?
Assumptions
The same as one-way ANOVA: independent observations, a continuous outcome, roughly normal residuals, and similar variances across all the cells (each combination of factor levels). With unequal cell sizes, use Type III sums of squares (the SPSS default), which test each effect adjusted for the others.
Worked example: vitamin C, delivery method and dose
The ToothGrowth experiment gave 60 guinea pigs vitamin C by one of two methods (orange juice, OJ, or ascorbic acid, VC) at one of three doses (0.5, 1 or 2 mg), 10 animals per combination. The t-test lesson compared the methods alone and found no evidence of a difference (p = .060). What happens when dose is included?
Step 1: run the model
Design: factorial ANOVA (Type III sums of squares, sum-to-zero contrasts) Outcome: len Factor: supp (2 levels) Factor: dose (3 levels) N: 60 Effect: supp || ss=205.3500, df=1, ms=205.3500, F=15.5720, p=0.0002312, pes=0.2238, ci=[0.0586, 0.4021] Effect: dose || ss=2426.4343, df=2, ms=1213.2172, F=92.0000, p=4.046e-18, pes=0.7731, ci=[0.6617, 0.8382] Effect: supp × dose || ss=108.3190, df=2, ms=54.1595, F=4.1070, p=0.02186, pes=0.1320, ci=[0.0015, 0.2950] Residual: ss=712.1060, df=54, ms=13.1871 R-squared: 0.7937 Cell: supp=VC, dose=0.5 || mean=7.9800, sd=2.7466, n=10 Cell: supp=VC, dose=1 || mean=16.7700, sd=2.5153, n=10 Cell: supp=VC, dose=2 || mean=26.1400, sd=4.7977, n=10 Cell: supp=OJ, dose=0.5 || mean=13.2300, sd=4.4597, n=10 Cell: supp=OJ, dose=1 || mean=22.7000, sd=3.9110, n=10 Cell: supp=OJ, dose=2 || mean=26.0600, sd=2.6551, n=10 Levene (residuals by cell): F=1.7086, df=5, 54, p=0.1484 Residual normality p: 0.8455
> options(contrasts = c("contr.sum", "contr.poly"))
> fit <- lm(len ~ supp * dose, data = tg)
> drop1(fit, scope = ~ ., test = "F")
Df Sum of Sq RSS AIC F value Pr(>F)
<none> 712.11 160.43
supp 1 205.35 917.46 173.64 15.572 0.0002312 ***
dose 2 2426.43 3138.54 245.43 92.000 < 2.2e-16 ***
supp:dose 2 108.32 820.43 164.93 4.107 0.0218603 *Identical sums of squares, F values and p-values. Analytika’s test suite checks this exact model against R.
Step 2: check the assumptions
Levene’s test on the residuals across the six cells gives p = .148, and residual normality gives p = .846. No problems.
Step 3: start with the interaction
Supplement × dose: F(2, 54) = 4.11, p = .022, partial η² = .13. The effect of supplement depends on dose. The cell means show how:
| Dose | Orange juice | Ascorbic acid | Difference (OJ − VC) |
|---|---|---|---|
| 0.5 mg | 13.23 | 7.98 | 5.25 |
| 1 mg | 22.70 | 16.77 | 5.93 |
| 2 mg | 26.06 | 26.14 | −0.08 |
Orange juice beats ascorbic acid at the two lower doses, but the advantage disappears at 2 mg. Simple-effects tests confirm it: supplement matters at 0.5 mg (F(1, 54) = 10.45, p = .002) and 1 mg (F(1, 54) = 13.33, p < .001), but not at 2 mg (F(1, 54) = 0.00, p = .961).
Step 4: the main effects, in light of the interaction
- Dose: F(2, 54) = 92.00, p < .001, partial η² = .77. Tooth growth rises strongly with dose, for both supplements.
- Supplement: F(1, 54) = 15.57, p < .001, partial η² = .22. On average, orange juice produces more growth. But the interaction shows this average hides “a clear advantage at low doses, none at 2 mg”, so the main effect alone would mislead.
Notice what happened to the supplement comparison. On its own the t-test found no evidence of a difference. With dose in the model, its large share of the variation is accounted for, and the supplement effect becomes clear. Leaving out a factor that matters can hide real effects.
Step 5: report it (APA 7)
A 2 (supplement) × 3 (dose) between-subjects ANOVA showed main effects of dose, F(2, 54) = 92.00, p < .001, η²p = .77, and supplement, F(1, 54) = 15.57, p < .001, η²p = .22, qualified by a supplement × dose interaction, F(2, 54) = 4.11, p = .022, η²p = .13. Orange juice produced more tooth growth than ascorbic acid at 0.5 mg and 1 mg, but not at 2 mg.
Include a table or plot of the cell means. An interaction plot (dose on the x-axis, one line per supplement) shows the converging lines at once.
Interpreting interactions
- Parallel lines on an interaction plot mean no interaction: each factor’s effect is the same at every level of the other.
- Converging or diverging lines mean the effect grows or shrinks, as here.
- Crossing lines mean the effect reverses direction. Main effects are then almost meaningless on their own.
The same idea in regression is called moderation. See moderation and interactions.
How to run it
- SPSS: Analyze → General Linear Model → Univariate. Add both factors, and request plots, simple effects (EM Means with “compare simple main effects”) and effect size estimates.
- R:
car::Anova(lm(y ~ A * B, data = df), type = 3)with sum-to-zero contrasts, or theafexpackage. - Analytika: ask, for example, “does tooth growth depend on supplement and dose?”. It fits the factorial ANOVA with Type III sums of squares, partial η² with CIs, cell means, and simple-effects follow-ups.
More in Comparing groups
Try it with the free tools
Run this on your own data
Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.