Concept map / ANOVA, contrasts and interactions
Share
Analysis of variance, contrasts, and interactions
Split score variation into a method effect, a study-time effect, and their interaction, and test the interaction as a contrast.
1Does Method B’s lead depend on study time?
Forty students learn with Method A or Method B and then study for a shorter or a longer time, ten in each of the four combinations, or cells. Analysis of variance (ANOVA) splits the variation in their scores into parts for method, study time, their interaction, and the spread within cells. An interaction means the effect of method changes with study time.
Each part becomes a mean square, and its F ratio compares it with the within-cell mean square, as in the F distribution lesson. Set Method B’s lead at each study time and watch the lines, then change the spread within cells and watch the F ratios.
| Source | Sum of squaresSS | df | Mean squareMS | F | p |
|---|---|---|---|---|---|
| Method | 160.0 | 1 | 160.0 | 10.00 | 0.003 |
| Study time | 640.0 | 1 | 640.0 | 40.00 | < 0.001 |
| Method × time | 40.0 | 1 | 40.0 | 2.50 | 0.123 |
| Within cells | 576.0 | 36 | 16.0 |
Method B is ahead by 2 points with less study time and ahead by 6 with more, so the interaction contrast is 4.0 points (95% confidence interval −1.1 to 9.1). The interaction F is 2.50 with p = 0.123. Averaged over study time, Method B is ahead by 4.0 points.
More controls
2When the lines cross, is there a method effect?
In a second study with 10 students per cell and the same spread (s = 4), Method B is 4 points behind Method A with less study time and 4 points ahead with more. What will the two-way ANOVA report for the main effect of method?
3The interaction is a difference of differences
The interaction contrast ψ is how much more Method B leads with more study time than with less. With two levels of each factor it carries the whole interaction. Its sum of squares is nψ²/4, with n students per cell, and dividing by the within-cell mean square gives the F ratio in the table. Point at a term to see its part of the chart.
Here = 6 − (2) = 4.0, so F = 10 × 4.0² / 4 / 16.00 = 2.50 on 1 and 36 degrees of freedom (p = 0.123). Its standard error is √(16.00 × 4 / 10) = 2.53, and the 95% interval is −1.1 to 9.1. The within-cell mean square is s², because every cell's scores have standard deviation s.
4Check yourself
The tasks use the sliders in section 1 and tick themselves when you meet them.
- Make the lines parallel while Method B stays at least 4 points ahead. The interaction sum of squares drops to zero and the method effect stays.Now: B leads by 2 (less) and 6 (more), interaction F 2.50
- Keep the interaction contrast at exactly 4 points and make it significant at the 5% level by changing only the spread within cells.Now: Contrast 4.0, spread 4.0, p = 0.123
- Build a crossover with no main effect of method: Method B behind with less study time, ahead by the same amount with more, and the interaction significant at the 5% level.Now: Method main effect 4.0, interaction p = 0.123
5The same table in R
The snippet rebuilds the page’s starting data from the same ten offsets, so every number in the ANOVA table matches the lab. aov with sum-to-zero contrasts gives the table. lm with the default treatment contrasts gives the interaction coefficient, which is the difference of differences ψ: 4, with a confidence interval from −1.13 to 9.13.
Two-way ANOVA and an interaction contrastShow the code
# Ten offsets with mean 0 and SD 1, reused in every cell
z <- c(-1.6, -1, -0.7, -0.6, -0.3, 0.3, 0.6, 0.7, 1, 1.6)
d <- expand.grid(i = 1:10, time = c("less", "more"),
method = c("A", "B"))
# Cell means at the page's starting sliders, spread s = 4
mu <- c(A.less = 50, A.more = 56, B.less = 52, B.more = 62)
d$score <- mu[paste(d$method, d$time, sep = ".")] + 4 * z[d$i]
# Two-way ANOVA with sum-to-zero contrasts
sum0 <- list(method = contr.sum, time = contr.sum)
fit <- aov(score ~ method * time, data = d, contrasts = sum0)
summary(fit)
# Treatment contrasts: the interaction coefficient is the
# difference of differences, psi
lin <- lm(score ~ method * time, data = d)
round(coef(lin)["methodB:timemore"], 2)
round(confint(lin)["methodB:timemore", ], 2)Uses base R only.
What the interaction tells you
- In a balanced design the sums of squares for method, study time, the interaction and the within-cell spread add up to the total.
- Each F ratio divides an effect’s mean square by the within-cell mean square, so doubling the spread within cells divides every F by four.
- In a 2 × 2 design the interaction is one contrast, ψ, the change in Method B’s lead from one study time to the other. Its standard error is √(MS within × 4 / n), so it can be reported with a confidence interval as well as a p-value.
- A main effect averages over the other factor. In a crossover the method effects cancel, so the main effect of method is zero while the methods differ by 4 points at each study time. Report the lead at each study time instead.
- The same split of variance into sources underlies generalizability theory, where the sources are persons, tasks and raters, and mixed-effects models, where some sources are random.
Recommended reading
- Introductory Statistics 2eBarbara Illowsky and Susan Dean§13.2, sums of squares, degrees of freedom, and the F ratio
- STAT 502: Analysis of Variance and Design of ExperimentsPenn State Department of StatisticsCourse notes · Lesson 5, multifactor ANOVA and interactions