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.

304050607080LessMoreTest scoreStudy timeMethod AMethod B
Method A cell meansMethod B cell meansDots: 10 students per cell
Two-way ANOVA table
SourceSum of squaresSSdfMean squareMSFp
Method160.01160.010.000.003
Study time640.01640.040.00< 0.001
Method × time40.0140.02.500.123
Within cells576.03616.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?

40506070LessMoreMean test scoreStudy timeMethod AMethod B

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.

ψ^=(yˉB,more−yˉA,more)−(yˉB,less−yˉA,less),Fmethod×time=nψ^2/4MSwithin\hat\psi = \big(\htmlClass{term-theta}{\bar y_{B,\text{more}} - \bar y_{A,\text{more}}}\big) - \big(\htmlClass{term-b}{\bar y_{B,\text{less}} - \bar y_{A,\text{less}}}\big), \qquad F_{\text{method} \times \text{time}} = \frac{n\hat\psi^{2}/4}{\htmlClass{term-c}{MS_{\text{within}}}}
ψ^=(yˉB,more−yˉA,more)−(yˉB,less−yˉA,less),Fmethod×time=nψ^2/4MSwithin\begin{aligned} \hat\psi &= \big(\htmlClass{term-theta}{\bar y_{B,\text{more}} - \bar y_{A,\text{more}}}\big) \\ &\quad - \big(\htmlClass{term-b}{\bar y_{B,\text{less}} - \bar y_{A,\text{less}}}\big), \\[6pt] F_{\text{method} \times \text{time}} &= \frac{n\hat\psi^{2}/4}{\htmlClass{term-c}{MS_{\text{within}}}} \end{aligned}

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