Examples follow the book’s section numbers.
Chapter 14 extends the multivariate approach to higher-order
experimental designs, specifically focusing on designs with multiple
within-subjects factors and mixed (split-plot) designs containing both
within- and between-subjects factors. By transforming repeated measures
into composite difference ()
variables, the text demonstrates how to test main effects and
interactions without relying on the restrictive sphericity assumption
required by the traditional univariate mixed-model approach. Once
omnibus multivariate tests establish statistical significance, the
chapter details how to rigorously probe these findings using simple
effects tests, interaction contrasts, and confidence intervals. It also
addresses the unique analytical needs of longitudinal randomized
designs, emphasizing the superiority of MANCOVA over repeated measures
ANOVA for evaluating treatment effects over time while controlling for
baseline scores. Finally, the chapter equips researchers with practical
tools for power analysis and sample size planning, demonstrating how
different methodological choices and contrast specifications impact
statistical power in these complex designs.
14.2 — Two Within-Subjects Factors, Each with Two Levels
To explore the multivariate approach for a within-subjects design, we
rely on the perceptual experiment data introduced in the text (Table
14.1, p. 768). In this study, 10 participants are measured on their
reaction times to recognize a target letter. There are two
within-subjects factors: Noise (Absent vs. Present) and
Angle (0 degrees vs. 8 degrees).
Let’s begin by loading the data for this example.
data(chapter_14_table_1)
str(chapter_14_table_1)
'data.frame': 10 obs. of 4 variables:
$ Absent0 : int 420 420 480 420 540 360 480 480 540 480
$ Absent8 : int 480 480 540 540 540 360 600 660 540 540
$ Present0: int 480 360 660 480 480 360 540 540 480 540
$ Present8: int 780 600 780 900 720 540 840 900 780 780
Absent0 Absent8 Present0 Present8
1 420 480 480 780
2 420 480 360 600
3 480 540 660 780
4 420 540 480 900
5 540 540 480 720
6 360 360 360 540
7 480 600 540 840
8 480 660 540 900
9 540 540 480 780
10 480 540 540 780
# Cell means, to check the data against the book.
colMeans(chapter_14_table_1)
Absent0 Absent8 Present0 Present8
462 528 492 762
#> 462, 528, 492, 762 — matches the Mean row of Table 14.1 (p. 768) and the
#> cell means of Table 14.2 (p. 769).
Table 14.2 (p. 769) also reports the marginal means, which are what
the two main effects compare. They follow from the cell means.
# Marginal means for Angle (averaging over Noise) and for Noise (averaging over Angle).
with(chapter_14_table_1, c(
Angle0 = mean(c(Absent0, Present0)),
Angle8 = mean(c(Absent8, Present8))
))
Angle0 Angle8
477 645
#> 477 and 645 — matches Table 14.2 (p. 769).
with(chapter_14_table_1, c(
Noise_Absent = mean(c(Absent0, Absent8)),
Noise_Present = mean(c(Present0, Present8))
))
Noise_Absent Noise_Present
495 627
#> 495 and 627 — matches Table 14.2 (p. 769).
Because both factors have exactly two levels, any main effect or
interaction will only have 1 degree of freedom. This means we can test
each omnibus effect individually by constructing a single difference
score ( variable) for each
one.
(Main Effect of Angle):
Averages across the Noise factor and subtracts the 0-degree angle scores
from the 8-degree angle scores.
(Main Effect of Noise):
Averages across the Angle factor and subtracts the Noise-Absent scores
from the Noise-Present scores.
(Angle Noise Interaction): Measures how
the Angle effect changes depending on the presence or absence of
Noise.
14.2.1 — Formation of Main-Effect Variables
# Create difference scores, per the rationale given in the book.
# D1 is Equation 14.1 (p. 770) and D2 is Equation 14.9 (p. 771).
chapter_14_table_1$D1 <- .5*(chapter_14_table_1$Absent8 + chapter_14_table_1$Present8) - .5*(chapter_14_table_1$Absent0 + chapter_14_table_1$Present0)
chapter_14_table_1$D2 <- .5*(chapter_14_table_1$Present0 + chapter_14_table_1$Present8) - .5*(chapter_14_table_1$Absent0 + chapter_14_table_1$Absent8)
14.2.2 — Formation of Interaction Variables
The interaction difference score is the difference between the Angle
effect when Noise is present and the Angle effect when Noise is absent
(Equation 14.10, p. 771).
chapter_14_table_1$D3 <- (chapter_14_table_1$Present8 - chapter_14_table_1$Absent8) - (chapter_14_table_1$Present0 - chapter_14_table_1$Absent0)
chapter_14_table_1
Absent0 Absent8 Present0 Present8 D1 D2 D3
1 420 480 480 780 180 180 240
2 420 480 360 600 150 30 180
3 480 540 660 780 90 210 60
4 420 540 480 900 270 210 300
5 540 540 480 720 120 60 240
6 360 360 360 540 90 90 180
7 480 600 540 840 210 150 180
8 480 660 540 900 270 150 180
9 540 540 480 780 150 90 300
10 480 540 540 780 150 150 180
We can summarize these new difference scores to check the means and
variability.
# dplyr is loaded above as part of tidyverse.
chapter_14_table_1_Summary <- chapter_14_table_1 %>%
summarize(
Mean_D1 = mean(D1),
Mean_D2 = mean(D2),
Mean_D3 = mean(D3),
SD_D1 = sd(D1),
SD_D2 = sd(D2),
SD_D3 = sd(D3)
)
chapter_14_table_1_Summary
Mean_D1 Mean_D2 Mean_D3 SD_D1 SD_D2 SD_D3
1 168 132 204 65.11528 61.96773 70.42727
#> Means 168, 132, and 204 — match the Mean row of Table 14.3 (p. 769).
# Or more simply using base R
summary(chapter_14_table_1[, c("D1", "D2", "D3")])
D1 D2 D3
Min. : 90.0 Min. : 30.0 Min. : 60
1st Qu.:127.5 1st Qu.: 90.0 1st Qu.:180
Median :150.0 Median :150.0 Median :180
Mean :168.0 Mean :132.0 Mean :204
3rd Qu.:202.5 3rd Qu.:172.5 3rd Qu.:240
Max. :270.0 Max. :210.0 Max. :300
Testing the hypotheses
The null hypothesis for each effect stipulates that the population
mean of its respective variable
is equal to zero ().
One way of testing the
variables is a one-sample -test of
each difference score against a null value of 0. Because each effect has
1 numerator degree of freedom, each here is the square root of the
corresponding reported in the
book.
t.test(
x = chapter_14_table_1$D1,
mu = 0,
alternative = "two.sided",
conf.level = 0.95
)
One Sample t-test
data: chapter_14_table_1$D1
t = 8.1588, df = 9, p-value = 1.891e-05
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
121.4193 214.5807
sample estimates:
mean of x
168
#> t = 8.1588, and 8.1588^2 = 66.57 — matches the F on p. 771.
t.test(
x = chapter_14_table_1$D2,
mu = 0,
alternative = "two.sided",
conf.level = 0.95
)
One Sample t-test
data: chapter_14_table_1$D2
t = 6.7361, df = 9, p-value = 8.498e-05
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
87.67095 176.32905
sample estimates:
mean of x
132
#> t = 6.7361, and 6.7361^2 = 45.375 — matches the F on p. 771.
t.test(
x = chapter_14_table_1$D3,
mu = 0,
alternative = "two.sided",
conf.level = 0.95
)
One Sample t-test
data: chapter_14_table_1$D3
t = 9.1599, df = 9, p-value = 7.391e-06
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
153.6194 254.3806
sample estimates:
mean of x
204
#> t = 9.1599, and 9.1599^2 = 83.90 — matches the F on p. 771.
Equivalently, the book computes each effect by hand with Equation
14.8 (p. 770), . Plugging the actual sample values for each variable into that formula reproduces
the book’s values exactly:
n <- nrow(chapter_14_table_1)
# The ingredients the book reports for D1 on p. 771.
c(n = n, Dbar = mean(chapter_14_table_1$D1), s2 = var(chapter_14_table_1$D1))
n Dbar s2
10 168 4240
#> n = 10, Dbar = 168, s^2 = 4,240 — matches p. 771.
# Equation 14.8 applied to each D variable.
F_D1 <- n * mean(chapter_14_table_1$D1)^2 / var(chapter_14_table_1$D1)
F_D2 <- n * mean(chapter_14_table_1$D2)^2 / var(chapter_14_table_1$D2)
F_D3 <- n * mean(chapter_14_table_1$D3)^2 / var(chapter_14_table_1$D3)
c(Angle_D1 = F_D1, Noise_D2 = F_D2, Interaction_D3 = F_D3)
Angle_D1 Noise_D2 Interaction_D3
66.56604 45.37500 83.90323
#> Angle D1: F = 66.57 — matches book p. 771.
#> Noise D2: F = 45.375 — matches book p. 771.
#> Inter. D3: F = 83.90 — matches book p. 771.
# Each observed F is referred to a critical F with 1 and n - 1 degrees of freedom.
qf(p = 1 - .05, df1 = 1, df2 = n - 1)
[1] 5.117355
#> 5.12 — matches the critical value quoted on p. 771.
The textbook explicitly frames these hypothesis tests as a comparison
between a full model and a restricted model. We can map this framework
onto R code.
Below, we fit two linear models for the Angle main effect (). The first is the Full Model (which
includes an intercept to estimate the mean), and the second is the
Restricted Model (which forces the intercept to 0). We then compare the
two using the anova() function to reproduce the -test in the book.
# Full Model
D1_Model_Mean <- lm(D1 ~ 1, data=chapter_14_table_1)
summary(D1_Model_Mean)
Call:
lm(formula = D1 ~ 1, data = chapter_14_table_1)
Residuals:
Min 1Q Median 3Q Max
-78.0 -40.5 -18.0 34.5 102.0
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 168.00 20.59 8.159 1.89e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 65.12 on 9 degrees of freedom
# Restricted Model
D1_Model_Null <- lm(D1 ~ 0, data=chapter_14_table_1)
# Compare the restricted model to the full model
anova(D1_Model_Null, D1_Model_Mean)
Analysis of Variance Table
Model 1: D1 ~ 0
Model 2: D1 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 320400
2 9 38160 1 282240 66.566 1.891e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> The two RSS columns are E(R) and E(F) of Equations 14.6 and 14.5 (p. 770),
#> and the model comparison gives F = 66.57 — matches book p. 771.
Now that we have confirmed the main effect of Angle (D1), we can
apply this exact same full-versus-restricted model comparison logic to
test the main effect of Noise (D2) and the Angle x Noise interaction
(D3).
# Models for D2 (Noise Main Effect)
D2_Model_Mean <- lm(D2 ~ 1, data=chapter_14_table_1)
D2_Model_Null <- lm(D2 ~ 0, data=chapter_14_table_1)
anova(D2_Model_Null, D2_Model_Mean)
Analysis of Variance Table
Model 1: D2 ~ 0
Model 2: D2 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 208800
2 9 34560 1 174240 45.375 8.498e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 45.375 for the Noise main effect — matches book p. 771.
# Models for D3 (Angle x Noise Interaction)
D3_Model_Mean <- lm(D3 ~ 1, data=chapter_14_table_1)
D3_Model_Null <- lm(D3 ~ 0, data=chapter_14_table_1)
anova(D3_Model_Null, D3_Model_Mean)
Analysis of Variance Table
Model 1: D3 ~ 0
Model 2: D3 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 460800
2 9 44640 1 416160 83.903 7.391e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 83.90 for the Angle x Noise interaction — matches book p. 771.
14.2.3 — Relationship to the Mixed-Model Approach
It is important to note that because this is a design, the main effects and
the interaction all have exactly 1 numerator degree of freedom.
Consequently, the sphericity assumption required by the traditional
mixed-model approach is necessarily satisfied. The book makes the point
explicitly on p. 772: when every factor has only two levels, the
multivariate and mixed-model approaches are identical, provided the
mixed-model approach uses an error term of the form . The degrees
of freedom agree as well, so there is nothing to choose between the two
approaches here.
14.3 — Multivariate Analysis of Two-Way Within-Subjects Designs
To motivate the analysis of a general within-subjects design, we continue with the
perceptual experiment, but we now reinstate the 4-degree angle
condition. This gives us a design (Noise: Absent vs. Present; Angle: 0, 4, and 8
degrees). Following the book, Angle is the factor, with levels, and Noise is the factor, with levels. These are the data of Table
14.4 (p. 774), which are the same data as Table 12.1 so that the
multivariate and mixed-model analyses can be compared.
data(chapter_14_table_4)
str(chapter_14_table_4)
'data.frame': 10 obs. of 6 variables:
$ Absent0 : int 420 420 480 420 540 360 480 480 540 480
$ Absent4 : int 420 480 480 540 660 420 480 600 600 420
$ Absent8 : int 480 480 540 540 540 360 600 660 540 540
$ Present0: int 480 360 660 480 480 360 540 540 480 540
$ Present4: int 600 480 780 780 660 480 720 720 720 660
$ Present8: int 780 600 780 900 720 540 840 900 780 780
Absent0 Absent4 Absent8 Present0 Present4 Present8
1 420 420 480 480 600 780
2 420 480 480 360 480 600
3 480 480 540 660 780 780
4 420 540 540 480 780 900
5 540 660 540 480 660 720
6 360 420 360 360 480 540
7 480 480 600 540 720 840
8 480 600 660 540 720 900
9 540 600 540 480 720 780
10 480 420 540 540 660 780
# Cell means, to check the data against the book.
colMeans(chapter_14_table_4)
Absent0 Absent4 Absent8 Present0 Present4 Present8
462 510 528 492 660 762
#> 462, 510, 528, 492, 660, 762 — matches the Mean row of Table 14.4 (p. 774).
The six cell means are worth looking at before any test is run,
because the whole argument of the section is about the pattern
they form.
cell_means <- chapter_14_table_4 |>
summarize(across(Absent0:Present8, mean)) |>
pivot_longer(everything(), names_to = "cell", values_to = "Mean_RT") |>
mutate(
Noise = if_else(str_starts(cell, "Absent"), "Absent", "Present"),
Angle = as.numeric(str_remove(cell, "Absent|Present"))
) |>
mutate(Noise = factor(Noise, levels = c("Absent", "Present")))
cell_means
# A tibble: 6 × 4
cell Mean_RT Noise Angle
<chr> <dbl> <fct> <dbl>
1 Absent0 462 Absent 0
2 Absent4 510 Absent 4
3 Absent8 528 Absent 8
4 Present0 492 Present 0
5 Present4 660 Present 4
6 Present8 762 Present 8
ggplot(cell_means, aes(x = Angle, y = Mean_RT, color = Noise, shape = Noise)) +
geom_line(linewidth = 0.8) +
geom_point(size = 3) +
scale_x_continuous(breaks = c(0, 4, 8)) +
labs(
x = "Angle (degrees off center)",
y = "Mean reaction time (ms)",
color = "Noise",
shape = "Noise"
)
14.3.1 — Formation of Main-Effect Variables
Because the Angle factor has three levels, we must form separate variables to test its main effect.
Since Angle is quantitative, we will use coefficients for linear (-1, 0,
1) and quadratic (1, -2, 1) trends to create and , respectively, averaging across the
Noise factor (Equations 14.14 and 14.15, p. 774).
Because the Noise factor only has two levels, we only need variable () to test its main effect, which
simply finds the difference between the average Noise Present and Noise
Absent scores (Equation 14.16, p. 775).
# Define Angle Main Effect D variables (Linear and Quadratic Trends)
chapter_14_table_4$D1 <- -1*(.5*(chapter_14_table_4$Absent0 + chapter_14_table_4$Present0)) + 0*(.5*(chapter_14_table_4$Absent4 + chapter_14_table_4$Present4)) + 1*(.5*(chapter_14_table_4$Absent8 + chapter_14_table_4$Present8))
chapter_14_table_4$D2 <- 1*(.5*(chapter_14_table_4$Absent0 + chapter_14_table_4$Present0)) - 2*(.5*(chapter_14_table_4$Absent4 + chapter_14_table_4$Present4)) + 1*(.5*(chapter_14_table_4$Absent8 + chapter_14_table_4$Present8))
# Define Noise Main Effect D variable
chapter_14_table_4$D3 <- (1/3)*(chapter_14_table_4$Present0 + chapter_14_table_4$Present4 + chapter_14_table_4$Present8) - (1/3)*(chapter_14_table_4$Absent0 + chapter_14_table_4$Absent4 + chapter_14_table_4$Absent8)
14.3.3 — Omnibus Tests—Multivariate Significance Tests
To test the main effect of Angle, we must test the null hypothesis
that both and equal zero simultaneously. The book
does this by building the error matrices and for the full and restricted models
and comparing their determinants with Equation 14.28 (p. 777). Nothing
but base R is needed for that, and it is worth doing once so the
machinery is visible:
D_A <- as.matrix(chapter_14_table_4[, c("D1", "D2")])
n <- nrow(D_A)
# E(F): deviations from the sample means of D1 and D2.
E_F_A <- crossprod(sweep(D_A, 2, colMeans(D_A)))
# E(R): deviations from zero, which is what the null hypothesis asserts.
E_R_A <- crossprod(D_A)
E_F_A
D1 D2
D1 38160 3240
D2 3240 77760
#> 38,160 and 77,760 on the diagonal, 3,240 off it — matches E(F) on p. 778.
E_R_A
D1 D2
D1 320400 -77400
D2 -77400 100800
#> 320,400 and 100,800 on the diagonal, -77,400 off it — matches E(R) on p. 778.
c(det_E_F = det(E_F_A), det_E_R = det(E_R_A))
det_E_F det_E_R
2956824000 26305560000
#> 2,956,824,000 and 26,305,560,000 — match the determinants on p. 778.
# Equation 14.28, with a = 3 levels of Angle.
a <- 3
F_A <- ((det(E_R_A) - det(E_F_A)) / (a - 1)) / (det(E_F_A) / (n - a + 1))
c(F_A = F_A, p = pf(F_A, df1 = a - 1, df2 = n - a + 1, lower.tail = FALSE))
F_A p
31.586237125 0.000159629
#> F = 31.59 with 2 and 8 df, p = .0002 — matches book p. 778.
R’s manova() does the same determinant arithmetic for
us, and anova() on the fitted object reports it as Wilks’s
Lambda with the same approximate .
# Multivariate test for the Main Effect of Angle (A)
MANOVA_A <- manova(cbind(D1, D2) ~ 1, data=chapter_14_table_4)
anova(MANOVA_A, test="Wilks")
Analysis of Variance Table
Df Wilks approx F num Df den Df Pr(>F)
(Intercept) 1 0.1124 31.586 2 8 0.0001596 ***
Residuals 9
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> approx F = 31.586 with 2 and 8 df — matches the hand computation above and
#> book p. 778. Wilks's Lambda is det E(F) / det E(R) = 0.1124.
Here we test the main effect of Noise (B). Because there is only a
single variable for that
effect, the matrices have one row and one column, their determinants are
just the single numbers they contain, and the multivariate test
collapses to a univariate one. A model comparison or a one-sample -test does the job.
# Approach 1: Model Comparison (ANOVA)
D3_Model_Mean <- aov(D3 ~ 1, data=chapter_14_table_4)
D3_Model_Null <- aov(D3 ~ 0, data=chapter_14_table_4)
anova(D3_Model_Null, D3_Model_Mean)
Analysis of Variance Table
Model 1: D3 ~ 0
Model 2: D3 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 241200
2 9 50760 1 190440 33.766 0.000256 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> RSS of 241,200 and 50,760 are E(R) = [241,200] and E(F) = [50,760] on p. 778,
#> and F = 33.77 — matches book p. 778.
# Approach 2: One-Sample t-test
t.test(
x = chapter_14_table_4$D3,
mu = 0,
alternative = "two.sided",
conf.level = 0.95
)
One Sample t-test
data: chapter_14_table_4$D3
t = 5.8108, df = 9, p-value = 0.000256
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
84.27674 191.72326
sample estimates:
mean of x
138
#> t = 5.8108, and 5.8108^2 = 33.77 — matches the F on p. 778.
Testing the Angle Noise
interaction requires testing
and simultaneously, so we
return to manova() and Equation 14.30 (p. 778).
# Multivariate test for the Interaction
MANOVA_Interaction <- manova(cbind(D4, D5) ~ 1, data=chapter_14_table_4)
anova(MANOVA_Interaction, test="Wilks")
Analysis of Variance Table
Df Wilks approx F num Df den Df Pr(>F)
(Intercept) 1 0.081777 44.914 2 8 4.472e-05 ***
Residuals 9
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> approx F = 44.914 with 2 and 8 df, p = .00004 — matches book p. 778.
Alternatively, we can use the Anova() function from the
car package (loaded above), which reports the same tests
with Pillai’s trace as its default statistic. With a single group every
multivariate criterion gives the same , so the two routes agree exactly.
# Notice we use lm() instead of manova() when passing to car::Anova()
Model_A_lm <- lm(cbind(D1, D2) ~ 1, data=chapter_14_table_4)
Model_B_lm <- lm(D3 ~ 1, data=chapter_14_table_4)
Model_Int_lm <- lm(cbind(D4, D5) ~ 1, data=chapter_14_table_4)
Anova(Model_A_lm, type="III")
Type III MANOVA Tests: Pillai test statistic
Df test stat approx F num Df den Df Pr(>F)
(Intercept) 1 0.8876 31.586 2 8 0.0001596 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> approx F = 31.586 — matches book p. 778.
Anova(Model_B_lm, type="III")
Anova Table (Type III tests)
Response: D3
Sum Sq Df F value Pr(>F)
(Intercept) 190440 1 33.766 0.000256 ***
Residuals 50760 9
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 33.766 — matches book p. 778.
Anova(Model_Int_lm, type="III")
Type III MANOVA Tests: Pillai test statistic
Df test stat approx F num Df den Df Pr(>F)
(Intercept) 1 0.91822 44.914 2 8 4.472e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> approx F = 44.914 — matches book p. 778.
14.4 — Measures of Effect
As noted in the text, while the multivariate approach is recommended
for hypothesis testing, the mixed-model formulation of omega squared
() is still preferred
for estimating effect sizes because it treats individual differences
between subjects as a source of total variance, just as between-subjects
designs do. Those components do not come from the variables; they come from the
mixed-model analysis of Chapter 12, which we can fit here with
aov() and an Error() stratum.
# Long format, with Noise and Angle spelled out level by level.
chapter_14_table_4$Subject <- factor(seq_len(nrow(chapter_14_table_4)))
within_long <- chapter_14_table_4 |>
select(Subject, Absent0:Present8) |>
pivot_longer(Absent0:Present8, names_to = "cell", values_to = "Score") |>
mutate(Noise = case_when(
str_starts(cell, "Absent") ~ "Absent",
str_starts(cell, "Present") ~ "Present"
)) |>
mutate(Angle = case_when(
str_ends(cell, "0") ~ "0",
str_ends(cell, "4") ~ "4",
str_ends(cell, "8") ~ "8"
)) |>
mutate(
Noise = factor(Noise, levels = c("Absent", "Present")),
Angle = factor(Angle, levels = c("0", "4", "8"))
)
# The mixed-model (univariate) analysis of these same data: Angle is A, Noise is B.
within_aov <- aov(Score ~ Angle * Noise + Error(Subject / (Angle * Noise)),
data = within_long)
summary(within_aov)
Error: Subject
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 9 292140 32460
Error: Subject:Angle
Df Sum Sq Mean Sq F value Pr(>F)
Angle 2 289920 144960 40.72 2.09e-07 ***
Residuals 18 64080 3560
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Error: Subject:Noise
Df Sum Sq Mean Sq F value Pr(>F)
Noise 1 285660 285660 33.77 0.000256 ***
Residuals 9 76140 8460
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Error: Subject:Angle:Noise
Df Sum Sq Mean Sq F value Pr(>F)
Angle:Noise 2 105120 52560 45.31 9.42e-08 ***
Residuals 18 20880 1160
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> A = 289,920 / 2 / 144,960 / F = 40.72; A x S = 64,080 / 18 / 3,560
#> B = 285,660 / 1 / 285,660 / F = 33.77; B x S = 76,140 / 9 / 8,460
#> A x B = 105,120 / 2 / 52,560 / F = 45.31; A x B x S = 20,880 / 18 / 1,160
#> — matches Table 12.5 (p. 650). The subjects stratum gives SS_S = 292,140 and
#> MS_S = 32,460, the two extra values the book supplies on p. 779.
Equation 12.6, repeated on p. 779, is . Pulling the pieces out of the fitted object gives the
book’s three values.
within_sum <- summary(within_aov)
# Subjects stratum, whose single line is the subjects effect.
SS_S <- within_sum$`Error: Subject`[[1]][1, "Sum Sq"]
MS_S <- within_sum$`Error: Subject`[[1]][1, "Mean Sq"]
c(SS_S = SS_S, MS_S = MS_S)
SS_S MS_S
292140 32460
#> 292,140 and 32,460 — matches the values stated on p. 779.
# One stratum per within-subjects effect, each with its own effect x S error line.
omega_squared_within <- function(stratum, df_effect) {
tab <- within_sum[[stratum]][[1]]
eff <- 1L # the effect is the first row of its stratum
err <- nrow(tab) # the effect x S term is the Residuals row
df_effect * (tab[eff, "Mean Sq"] - tab[err, "Mean Sq"]) /
(tab[eff, "Sum Sq"] + tab[err, "Sum Sq"] + SS_S + MS_S)
}
c(
Angle_A = omega_squared_within("Error: Subject:Angle", df_effect = 2),
Noise_B = omega_squared_within("Error: Subject:Noise", df_effect = 1),
Angle_x_Noise = omega_squared_within("Error: Subject:Angle:Noise", df_effect = 2)
)
Angle_A Noise_B Angle_x_Noise
0.4167403 0.4038462 0.2281403
#> .42, .40, and .23 — matches the omega squared values on p. 779.
In DMAR: the sphericity-adjusted tests in one table
The mixed-model values above
assume sphericity, which is exactly the assumption the multivariate
approach of this chapter avoids. aov() does not report the
Greenhouse–Geisser or Huynh–Feldt corrections, so a reader comparing the
two approaches has to compute separately. The DMAR function
anova_within_two_way() reports the uncorrected test and the
three adjusted versions together, along with partial , from the same long data
frame.
anova_within_two_way(
data = as.data.frame(within_long),
outcome = "Score",
factor_A = "Angle",
factor_B = "Noise",
subject = "Subject"
)
| A |
none |
40.719 |
2 |
18 |
< 0.0001 |
NA |
0.819 |
| A |
Greenhouse-Geisser |
40.719 |
1.923 |
17.309 |
< 0.0001 |
0.962 |
0.819 |
| A |
Huynh-Feldt |
40.719 |
2 |
18 |
< 0.0001 |
1.000 |
0.819 |
| A |
lower_bound |
40.719 |
1 |
9 |
0.0001 |
0.500 |
0.819 |
| B |
none |
33.766 |
1 |
9 |
0.0003 |
NA |
0.790 |
| B |
Greenhouse-Geisser |
33.766 |
1 |
9 |
0.0003 |
1.000 |
0.790 |
| B |
Huynh-Feldt |
33.766 |
1 |
9 |
0.0003 |
1.000 |
0.790 |
| B |
lower_bound |
33.766 |
1 |
9 |
0.0003 |
1.000 |
0.790 |
| A:B |
none |
45.310 |
2 |
18 |
< 0.0001 |
NA |
0.834 |
| A:B |
Greenhouse-Geisser |
45.310 |
1.808 |
16.272 |
< 0.0001 |
0.904 |
0.834 |
| A:B |
Huynh-Feldt |
45.310 |
2 |
18 |
< 0.0001 |
1.000 |
0.834 |
| A:B |
lower_bound |
45.310 |
1 |
9 |
< 0.0001 |
0.500 |
0.834 |
#> The "none" rows give F = 40.719 (A), 33.766 (B), and 45.310 (A:B), the same
#> values as the aov() output above and as Table 12.5 (p. 650). The adjusted
#> rows are what aov() does not provide.
The contrast with the multivariate tests of Section 14.3 is the point
of the chapter: for the Noise main effect, which has 1 numerator degree
of freedom, the two approaches agree exactly (). For the Angle main effect and
the interaction, which have 2, they do not ( versus , and versus ), because the multivariate approach
buys its freedom from the sphericity assumption with a different error
structure.
With the effect sizes in hand, we follow up the significant omnibus
tests with contrasts and simple effects.
14.4.1 — Further Investigation of Main Effects
Because the Angle main effect was significant and has three levels,
we may want to test specific comparisons of its marginal means. In
Section 14.3, we already created a variable that represents the
quadratic trend of the Angle main effect.
We can test it individually by comparing it to a null model (where
the intercept is 0).
# Test the quadratic trend of Angle (D2)
D2_Model_Mean <- lm(D2 ~ 1, data=chapter_14_table_4)
D2_Model_Null <- lm(D2 ~ 0, data=chapter_14_table_4)
anova(D2_Model_Null, D2_Model_Mean)
Analysis of Variance Table
Model 1: D2 ~ 0
Model 2: D2 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 100800
2 9 77760 1 23040 2.6667 0.1369
#> F = 2.67 — matches book p. 779.
# The ingredients the book reports for this contrast on p. 779.
c(Dbar = mean(chapter_14_table_4$D2), s2 = var(chapter_14_table_4$D2))
Dbar s2
-48 8640
#> Dbar = -48 and s^2 = 8,640 — match p. 779, and 10(-48)^2 / 8,640 = 2.67.
# Critical value for a single planned comparison, 1 and n - 1 df.
qf(p = 1 - .05, df1 = 1, df2 = nrow(chapter_14_table_4) - 1)
[1] 5.117355
#> 5.12 — matches the critical value on p. 780, so the quadratic trend is
#> not statistically significant.
The observed of 2.67 is not
statistically significant, and it is the same the mixed-model approach of Chapter 12
produces for the quadratic angle trend when a separate error term is
used (p. 779).
14.4.2 — Further Investigation of an Interaction—Simple Effects
Because we found a significant Angle Noise interaction, the next
logical step is to test simple effects. First, we will test the simple
effect of Noise at each individual level of Angle (0, 4, and 8
degrees).
To do this, we create three new variables (, , and ), each representing the difference
between Noise Present and Noise Absent at a specific angle.
# Simple effects of Noise at specific Angles
chapter_14_table_4$D6 <- chapter_14_table_4$Present0 - chapter_14_table_4$Absent0
chapter_14_table_4$D7 <- chapter_14_table_4$Present4 - chapter_14_table_4$Absent4
chapter_14_table_4$D8 <- chapter_14_table_4$Present8 - chapter_14_table_4$Absent8
# Test each simple effect of Noise
anova(lm(D6 ~ 0, data=chapter_14_table_4), lm(D6 ~ 1, data=chapter_14_table_4))
Analysis of Variance Table
Model 1: D6 ~ 0
Model 2: D6 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 61200
2 9 52200 1 9000 1.5517 0.2443
#> F = 1.55 — matches book p. 781.
anova(lm(D7 ~ 0, data=chapter_14_table_4), lm(D7 ~ 1, data=chapter_14_table_4))
Analysis of Variance Table
Model 1: D7 ~ 0
Model 2: D7 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 327600
2 9 102600 1 225000 19.737 0.001617 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 19.74 — matches book p. 781.
anova(lm(D8 ~ 0, data=chapter_14_table_4), lm(D8 ~ 1, data=chapter_14_table_4))
Analysis of Variance Table
Model 1: D8 ~ 0
Model 2: D8 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 586800
2 9 39240 1 547560 125.59 1.376e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 125.59 — matches book p. 781.
The output matches the text: the effect of Noise at 0 degrees () is not significant, but the
effect of Noise intensifies at 4 degrees () and 8 degrees (), all three on p. 781.
Next, we test the simple effect of Angle at each individual level of
Noise. Because Angle has three levels, we must form two variables for each noise condition. We
will use linear and quadratic coefficients again, but this time we will
not average across the Noise conditions.
# Simple effect of Angle when Noise is absent
chapter_14_table_4$D9 <- -1*chapter_14_table_4$Absent0 + 0*chapter_14_table_4$Absent4 + 1*chapter_14_table_4$Absent8
chapter_14_table_4$D10 <- 1*chapter_14_table_4$Absent0 - 2*chapter_14_table_4$Absent4 + 1*chapter_14_table_4$Absent8
# Simple effect of Angle when Noise is present
chapter_14_table_4$D11 <- -1*chapter_14_table_4$Present0 + 0*chapter_14_table_4$Present4 + 1*chapter_14_table_4$Present8
chapter_14_table_4$D12 <- 1*chapter_14_table_4$Present0 - 2*chapter_14_table_4$Present4 + 1*chapter_14_table_4$Present8
We test these simple effects simultaneously using a multivariate
approach with the Anova() function from the
car package.
# Test D9 and D10 simultaneously (Angle effect | Noise Absent)
MANOVA_D9D10_Full <- lm(cbind(D9, D10) ~ 1, data=chapter_14_table_4)
Anova(MANOVA_D9D10_Full, type="III")
Type III MANOVA Tests: Pillai test statistic
Df test stat approx F num Df den Df Pr(>F)
(Intercept) 1 0.64407 7.2381 2 8 0.01605 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> approx F = 7.238 with 2 and 8 df, p = .016 — matches book p. 781.
# Test D11 and D12 simultaneously (Angle effect | Noise Present)
MANOVA_D11D12_Full <- lm(cbind(D11, D12) ~ 1, data=chapter_14_table_4)
Anova(MANOVA_D11D12_Full, type="III")
Type III MANOVA Tests: Pillai test statistic
Df test stat approx F num Df den Df Pr(>F)
(Intercept) 1 0.91849 45.072 2 8 4.415e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> approx F = 45.072 with 2 and 8 df, p = .00004 — matches book p. 781.
These results confirm the textbook’s findings: there is a significant
simple effect of Angle when Noise is absent () and a highly significant simple
effect of Angle when Noise is present (), both on p. 781.
Having found a significant simple effect of Angle in each noise
condition, the book goes one step further and tests the two variables for Noise Absent
individually, which is how the nature of that simple effect is
identified.
# The individual cell mean comparisons within Noise Absent.
anova(lm(D9 ~ 0, data=chapter_14_table_4), lm(D9 ~ 1, data=chapter_14_table_4))
Analysis of Variance Table
Model 1: D9 ~ 0
Model 2: D9 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 75600
2 9 32040 1 43560 12.236 0.006745 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 12.24 for the linear trend of Angle when Noise is absent — matches p. 782.
anova(lm(D10 ~ 0, data=chapter_14_table_4), lm(D10 ~ 1, data=chapter_14_table_4))
Analysis of Variance Table
Model 1: D10 ~ 0
Model 2: D10 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 162000
2 9 153000 1 9000 0.5294 0.4854
#> F = 0.53 for the quadratic trend of Angle when Noise is absent — matches p. 782.
14.4.3 — Interaction Contrasts
An alternative to testing simple effects is to test interaction
contrasts. The omnibus interaction is represented collectively by and (which we created in Section
14.3).
We can test these 1-degree-of-freedom interaction contrasts
individually to see exactly what is driving the omnibus interaction.
# Test Interaction Contrast: Noise x Linear trend of Angle (D4)
anova(lm(D4 ~ 0, data=chapter_14_table_4), lm(D4 ~ 1, data=chapter_14_table_4))
Analysis of Variance Table
Model 1: D4 ~ 0
Model 2: D4 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 460800
2 9 44640 1 416160 83.903 7.391e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 83.90 — matches book p. 782.
# Test Interaction Contrast: Noise x Quadratic trend of Angle (D5)
anova(lm(D5 ~ 0, data=chapter_14_table_4), lm(D5 ~ 1, data=chapter_14_table_4))
Analysis of Variance Table
Model 1: D5 ~ 0
Model 2: D5 ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 10 129600
2 9 116640 1 12960 1 0.3434
#> F = 1.00 — matches book p. 782.
As the text reports on p. 782, the interaction contrast for is highly significant (), while is not (). This indicates that the Noise effect grows stronger in
a linear fashion as the angle deviates further from 0 degrees.
14.5 — Confidence Intervals for Contrasts
Just as in the one-way within-subjects design, we can form confidence
intervals for contrasts in the two-way design using the general
formula:
Where is the critical value
(which changes depending on whether the contrast is uncorrected, a
planned Bonferroni, or a post hoc Roy-Bose/Scheffé) and is the standard error of the
mean of the variable.
Because most statistical software only outputs uncorrected confidence
intervals by default, we often need to calculate the adjusted critical
values ourselves to control the familywise alpha level. Below we define
the parameters of the design as the book does (; Angle is with levels; Noise is with
levels) and calculate the
critical values for uncorrected, Bonferroni-adjusted, and post hoc
tests.
Critical values for main-effect contrasts
Uncorrected critical values. With a per-comparison
alpha level, the critical value for a single variable is read from the distribution with 1 and degrees of freedom (p. 780).
n <- nrow(chapter_14_table_4)
a <- 3 # Angle, the A factor
b <- 2 # Noise, the B factor
alpha_FW <- .05
# A single planned comparison of either factor's marginal means.
CV_Single_Comparison <- qf(p = 1 - alpha_FW, df1 = 1, df2 = n - 1)
CV_Single_Comparison
[1] 5.117355
#> 5.12 — the critical value used on pp. 780 and 782.
Bonferroni adjusted critical values.
If a set of planned
comparisons is tested, each contrast is tested at (p. 780). The Angle
factor has degrees of
freedom, so testing both its linear and quadratic trends as planned
comparisons means ; the Noise
factor has only degree of
freedom, so there.
# Number of planned contrasts within each factor (family)
C_for_A_Factor <- 2
C_for_B_Factor <- 1
CV_A_Factor_Bonferroni <- qf(p = 1 - alpha_FW/C_for_A_Factor, df1 = 1, df2 = n - 1)
CV_B_Factor_Bonferroni <- qf(p = 1 - alpha_FW/C_for_B_Factor, df1 = 1, df2 = n - 1)
CV_A_Factor_Bonferroni
[1] 7.209283
[1] 5.117355
Dividing the familywise alpha level by the number of planned
contrasts raises the critical value for the Angle family from 5.12 to
7.21. With a single planned contrast (), as for Noise, is just , so the Bonferroni and uncorrected
critical values coincide.
Roy–Bose (multivariate Scheffé) critical values.
For post hoc complex comparisons in a multivariate design, the text
gives the Roy–Bose critical value in Equation 14.31 for contrasts of the
marginal means and Equation 14.32
for contrasts of the marginal
means (p. 780). This is the most conservative adjustment.
CV_A_Factor_Scheffe <- (n-1)*(a-1)*qf(p=1-alpha_FW, df1=a-1, df2=n-a+1)/(n-a+1)
CV_B_Factor_Scheffe <- (n-1)*(b-1)*qf(p=1-alpha_FW, df1=b-1, df2=n-b+1)/(n-b+1)
CV_A_Factor_Scheffe # Angle: Equation 14.31
[1] 10.03268
CV_B_Factor_Scheffe # Noise: Equation 14.32
[1] 5.117355
Tested post hoc, the quadratic trend of Angle would be compared
against 10.03 rather than 5.12, so the conclusion of Section 14.4.1 does
not change. For the Noise factor, which contributes a single variable, the Roy–Bose value reduces to
the uncorrected 5.12, as it must.
Critical values for interaction contrasts
The general form for these critical values applies to interactions as
well, using the interaction degrees of freedom , which is the
general expression of Equation 14.34 (p. 782).
# Omnibus degrees of freedom for the interaction
df_interaction <- (a-1)*(b-1)
# A single planned interaction contrast is still a 1 df test.
qf(p = 1 - alpha_FW, df1 = 1, df2 = n - 1)
[1] 5.117355
#> 5.12 — the value the book uses for D4 and D5 on p. 782.
# Bonferroni, with C = (a - 1)(b - 1) = 2 planned interaction contrasts
C_Interaction_Contrasts <- df_interaction
CV_Interaction_Bonferroni <- qf(p=1-alpha_FW/C_Interaction_Contrasts, df1=1, df2=n-1)
CV_Interaction_Bonferroni
[1] 7.209283
# Roy-Bose (Scheffe) Post Hoc Interaction CV (Equations 14.33 and 14.34)
CV_Interaction_Scheffe <- (n-1)*df_interaction*qf(p=1-alpha_FW, df1=df_interaction, df2=n-df_interaction)/(n-df_interaction)
CV_Interaction_Scheffe
[1] 10.03268
The observed of 83.90 for
exceeds even the post hoc
critical value of 10.03, while the observed of 1.00 for falls short of the uncorrected 5.12 —
which is exactly what the book concludes on p. 782.
Reproducing Table 14.6: estimates and standard errors
Now that we have the mathematical framework for our critical values,
we need the sample estimates () and the standard errors (). The textbook explores four
specific contrasts in Table 14.6 (p. 784):
D1: Angle Linear (Main Effect)
D9: Angle Linear (Simple Effect: Noise Absent)
D11: Angle Linear (Simple Effect: Noise Present)
Interaction Contrast: The difference between the two simple
effects (D11 - D9)
By fitting intercept-only models in R, we can extract these values.
The default confint() method provides the uncorrected 95%
confidence intervals, which is what the book’s Table 14.6 reports: in
all four cases 95% confidence pertains to a single comparison rather
than a collection of them.
# Create the specific Interaction Contrast variable from Table 14.6
chapter_14_table_4$NA_NP_0_8 <- chapter_14_table_4$D11 - chapter_14_table_4$D9
# Fit intercept-only models for each contrast
model_D1 <- lm(D1 ~ 1, data=chapter_14_table_4)
model_D9 <- lm(D9 ~ 1, data=chapter_14_table_4)
model_D11 <- lm(D11 ~ 1, data=chapter_14_table_4)
model_Interaction <- lm(NA_NP_0_8 ~ 1, data=chapter_14_table_4)
# Combine Estimates, Standard Errors, and Uncorrected 95% Confidence Intervals
results_table <- data.frame(
Contrast = c("D1 (Angle Linear Main)", "D9 (Angle Linear | Noise Absent)",
"D11 (Angle Linear | Noise Present)", "Interaction (D11 - D9)"),
Estimate = c(coef(model_D1), coef(model_D9), coef(model_D11), coef(model_Interaction)),
Std_Error = c(summary(model_D1)$coefficients[1, 2], summary(model_D9)$coefficients[1, 2],
summary(model_D11)$coefficients[1, 2], summary(model_Interaction)$coefficients[1, 2]),
Lower_95_Uncorrected = c(confint(model_D1)[1], confint(model_D9)[1], confint(model_D11)[1], confint(model_Interaction)[1]),
Upper_95_Uncorrected = c(confint(model_D1)[2], confint(model_D9)[2], confint(model_D11)[2], confint(model_Interaction)[2])
)
results_table |>
gt() |>
fmt_number(columns = -Contrast, decimals = 3) |>
cols_label(
Std_Error = "Std. Error",
Lower_95_Uncorrected = "Lower 95%",
Upper_95_Uncorrected = "Upper 95%"
) |>
tab_header(title = md("Confidence intervals for four contrasts in the reaction time data")) |>
cols_align(align = "center", columns = -Contrast)
| Confidence intervals for four contrasts in the reaction time data |
| Contrast |
Estimate |
Std. Error |
Lower 95% |
Upper 95% |
| D1 (Angle Linear Main) |
168.000 |
20.591 |
121.419 |
214.581 |
| D9 (Angle Linear | Noise Absent) |
66.000 |
18.868 |
23.318 |
108.682 |
| D11 (Angle Linear | Noise Present) |
270.000 |
27.203 |
208.463 |
331.537 |
| Interaction (D11 - D9) |
204.000 |
22.271 |
153.619 |
254.381 |
#> D1: 168.000, se 20.591, [121.419, 214.581] — matches Table 14.6 (p. 784).
#> D9: 66.000, se 18.868, [ 23.318, 108.682] — matches Table 14.6 (p. 784).
#> D11: 270.000, se 27.203, [208.463, 331.537] — matches Table 14.6 (p. 784).
#> NA_NP_0_8: 204.000, se 22.271, [153.619, 254.381] — matches Table 14.6 (p. 784).
As the book points out (p. 784), the mean of the interaction contrast
is exactly the difference between the means of and : . To widen any of these intervals for multiple
comparisons, multiply the standard error by the square root of one of
the critical values computed above instead of by the quantile confint()
uses.
14.6 — One Within-Subjects Factor and One Between-Subjects Factor in
the Same Design
14.6.1 — Split-Plot Design with Two Levels of the Within-Subjects
Factor
A split-plot design (often referred to as a mixed ANOVA) contains
both a between-subjects factor and a within-subjects factor.
To illustrate the multivariate approach to this design, we will
revisit the perceptual psychology example from Chapter 12: *
Between-Subjects Factor (A): Age (Young vs. Old) *
Within-Subjects Factor (B): Angle (0° and 8°)
To keep things simple initially, we are only looking at two levels of
the within-subjects factor (0° and 8°). Let’s load and format the data
of Table 14.7 (p. 786).
data(chapter_14_table_7)
# Spell out the Age factor level by level, then set the level order.
chapter_14_table_7 <- chapter_14_table_7 |>
mutate(Age = case_when(
Group == 1 ~ "Young",
Group == 2 ~ "Old"
)) |>
mutate(Age = factor(Age, levels = c("Young", "Old")))
head(chapter_14_table_7)
Angle0 Angle8 Group Age
1 450 630 1 Young
2 390 540 1 Young
3 570 660 1 Young
4 450 720 1 Young
5 510 630 1 Young
6 360 450 1 Young
# Cell means, to check the data against the book.
chapter_14_table_7 |>
group_by(Age) |>
summarize(Angle0 = mean(Angle0), Angle8 = mean(Angle8))
# A tibble: 2 × 3
Age Angle0 Angle8
<fct> <dbl> <dbl>
1 Young 477 645
2 Old 543 792
#> Young 477 and 645; Old 543 and 792 — matches the Mean rows of Table 14.7 (p. 786).
In any two-factor design, we have three omnibus effects to test:
The main effect of Age (Between-Subjects)
The main effect of Angle (Within-Subjects)
The Age Angle
interaction (Within-Subjects)
14.6.2 — Main Effect of Between-Subjects Factor
To test the main effect of our between-subjects factor (Age), we need
to average over the within-subjects factor. We do this by creating a new
transformed variable, , which is
simply the average of the 0° and 8° scores for each participant
(Equation 14.37, p. 787).
Once we compute for
every participant, testing the main effect of Age is identical to
conducting a standard one-way between-subjects ANOVA with as the dependent variable, which is
Equation 14.40 (p. 787).
# Create the M variable (Average of the two angles)
chapter_14_table_7$M <- (chapter_14_table_7$Angle0 + chapter_14_table_7$Angle8) / 2
# Group means on M, the marginal means the test compares.
tapply(chapter_14_table_7$M, chapter_14_table_7$Age, mean)
Young Old
561.0 667.5
#> 561 and 667.5 — matches the Mean rows of Table 14.8 (p. 788).
# Test the main effect of Age using a one-way ANOVA on M
anova_age_main <- aov(M ~ Age, data = chapter_14_table_7)
summary(anova_age_main)
Df Sum Sq Mean Sq F value Pr(>F)
Age 1 56711 56711 9.242 0.00704 **
Residuals 18 110452 6136
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Residual SS = 110,452.5, the denominator sum the book reports on p. 788, and
#> F = 9.242 with 1 and 18 df, p = .007 — matches book p. 788.
The output gives us an value
of 9.24 and a value of .007. The
main effect of Age is statistically significant. Averaging across the
angles, older participants have significantly slower reaction times than
younger participants.
The same one-way ANOVA on as
an APA-style table, with sums of squares, df, F,
p, and partial .
(apaTables::apa.aov.table() produces only plain text that
reads no better than base R in HTML, so the table is built with
gt, which formats it properly.)
age_tbl <- broom::tidy(anova_age_main)
ss_res <- age_tbl$sumsq[age_tbl$term == "Residuals"] # error SS, for eta^2
age_tbl |>
transmute(
Source = if_else(term == "Age", "Age", "Within (S/A)"),
SS = sumsq, df = df, MS = meansq,
Fstat = statistic, p = p.value,
# Partial eta-squared: the effect's share of effect-plus-error variance.
peta = if_else(term == "Residuals", NA_real_, sumsq / (sumsq + ss_res))
) |>
gt() |>
fmt_number(columns = c(SS, MS, Fstat), decimals = 2) |>
fmt_number(columns = peta, decimals = 3) |>
fmt_number(columns = p, decimals = 4) |>
sub_missing(missing_text = "") |>
cols_label(Fstat = md("*F*"), p = md("*p*"),
peta = md("Partial η<sup>2</sup>")) |>
tab_header(title = md("Analysis of variance for the Age main effect (marginal mean *M*)")) |>
cols_align(align = "center", columns = -Source)
| Analysis of variance for the Age main effect (marginal mean M) |
| Source |
SS |
df |
MS |
F |
p |
Partial η2 |
| Age |
56,711.25 |
1 |
56,711.25 |
9.24 |
0.0070 |
0.339 |
| Within (S/A) |
110,452.50 |
18 |
6,136.25 |
|
|
|
14.6.3 — Within-Subjects Effects
The remaining two effects (Angle main effect and Age Angle interaction) both involve
the difference between the 0° and 8° conditions. To test these, we
create another transformed variable, , representing the difference score for
each participant (Equation 14.41, p. 788).
# Create the D variable (Difference between 8° and 0°)
chapter_14_table_7$D <- chapter_14_table_7$Angle8 - chapter_14_table_7$Angle0
# Displaying M and D to mirror Table 14.8
chapter_14_table_7[, c("Age", "M", "D")]
Age M D
1 Young 540 180
2 Young 465 150
3 Young 615 90
4 Young 585 270
5 Young 570 120
6 Young 405 90
7 Young 615 210
8 Young 645 270
9 Young 585 150
10 Young 585 150
11 Old 555 270
12 Old 705 210
13 Old 570 240
14 Old 705 150
15 Old 600 360
16 Old 735 270
17 Old 750 240
18 Old 600 240
19 Old 795 210
20 Old 660 300
# Group means on D.
tapply(chapter_14_table_7$D, chapter_14_table_7$Age, mean)
Young Old
168 249
#> 168 and 249 — matches the Mean rows of Table 14.8 (p. 788).
Notice that every participant has a positive score, meaning everyone was slower at
8° than at 0°. Also notice that the scores seem generally larger for the
Old group than the Young group.
14.6.4 — Test of the Interaction
The Age Angle interaction
tests whether the effect of Angle (our variable) differs depending on Age. If
there is no interaction, the mean
score should be the same for both Young and Old participants.
We can test this by running a standard one-way ANOVA on the variable.
# Test the interaction by running an ANOVA on the difference score (D)
# This is Equation 14.44 (p. 789).
anova_interaction <- aov(D ~ Age, data = chapter_14_table_7)
summary(anova_interaction)
Df Sum Sq Mean Sq F value Pr(>F)
Age 1 32805 32805 8.807 0.00825 **
Residuals 18 67050 3725
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Residual SS = 67,050, the denominator sum reported on p. 790, and F = 8.807
#> with 1 and 18 df, p = .008 — matches book p. 790.
The value is 8.81 with a value of .008. The interaction is
statistically significant. The angle effect is significantly stronger
for older participants () than for younger ones (), as the book notes on
p. 790.
14.6.5 — Within-Subjects Main Effect
The final test is the main effect of Angle. This tests whether the
grand mean of () is significantly different from
zero, averaging across Age.
The book proves that the
statistic for this main effect can be calculated by comparing the sum of
squares for the angle main effect (, Equation 14.47, p. 791) to
the error term from our full model (which happens to be the exact same
error term used in the interaction test above).
Let’s compute this exactly as Equation 14.48 (p. 792) defines it:
# Calculate N, a, and grand mean of D
N <- nrow(chapter_14_table_7)
a <- length(levels(chapter_14_table_7$Age))
D_bar <- mean(chapter_14_table_7$D)
# Extract the Sum of Squared Errors from our previous interaction model
# This is the denominator sum of squares: sum((Dij - Dj_bar)^2)
SS_error <- sum(resid(anova_interaction)^2)
df_error <- N - a
MS_error <- SS_error / df_error
# Calculate the Sum of Squares for the Angle Main Effect
SS_angle <- N * (D_bar^2)
# Compute the F-statistic
F_angle <- SS_angle / MS_error
# Compute the p-value
p_angle <- pf(F_angle, df1 = 1, df2 = df_error, lower.tail = FALSE)
# Display results
cat("Sum of Squares (Angle):", SS_angle,
"\nF-statistic:", F_angle,
"\np-value:", p_angle, "\n")
Sum of Squares (Angle): 869445
F-statistic: 233.4081
p-value: 9.479516e-12
#> Dbar = 208.5 and SS = 869,445 — match p. 791; F = 233.41 with 1 and 18 df
#> — matches book p. 792.
The by-hand calculation gives us an value of 233.41, matching the text.
Participants responded significantly more slowly in the 8° condition
compared to the 0° condition.
Notice a structural detail here: the error term for the
within-subjects main effect is identical to the error term for the
interaction. Both tests use the full-model variance of the scores as their denominator, because
both use Equation 14.42 as the full model (p. 792).
While the by-hand calculation makes the algebra visible, we can
bypass it entirely in practice. Because the Angle main effect tests if
the grand mean of is zero, we can
extract this directly from the (Intercept) of a linear
model predicting .
However, by default, R uses dummy coding, meaning the intercept tests
the mean of the reference group (e.g., Young participants). To test the
grand mean, we must change the Age factor to use
sum-to-zero contrasts (effect coding).
# Change the contrast coding for Age to sum-to-zero
contrasts(chapter_14_table_7$Age) <- contr.sum
# Fit the linear model predicting the Difference score (D) by Age
model_D <- lm(D ~ Age, data = chapter_14_table_7)
# Use car's Anova() (loaded above) to get Type III Sums of Squares
Anova(model_D, type = 3)
Anova Table (Type III tests)
Response: D
Sum Sq Df F value Pr(>F)
(Intercept) 869445 1 233.4081 9.48e-12 ***
Age 32805 1 8.8067 0.008246 **
Residuals 67050 18
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> (Intercept) SS = 869,445 — matches book p. 791; F = 233.41 — matches p. 792.
#> Age F = 8.81 — matches book p. 790.
In the output above, the (Intercept) row gives us an
value of 233.41, which matches
the by-hand calculation for the Angle main effect. Additionally, the
Age row gives us an
value of 8.81, which matches the earlier test for the Age Angle interaction.
This single lm(D ~ Age) model therefore carries both
within-subjects effects: its intercept is the grand
mean of (the Angle main effect)
and its Age coefficient is the between-group difference
in (the Age Angle interaction). A
publication-quality table makes those two pieces easy to read. With
modelsummary (the estimate with its standard error
beneath, fit statistics at the foot):
modelsummary(
list("D = Angle8 - Angle0" = model_D),
estimate = "{estimate}",
statistic = "({std.error})", # standard errors in parentheses, APA style
gof_map = c("nobs", "aic", "bic", "logLik"),
stars = TRUE,
output = "gt" # gt backend, to match the gtsummary table below
)
| |
D = Angle8 - Angle0 |
| (Intercept) |
208.500 |
|
(13.647) |
| Age1 |
-40.500 |
|
(13.647) |
| Num.Obs. |
20 |
| AIC |
225.1 |
| BIC |
228.1 |
| Log.Lik. |
-109.553 |
| + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001 |
The same model as a gtsummary
tbl_regression() table, with the intercept shown so the
Angle main effect is visible:
tbl_regression(model_D, intercept = TRUE) |>
modify_caption("**Regression of the difference score *D* on Age**")
Regression of the difference score D on Age
| Characteristic |
Beta |
95% CI |
p-value |
| (Intercept) |
209 |
180, 237 |
<0.001 |
| Age |
|
|
|
| Young |
-41 |
-69, -12 |
0.008 |
| Old |
— |
— |
|
| Abbreviation: CI = Confidence Interval |
In DMAR: all three split-plot effects in one table
We assembled the three split-plot effects above by hand: an ANOVA on
the marginal mean for the
between-subjects factor, an ANOVA on the difference score for the interaction, and an intercept
(or by-hand) test for the within-subjects main effect. The DMAR function
manova_split_plot() packages this as a single call: it
takes the wide data, the names of the within-subjects columns, and the
name of the between-subjects factor, and returns the four classical
multivariate test statistics (Wilks’s Lambda, Pillai’s trace,
Hotelling-Lawley, and Roy’s largest root) for the between-subjects
effect (A), the within-subjects effect (B), and their interaction, all
in one table.
# DMAR is loaded above. Build the wide two-level split-plot data, spelling
# out the between-subjects factor level by level.
mix <- chapter_14_table_7 |>
as_tibble() |>
mutate(Age = case_when(
Group == 1 ~ "Young",
Group == 2 ~ "Old"
)) |>
mutate(Age = factor(Age, levels = c("Young", "Old")))
split_plot_tests <- manova_split_plot(
data = mix,
within = c("Angle0", "Angle8"),
between = "Age",
ss_type = 3
)
# The returned data frame carries the sums-of-squares type as a final row
# rather than as an attribute, so we keep only the rows that are tests.
subset(split_plot_tests, effect != "sum_of_squares_type")
| A |
Pillai |
0.339 |
9.242 |
1 |
18 |
0.0070 |
| A |
Wilks |
0.661 |
9.242 |
1 |
18 |
0.0070 |
| A |
Hotelling-Lawley |
0.513 |
9.242 |
1 |
18 |
0.0070 |
| A |
Roy |
0.513 |
9.242 |
1 |
18 |
0.0070 |
| B |
Pillai |
0.928 |
233.408 |
1 |
18 |
< 0.0001 |
| B |
Wilks |
0.072 |
233.408 |
1 |
18 |
< 0.0001 |
| B |
Hotelling-Lawley |
12.967 |
233.408 |
1 |
18 |
< 0.0001 |
| B |
Roy |
12.967 |
233.408 |
1 |
18 |
< 0.0001 |
| interaction |
Pillai |
0.329 |
8.807 |
1 |
18 |
0.0082 |
| interaction |
Wilks |
0.671 |
8.807 |
1 |
18 |
0.0082 |
| interaction |
Hotelling-Lawley |
0.489 |
8.807 |
1 |
18 |
0.0082 |
| interaction |
Roy |
0.489 |
8.807 |
1 |
18 |
0.0082 |
Sum of squares: Type III
#> A (Age) F = 9.24 matches book p. 788; B (Angle) F = 233.41 matches
#> p. 792 (Equation 14.48); interaction F = 8.81 matches p. 790.
Because the within-subjects factor here has only two levels, and the four multivariate
statistics all yield the same .
The A rows reproduce the Age main effect (, book p. 788), the
B rows reproduce the Angle main effect of Equation 14.48
(, p. 792, the value of
the by-hand computation above), and the interaction rows
reproduce the Age Angle
interaction (, p. 790).
With equal group sizes, as here, the Type III test that
ss_type = 3 asks for and the Type II test agree; with
unequal sizes, the Type III test is the test of the unweighted mean of
the difference scores, which the book prefers (Chapter 14, note 6,
p. 854).
14.6.7 — General
Split-Plot Design
The principles we just used for a design with two within-subjects
levels apply when there are more levels, but the analysis becomes truly
multivariate. When we only had 0° and 8° conditions, we could get away
with a single difference variable (). Now we reinstate the 4° condition so
that our Angle factor has three levels, giving a design with levels of the between-subjects
factor and levels of the
within-subjects factor.
Because our within-subjects factor now has levels, we will need to form (or 2) variables to capture the
within-subjects effects, requiring us to test them simultaneously using
matrices.
Let’s load the data of Table 14.9 (p. 794).
data(chapter_14_table_9)
# Spell out the Age factor level by level, then set the level order.
chapter_14_table_9 <- chapter_14_table_9 |>
mutate(Age = case_when(
Group == 1 ~ "Young",
Group == 2 ~ "Old"
)) |>
mutate(Age = factor(Age, levels = c("Young", "Old")))
head(chapter_14_table_9)
Angle0 Angle4 Angle8 Group Age
1 450 510 630 1 Young
2 390 480 540 1 Young
3 570 630 660 1 Young
4 450 660 720 1 Young
5 510 660 630 1 Young
6 360 450 450 1 Young
# Cell means, to check the data against the book.
chapter_14_table_9 |>
group_by(Age) |>
summarize(across(Angle0:Angle8, mean))
# A tibble: 2 × 4
Age Angle0 Angle4 Angle8
<fct> <dbl> <dbl> <dbl>
1 Young 477 585 645
2 Old 543 654 792
#> Young 477, 585, 645; Old 543, 654, 792 — matches the Mean rows of
#> Table 14.9 (p. 794).
14.6.8 — Between-Subjects Main Effect
Just like before, to test the main effect of Age, we collapse across
the repeated measures. Regardless of how many within-subjects levels
there are, we always form exactly one variable representing each
participant’s overall mean score:
# Compute M (Mean across all three angles); Equation 14.49, p. 793.
chapter_14_table_9$M <- (chapter_14_table_9$Angle0 + chapter_14_table_9$Angle4 + chapter_14_table_9$Angle8) / 3
# Group means and grand mean on M.
c(tapply(chapter_14_table_9$M, chapter_14_table_9$Age, mean),
Grand = mean(chapter_14_table_9$M))
Young Old Grand
569 663 616
#> 569, 663, and 616 — matches the Group Mean and Grand Mean rows of
#> Table 14.10 (p. 795).
# Test the Age Main Effect using a one-way ANOVA on M
anova_age_main_3 <- aov(M ~ Age, data = chapter_14_table_9)
summary(anova_age_main_3)
Df Sum Sq Mean Sq F value Pr(>F)
Age 1 44180 44180 7.276 0.0147 *
Residuals 18 109300 6072
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 7.276 with 1 and 18 df, p = .0147 — matches book p. 794.
The output gives us an value
of 7.28 and a value of .0147,
indicating a statistically significant main effect of Age. This is the
same value the mixed-model
(univariate) approach of Chapter 12 produces, as the book notes on
p. 795. Because testing the between-subjects effect involves averaging
over the within-subjects factor (bypassing sphericity concerns), the
multivariate and univariate approaches are mathematically identical
here.
14.6.9 — Within-Subjects Effects
To test the within-subjects effects (Angle main effect and Age Angle interaction), we must form
difference variables. Since
Angle is a quantitative factor with 3 levels, it is highly logical to
use orthogonal polynomial contrasts:
# Create D1 (Linear) and D2 (Quadratic)
chapter_14_table_9$D1 <- -1*chapter_14_table_9$Angle0 + 0*chapter_14_table_9$Angle4 + 1*chapter_14_table_9$Angle8
chapter_14_table_9$D2 <- 1*chapter_14_table_9$Angle0 - 2*chapter_14_table_9$Angle4 + 1*chapter_14_table_9$Angle8
# Display M, D1, and D2 to mirror Table 14.10
head(chapter_14_table_9[, c("Age", "M", "D1", "D2")])
Age M D1 D2
1 Young 530 180 60
2 Young 470 150 -30
3 Young 620 90 -30
4 Young 610 270 -150
5 Young 600 120 -180
6 Young 420 90 -90
# Group means and grand means on the two D variables.
rbind(
tapply(chapter_14_table_9$D1, chapter_14_table_9$Age, mean),
tapply(chapter_14_table_9$D2, chapter_14_table_9$Age, mean)
)
Young Old
[1,] 168 249
[2,] -48 27
c(D1_grand = mean(chapter_14_table_9$D1), D2_grand = mean(chapter_14_table_9$D2))
D1_grand D2_grand
208.5 -10.5
#> D1: 168 (Young), 249 (Old), grand 208.5; D2: -48, 27, grand -10.5
#> — matches Table 14.10 (p. 795).
14.6.10 — Within-Subjects Main Effect
The null hypothesis for the Angle main effect states that the grand
means of both and equal zero simultaneously. Because we
have multiple variables, we can
no longer use simple sums of squares; we must compute matrices
representing the Sum of Squares and Cross-Products (SSCP).
We need two matrices: (Full
Model Matrix):
The error matrix capturing how much participants deviate from
their own group means on and
.
(Restricted Model
Matrix): The error matrix capturing how much participants deviate from
the grand mean assumption (where the true grand mean is hypothesized to
be zero).
The code below constructs these matrices directly from the
definitions on pp. 797–798.
# Extract Group Means and Grand Means for D1 and D2
D1_grand <- mean(chapter_14_table_9$D1)
D2_grand <- mean(chapter_14_table_9$D2)
# Calculate the Full Model Error Matrix E(F)
# e(F) = Participant Score - Group Mean
e1_F <- chapter_14_table_9$D1 - ave(chapter_14_table_9$D1, chapter_14_table_9$Age)
e2_F <- chapter_14_table_9$D2 - ave(chapter_14_table_9$D2, chapter_14_table_9$Age)
# Crossprod creates the SSCP matrix: Sum of squares on diagonal, cross-products off-diagonal
E_F <- crossprod(cbind(e1_F, e2_F))
rownames(E_F) <- colnames(E_F) <- c("D1", "D2")
# Full Model Matrix E(F)
print(E_F)
D1 D2
D1 67050 -9090
D2 -9090 125370
#> 67,050 and 125,370 on the diagonal, -9,090 off it — matches E(F) on p. 797.
# Calculate the Restricted Model Matrix E(R)
# The text establishes a shortcut formula: E(R) = E(F) + N * (Grand Mean Matrix)
N <- nrow(chapter_14_table_9)
E_R <- matrix(c(
E_F[1,1] + N * (D1_grand^2), # E11(R)
E_F[1,2] + N * (D1_grand * D2_grand), # E12(R)
E_F[2,1] + N * (D1_grand * D2_grand), # E21(R)
E_F[2,2] + N * (D2_grand^2) # E22(R)
), nrow=2)
rownames(E_R) <- colnames(E_R) <- c("D1", "D2")
# Restricted Model Matrix E(R)
print(E_R)
D1 D2
D1 936495 -52875
D2 -52875 127575
#> 936,495 and 127,575 on the diagonal, -52,875 off it — matches E(R) on p. 798.
Both matrices match the text. To conduct the statistical test, we
compare the “volume” of these matrices using their determinants. The
formula for the test statistic (Equation 14.54, p. 798) is:
# Calculate Determinants
det_EF <- det(E_F)
det_ER <- det(E_R)
cat("Determinant of E(F):", format(det_EF, scientific=FALSE), "\n")
Determinant of E(F): 8323430400
cat("Determinant of E(R):", format(det_ER, scientific=FALSE), "\n")
Determinant of E(R): 116677584000
# Compute the F-statistic
a <- length(levels(chapter_14_table_9$Age)) # 2 levels of Age
b <- 3 # 3 angles
df_num <- b - 1
df_den <- N - a - b + 2
F_angle_multiv <- ((det_ER - det_EF) / df_num) / (det_EF / df_den)
p_angle_multiv <- pf(F_angle_multiv, df1 = df_num, df2 = df_den, lower.tail = FALSE)
cat(
"\nAngle Main Effect (Multivariate F):\n",
"F(", df_num, ", ", df_den, ") = ", F_angle_multiv, "\n",
"p-value = ", p_angle_multiv, "\n",
sep = ""
)
Angle Main Effect (Multivariate F):
F(2, 17) = 110.6527
p-value = 1.791335e-10
#> |E(F)| = 8,323,430,400 and |E(R)| = 116,677,584,000 — match p. 798.
#> F = 110.65 with 2 and 17 df, p < .0001 — matches book p. 798.
By dividing the determinants, we arrive at an value of 110.65 with 2 and 17 degrees
of freedom (). Thus,
the main effect of Angle is highly statistically significant when
evaluated via the multivariate matrix approach.
14.6.11 — Test of the Interaction
The final omnibus effect is the interaction between Age and Angle.
Like the main effect, this test involves comparing full and restricted
models. The full models () are
identical to the ones we used for the within-subjects main effect,
because they simply represent how much each participant deviates from
their own specific group mean on
and .
The restricted models (),
however, change. The interaction null hypothesis states that there are
no group differences on the within-subjects differences. This means our
restricted model simply predicts that every participant’s score on a
variable is equal to the grand
mean of that variable:
Let’s compute the new
matrix for the interaction and compare it to the matrix we already computed.
# Calculate the Restricted Model Errors for the Interaction
# e(R) = Participant Score - Grand Mean
e1_R_int <- chapter_14_table_9$D1 - D1_grand
e2_R_int <- chapter_14_table_9$D2 - D2_grand
# Calculate the Restricted Model Matrix E(R) for Interaction
E_R_int <- crossprod(cbind(e1_R_int, e2_R_int))
rownames(E_R_int) <- colnames(E_R_int) <- c("D1", "D2")
# Restricted Model Matrix E(R) for Interaction
print(E_R_int)
D1 D2
D1 99855 21285
D2 21285 153495
#> 99,855 and 153,495 on the diagonal, 21,285 off it — matches the E(R) for the
#> interaction on p. 799.
This matrix differs from the used for the main effect, because
each participant’s error is taken from the grand mean of the variable rather than from the group
mean minus the grand mean (p. 799).
The special case F test ()
Because our between-subjects factor (Age) only has two levels (), we can use a simplified formula
to calculate the statistic
directly from the determinants of our two matrices (Equation 14.58,
p. 800):
# Calculate Determinant of the new E(R)
det_ER_int <- det(E_R_int)
cat(
"Determinant of E(F): ", format(det_EF, scientific = FALSE), "\n",
"Determinant of E(R): ", format(det_ER_int, scientific = FALSE), "\n",
sep = ""
)
Determinant of E(F): 8323430400
Determinant of E(R): 14874192000
# Compute the F-statistic for the interaction (a = 2 special case)
F_int_special <- ((det_ER_int - det_EF) / (b - 1)) / (det_EF / (N - b))
p_int_special <- pf(F_int_special, df1 = b - 1, df2 = N - b, lower.tail = FALSE)
cat(
"\nInteraction Effect F-test (a = 2):\n",
"F(", b - 1, ", ", N - b, ") = ", F_int_special, "\n",
"p-value = ", p_int_special, "\n",
sep = ""
)
Interaction Effect F-test (a = 2):
F(2, 17) = 6.689727
p-value = 0.007192605
#> |E(R)| = 14,874,192,000 — matches p. 801.
#> F = 6.69 with 2 and 17 df, p = .0072 — matches book p. 801.
The output yields an value of
6.69 with a value of .0072,
indicating a significant Age
Angle interaction.
General Multivariate Statistics (Wilks’s Lambda and
Pillai–Bartlett)
When a design has more than two levels for the between-subjects
factor (), the simple
determinant ratio breaks down, and we must rely on general multivariate
test statistics. The book restricts its discussion to two of the four:
Wilks’s Lambda () and the
Pillai–Bartlett trace ().
- Wilks’s Lambda ()
Wilks’s Lambda is the ratio of the full model’s determinant to the
restricted model’s determinant, (Equation 14.60, p. 801). Values closer to 0
indicate larger effects, while values closer to 1 indicate smaller
ones.
# Calculate Wilks' Lambda
wilks_lambda <- det_EF / det_ER_int
cat("Wilks' Lambda:", wilks_lambda, "\n")
Wilks' Lambda: 0.5595887
- Pillai–Bartlett Trace ()
This statistic is based on subtracting the full matrix from the
restricted matrix to get a Hypothesis matrix (). We then multiply by the inverse of the Total matrix
(). The trace (sum of the
diagonal elements) of this resulting matrix is Pillai’s .
# Calculate Pillai-Bartlett Trace
H_matrix <- E_R_int - E_F
T_matrix <- E_R_int
# H multiplied by the inverse of T
HT_inv <- H_matrix %*% solve(T_matrix)
# H * T^-1 Matrix
print(HT_inv)
D1 D2
D1 0.2950662 0.1569726
D2 0.2732095 0.1453450
#> .2951, .1570, .2732, .1453 — matches the matrix on p. 803.
# The trace is the sum of the diagonal elements
pillai_V <- sum(diag(HT_inv))
cat("\nPillai-Bartlett Trace (V):", pillai_V, "\n")
Pillai-Bartlett Trace (V): 0.4404113
#> V = 0.4404 — matches book p. 804, where Equation 14.63 converts it to the
#> same F of 6.69 with 2 and 17 df.
Built-in Functions
We can bypass the matrix algebra using R’s built-in
manova() function. Because the interaction hypothesis
states that there are no group differences on the within-subjects
differences, running a one-way MANOVA predicting our difference
variables ( and ) by the between-subjects factor (Age)
tests the interaction.
# Fit the MANOVA model predicting the difference scores by Age
interaction_manova <- manova(cbind(D1, D2) ~ Age, data = chapter_14_table_9)
# Request Wilks' Lambda
summary(interaction_manova, test = "Wilks")
Df Wilks approx F num Df den Df Pr(>F)
Age 1 0.55959 6.6897 2 17 0.007193 **
Residuals 18
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Wilks = 0.55959 and approx F = 6.69 with 2 and 17 df, p = .0072
#> — matches the by-hand values above and book p. 801.
# Request Pillai-Bartlett Trace
summary(interaction_manova, test = "Pillai")
Df Pillai approx F num Df den Df Pr(>F)
Age 1 0.44041 6.6897 2 17 0.007193 **
Residuals 18
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Pillai = 0.44041 — matches V = 0.4404 on p. 804, with the same F of 6.69.
Notice how the manova() summary outputs match our
by-hand calculations exactly.
Because our design only has two levels for the between-subjects
factor, the parameter (the
smaller of and ) equals 1. Whenever , all four multivariate test
statistics (Wilks’s Lambda, Pillai–Bartlett, Hotelling–Lawley, and Roy’s
greatest characteristic root) necessarily agree, which the book
establishes on p. 804. This is why the specialized test above captures the interaction
without the approximations that larger designs require.
14.7 — Measures of Effect
Even though we just used the multivariate (MANOVA) approach to test
our within-subjects effects, when it comes to calculating effect sizes,
the text recommends reverting to the mixed-model (univariate)
formulation of omega squared ().
This is because the mixed-model approach treats individual
differences between subjects () as a meaningful source of total
variance, ensuring our effect sizes reflect the reality of the repeated
measures design.
The formulas for the split-plot design are identical to those from
Chapter 12, repeated as Equations 12.22 through 12.24 on p. 805:
Main Effect of Between-Subjects Factor (A):
Main Effect of Within-Subjects Factor (B):
Interaction (AB):
While multivariate software doesn’t always output these mixed-model
components directly, we can extract them in R by fitting a traditional
univariate repeated measures ANOVA model.
# Reshape the data to "long" format for univariate ANOVA
chapter_14_long <- reshape(
as.data.frame(chapter_14_table_9),
varying = c("Angle0", "Angle4", "Angle8"),
v.names = "Score",
timevar = "Angle",
times = c(0, 4, 8),
direction = "long"
)
chapter_14_long$Angle <- factor(chapter_14_long$Angle)
chapter_14_long$Participant <- factor(chapter_14_long$id)
# Run the mixed-model ANOVA
univariate_aov <- aov(Score ~ Age * Angle + Error(Participant/Angle), data = chapter_14_long)
# Save the summary object so we can extract values from it
aov_summary <- summary(univariate_aov)
# Extract the components dynamically
# The summary object is a list. [[1]] is the Between-Subjects part, [[2]] is the Within-Subjects part.
# Between-Subjects components (from Error: Participant)
# Row 1 is Age, Row 2 is Residuals (S/A)
SS_A <- aov_summary$`Error: Participant`[[1]][1, "Sum Sq"]
SS_SA <- aov_summary$`Error: Participant`[[1]][2, "Sum Sq"]
MS_SA <- aov_summary$`Error: Participant`[[1]][2, "Mean Sq"]
# Within-Subjects components (from Error: Participant:Angle)
# Row 1 is Angle, Row 2 is Age:Angle, Row 3 is Residuals (BxS/A)
SS_B <- aov_summary$`Error: Participant:Angle`[[1]][1, "Sum Sq"]
MS_B <- aov_summary$`Error: Participant:Angle`[[1]][1, "Mean Sq"]
SS_AB <- aov_summary$`Error: Participant:Angle`[[1]][2, "Sum Sq"]
MS_AB <- aov_summary$`Error: Participant:Angle`[[1]][2, "Mean Sq"]
SS_BSA <- aov_summary$`Error: Participant:Angle`[[1]][3, "Sum Sq"]
MS_BSA <- aov_summary$`Error: Participant:Angle`[[1]][3, "Mean Sq"]
# Calculate Omega Squared Values
a <- length(levels(chapter_14_long$Age)) # Dynamically count levels of Age (2)
b <- length(levels(chapter_14_long$Angle)) # Dynamically count levels of Angle (3)
omega_sq_A <- (SS_A - (a-1)*MS_SA) / (SS_A + SS_SA + MS_SA)
omega_sq_B <- ((b-1)*(MS_B - MS_BSA)) / (SS_B + SS_BSA + SS_SA + MS_SA)
omega_sq_AB <- ((a-1)*(b-1)*(MS_AB - MS_BSA)) / (SS_AB + SS_BSA + SS_SA + MS_SA)
cat(
"Omega Squared (Age): ", round(omega_sq_A, 2), "\n",
"Omega Squared (Angle): ", round(omega_sq_B, 2), "\n",
"Omega Squared (Age x Angle): ", round(omega_sq_AB, 2), "\n",
sep = ""
)
Omega Squared (Age): 0.24
Omega Squared (Angle): 0.52
Omega Squared (Age x Angle): 0.04
#> .24, .52, and .04 — matches the omega squared values on p. 805.
As the text notes on p. 805, the Age (.24) and Angle (.52) main
effects account for considerably more variance than the interaction
(.04), but the interaction might still be the most theoretically
interesting finding.
14.7.1 — Further Investigation of Main Effects
If we want to dig into the within-subjects main effect, we
investigate specific
variables.
For example, our variable
represents the quadratic trend of the Angle factor. Let’s isolate the
test for just the quadratic trend
by looking specifically at the
components of the and matrices we computed earlier in
Section 14.6.10, which is exactly how the book proceeds on p. 806.
Recall Equation 14.48 for testing a specific variable:
# E_F and E_R from section 14.6.10 contain the Error components for D1 and D2
# The [2,2] elements correspond to D2 (the quadratic trend)
E_F_D2 <- E_F[2, 2]
E_R_D2 <- E_R[2, 2]
# The numerator is N * (Grand Mean of D2)^2, which is also E_R - E_F
num_D2 <- E_R_D2 - E_F_D2
cat("EF for D2:", E_F_D2, "\n")
EF for D2: 125370
cat("ER for D2:", E_R_D2, "\n")
ER for D2: 127575
cat("N * Dbar^2:", num_D2, "\n")
N * Dbar^2: 2205
#> 125,370; 127,575; and 2,205 — all three match book p. 806.
# Calculate the F-statistic
df_num_D2 <- 1
df_den_D2 <- N - a
F_D2 <- num_D2 / (E_F_D2 / df_den_D2)
cat("\nF-statistic for Quadratic Trend (D2):", F_D2, "\n")
F-statistic for Quadratic Trend (D2): 0.3165829
#> F = 0.32 with 1 and 18 df — matches book p. 806.
# Critical values: per comparison, then the post hoc Roy-Bose value of
# Equation 14.64 (p. 806).
qf(p = 1 - .05, df1 = 1, df2 = N - a)
[1] 4.413873
#> 4.41 — matches the critical value quoted on p. 807.
(N - a) * (b - 1) * qf(p = 1 - .05, df1 = b - 1, df2 = N - a - b + 2) /
(N - a - b + 2)
[1] 7.605594
#> 7.60 — matches the post hoc critical value computed on p. 807.
The value is 0.32. Against
either critical value it is far from significant, confirming there is no
meaningful quadratic trend in the data.
We can bypass the by-hand arithmetic entirely with base R’s linear
modeling. When software performs a multivariate test, it is
simultaneously running univariate ANOVAs on each individual variable; the book notes on p. 807 that
this is how statistical packages report the univariate of 233.41 for and 0.32 for alongside the multivariate of 110.65.
To see these in R, we can wrap our multivariate linear model in
summary.aov(). However, there is a crucial distinction to
keep in mind:
To test the Interaction (Age Angle components): We look at the
Age effect output by summary.aov().
To test the Within-Subjects Main Effect (Angle components): We
must look at the Intercept of these models, because testing if the grand
mean of a difference score equals zero is exactly what an intercept test
evaluates.
Let’s illustrate this. We will fit the linear model and explicitly
ask for the Intercept test to find our 0.32 F-value.
# Sum-to-zero coding for Age, so that the Intercept is the unweighted grand
# mean of each D variable rather than the mean of the first group. This is set
# on the Age column itself, visibly, because it changes what the output means.
contrasts(chapter_14_table_9$Age) <- contr.sum
# Fit the multivariate linear model predicting D1 and D2
multivariate_lm <- lm(cbind(D1, D2) ~ Age, data = chapter_14_table_9)
# View the univariate ANOVA for D2 (Quadratic Trend)
# We use summary() to see the t-test for the Intercept.
# Remember: F = t^2 for tests with 1 numerator degree of freedom!
summary(multivariate_lm)$`Response D2`
Call:
lm(formula = D2 ~ Age, data = chapter_14_table_9)
Residuals:
Min 1Q Median 3Q Max
-132.0 -64.5 18.0 63.0 138.0
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -10.50 18.66 -0.563 0.5806
Age1 -37.50 18.66 -2.009 0.0597 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 83.46 on 18 degrees of freedom
Multiple R-squared: 0.1832, Adjusted R-squared: 0.1379
F-statistic: 4.038 on 1 and 18 DF, p-value: 0.05972
# The intercept t, squared, is the F for the quadratic trend.
summary(multivariate_lm)$`Response D2`$coefficients["(Intercept)", "t value"]^2
[1] 0.3165829
#> 0.32 — matches book p. 806.
In the output for Response D2, the
(Intercept) row has a value of about , and squaring it returns the 0.32
we computed from the matrices.
If we wanted to test the univariate simple effects for the
interaction instead, we would just run:
# This will output the ANOVA tables showing the Age effect on D1 and D2
summary.aov(multivariate_lm)
Response D1 :
Df Sum Sq Mean Sq F value Pr(>F)
Age 1 32805 32805 8.8067 0.008246 **
Residuals 18 67050 3725
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Response D2 :
Df Sum Sq Mean Sq F value Pr(>F)
Age 1 28125 28125 4.038 0.05972 .
Residuals 18 125370 6965
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> The Age line of Response D2 gives F = 4.038, p = .0597, the interaction
#> contrast the book reports on p. 814.
This breaks the omnibus multivariate models down into specific
contrast tests without cross-multiplying any error matrices by hand.
14.7.2 — Further Investigation of an Interaction—Simple Effects
Because our Age Angle
interaction was significant, we must break it down. We can test the
between-subjects factor at fixed levels of the within-subjects factor
(Age within a specific Angle), or the within-subjects factor at fixed
levels of the between-subjects factor (Angle within a specific Age).
14.7.3 — Between-Subjects Effects at a Fixed Level of
Within-Subjects Factor
If we want to know whether Young and Old participants differ
specifically at the 0° Angle, the within-subjects nature of the design
drops out: only one score per participant is involved, so this is a
one-way between-subjects ANOVA on the Angle0 column
(p. 807). The book describes the procedure here rather than reporting a
value for this particular test, so there is nothing to confirm against
the printed page.
# Simple effect of Age at 0 degrees
simple_effect_age_at_0 <- aov(Angle0 ~ Age, data = chapter_14_table_9)
summary(simple_effect_age_at_0)
Df Sum Sq Mean Sq F value Pr(>F)
Age 1 21780 21780 3.161 0.0923 .
Residuals 18 124020 6890
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
As the book stresses on p. 808, this is a test on an original variable, not on a variable, and the error term it uses is
— the
error term that does not require sphericity, and the one SAS, SPSS, and
R all use by default.
14.7.4 — Within-Subjects Effects at a Fixed Level of
Between-Subjects Factor
This calculation is more complex in a multivariate framework. Let’s
test the Angle effect only for the Younger participants. We treat this
as a one-way within-subjects design using just the Young group.
Let’s compute the and
matrices specifically for
the Young participants.
# Filter data for Young participants
young_data <- subset(chapter_14_table_9, Age == "Young")
n1 <- nrow(young_data)
# Get Means for Young participants
D1_mean_young <- mean(young_data$D1)
D2_mean_young <- mean(young_data$D2)
# Calculate E(F)_1 (Deviations from Young means)
e1_F_young <- young_data$D1 - D1_mean_young
e2_F_young <- young_data$D2 - D2_mean_young
E_F_1 <- crossprod(cbind(e1_F_young, e2_F_young))
# Calculate E(R)_1 (Deviations from zero, since null is no effect)
# Mathematically: E(R)_1 = E(F)_1 + n1 * (Mean Vector * Mean Vector^T)
E_R_1 <- matrix(c(
E_F_1[1,1] + n1 * (D1_mean_young^2),
E_F_1[1,2] + n1 * (D1_mean_young * D2_mean_young),
E_F_1[2,1] + n1 * (D1_mean_young * D2_mean_young),
E_F_1[2,2] + n1 * (D2_mean_young^2)
), nrow=2)
# E(F)_1 for Young Participants
print(E_F_1)
e1_F_young e2_F_young
e1_F_young 38160 3240
e2_F_young 3240 77760
#> 38,160 and 77,760 on the diagonal, 3,240 off it — matches E(F)_1 on p. 809.
# E(R)_1 for Young Participants
print(E_R_1)
[,1] [,2]
[1,] 320400 -77400
[2,] -77400 100800
#> 320,400 and 100,800 on the diagonal, -77,400 off it — matches E(R)_1 on p. 809.
Both matrices match the book. The book also points out (p. 809) that
the overall is the sum of the
separate within-group matrices, which is worth checking because it is
what makes the pooled error term below possible.
old_data <- subset(chapter_14_table_9, Age == "Old")
E_F_2 <- crossprod(cbind(old_data$D1 - mean(old_data$D1),
old_data$D2 - mean(old_data$D2)))
print(E_F_2)
[,1] [,2]
[1,] 28890 -12330
[2,] -12330 47610
#> 28,890 and 47,610 on the diagonal, -12,330 off it — matches E(F)_2 on p. 809.
# E(F) = E(F)_1 + E(F)_2
E_F_1 + E_F_2
e1_F_young e2_F_young
e1_F_young 67050 -9090
e2_F_young -9090 125370
#> 67,050 and 125,370 on the diagonal, -9,090 off it: the E(F) of Section
#> 14.6.10, as the book states on p. 809.
Now we calculate the test.
There are two approaches to do so.
- Separate Error Term (Equation 14.65, p. 809)
det_EF1 <- det(E_F_1)
det_ER1 <- det(E_R_1)
c(det_E_F_1 = det_EF1, det_E_R_1 = det_ER1)
det_E_F_1 det_E_R_1
2956824000 26305560000
#> 2,956,824,000 and 26,305,560,000 — match the determinants on p. 809.
F_sep <- ((det_ER1 - det_EF1) / (b - 1)) / (det_EF1 / (n1 - b + 1))
p_sep <- pf(F_sep, df1 = b - 1, df2 = n1 - b + 1, lower.tail = FALSE)
cat("F-test (Separate Error Term): F = ", F_sep, ", p = ", p_sep, "\n")
F-test (Separate Error Term): F = 31.58624 , p = 0.000159629
#> F = 31.59 with 2 and 8 df, p = .0002 — matches book p. 809.
The result (, ) shows a highly significant
Angle effect for the Young group.
- Pooled Error Term (Alternative)
If we assume the covariance matrices are equal in the population
(Homogeneity of Covariance), we gain statistical power by using the
overall matrix – calculated
from all participants – as our error term.
The formula for the pooled
statistic (Equation 14.66, p. 810) substitutes our targeted hypothesis
matrix into the overall error space:
# E_F and det_EF are the full-sample matrix and determinant from Section 14.6.10.
# The text defines a specific matrix addition/subtraction:
Pooled_Hypothesis_Matrix <- E_F + E_R_1 - E_F_1
print(Pooled_Hypothesis_Matrix)
D1 D2
D1 349290 -89730
D2 -89730 148410
#> 349,290 and 148,410 on the diagonal, -89,730 off it — matches p. 810.
det_pooled_hyp <- det(Pooled_Hypothesis_Matrix)
cat("Determinant of |E(F) + E(R)1 - E(F)1|:", format(det_pooled_hyp, scientific=FALSE), "\n")
Determinant of |E(F) + E(R)1 - E(F)1|: 43786656000
#> 43,786,656,000 — matches book p. 810.
# Calculate the F-statistic using the overall det_EF computed in 14.6.10
F_pooled <- ((det_pooled_hyp - det_EF) / (b - 1)) / (det_EF / (N - a - b + 2))
p_pooled <- pf(F_pooled, df1 = b - 1, df2 = N - a - b + 2, lower.tail = FALSE)
cat("F-test (Pooled Error Term): F = ", F_pooled, ", p = ", p_pooled, "\n")
F-test (Pooled Error Term): F = 36.21553 , p = 7.433013e-07
#> F = 36.22 with 2 and 17 df, p < .0001 — matches book p. 810.
Using the pooled error term gives us with ,
which is somewhat more powerful because of the additional denominator
degrees of freedom (17 instead of 8). However, as the textbook warns on
pp. 810–811, the pooled test is not robust to violations of the
homogeneity of covariance matrices assumption, and Box’s test is of little practical help in
deciding. With samples of perhaps 40 or more per level of , the separate error term is preferable
because the extra degrees of freedom from pooling are then
inconsequential.
14.7.5 — Cell Mean Comparisons
Because we found a significant overall Angle effect for the younger
participants, it makes sense to drill down even further. Let’s test a
specific contrast (the quadratic trend) strictly for the younger
participants.
This test is essentially a one-way within-subjects contrast. However,
just like in the previous section, we must choose between a separate
error term (using only the data from the younger participants) and a
pooled error term (using error data across all participants).
Method 1: separate error term
The statistic for testing a
specific variable at a specific
level of () using a separate error term is
Equation 14.67 (p. 812):
Let’s calculate this in R using the young_data we
created earlier.
# Get the sample size, mean, and variance of D2 for Young participants
n1 <- nrow(young_data)
Dbar_21 <- mean(young_data$D2)
s2_D21 <- var(young_data$D2)
cat("Mean of D2 (Young):", Dbar_21, "\n",
"Variance of D2 (Young):", s2_D21, "\n")
Mean of D2 (Young): -48
Variance of D2 (Young): 8640
#> -48 and 8,640 — match book p. 812.
# Calculate the F-statistic
F_cell_sep <- (n1 * Dbar_21^2) / s2_D21
p_cell_sep <- pf(F_cell_sep, df1 = 1, df2 = n1 - 1, lower.tail = FALSE)
cat("\nF-statistic (Separate Error):", round(F_cell_sep, 2), "\n")
F-statistic (Separate Error): 2.67
cat("p-value:", round(p_cell_sep, 4), "\n")
p-value: 0.1369
#> F = 2.67 with 1 and 9 df — matches book p. 812.
# The book also reads these numbers off the diagonals of E(F)_1 and E(R)_1:
# the numerator is the difference of the [2, 2] elements and the denominator
# divides the E(F)_1 element by n1 - 1.
c(numerator = E_R_1[2, 2] - E_F_1[2, 2], denominator = E_F_1[2, 2] / (n1 - 1))
numerator denominator
23040 8640
#> 23,040 and 8,640 — match book p. 812, and their ratio is again 2.67.
Testing whether the mean of a difference score equals zero for a
single group is the definition of a one-sample -test, so the same result is available
directly.
t.test(
x = young_data$D2,
mu = 0,
alternative = "two.sided",
conf.level = 0.95
)
One Sample t-test
data: young_data$D2
t = -1.633, df = 9, p-value = 0.1369
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-114.49357 18.49357
sample estimates:
mean of x
-48
#> t = -1.633, and (-1.633)^2 = 2.67 — matches the F on p. 812.
Method 2: pooled error term
If we assume homogeneity of variance across the age groups, we can
pool the variance of across
both groups. We substitute the separate variance with the pooled
variance, (also known as
the mean square within for the
variable, ). This is
Equation 14.68 (p. 812).
# The Older participants' variance on D2 (old_data was built above)
s2_D22 <- var(old_data$D2)
# Calculate pooled variance (unweighted average, since n is equal)
s2_D2p <- (s2_D21 + s2_D22) / 2
cat("Variance of D2 (Old):", s2_D22, "\n")
Variance of D2 (Old): 5290
cat("Pooled Variance of D2:", s2_D2p, "\n")
Pooled Variance of D2: 6965
#> 5,290 and 6,965 — match book p. 812.
# The same pooled variance is the [2, 2] element of E(F) divided by N - a.
E_F[2, 2] / (N - a)
[1] 6965
#> 6,965 — the equivalence the book points out on p. 812.
# Calculate the F-statistic
F_cell_pool <- (n1 * Dbar_21^2) / s2_D2p
# Denominator df is N - a (20 - 2 = 18)
p_cell_pool <- pf(F_cell_pool, df1 = 1, df2 = N - a, lower.tail = FALSE)
cat(
"\nF-statistic (Pooled Error):", round(F_cell_pool, 2), "\n",
"p-value:", round(p_cell_pool, 4), "\n"
)
F-statistic (Pooled Error): 3.31
p-value: 0.0856
#> F = 3.31 with 1 and 18 df — matches book p. 812.
Using the pooled error gives us an value of 3.31. As discussed previously,
deciding which critical value to use for these tests depends on whether
they were planned (Bonferroni) or post hoc, in which case the Roy–Bose
values of Equations 14.69 and 14.70 (p. 813) apply, the first for the
separate error term and the second for the pooled one.
14.7.6 — Interaction Contrasts
Instead of looking at the simple effect of the quadratic trend within
one group, we can evaluate if the quadratic trend is significantly
different between the younger and older participants with an interaction
contrast.
Because an interaction contrast effectively reduces the
within-subjects factor down to a single variable (the quadratic trend
difference), the within-subjects nature of the design vanishes! We are
left comparing two independent groups on a single score.
The formula from Chapter 4 for testing a specific between-group
comparison applies directly, which the book gives as Equation 14.73
(p. 814):
Let’s define our contrast () as the difference between the
mean score for younger
participants and the mean score
for older participants (,
).
# Get the mean D2 score for Older participants
Dbar_22 <- mean(old_data$D2)
# Calculate the contrast (psi_hat)
psi_hat <- Dbar_21 - Dbar_22
cat("Contrast (Psi Hat):", psi_hat, "\n")
Contrast (Psi Hat): -75
#> -48 - 27 = -75 — matches book p. 814.
MS_SA_D <- s2_D2p # We already calculated MS_S/A(D) as the pooled variance (s2_D2p)
# Calculate the F-statistic
# Contrast weights: c1 = 1, c2 = -1. n1 = 10, n2 = 10.
sum_cj2_nj <- (1^2 / 10) + ((-1)^2 / 10)
F_interaction_contrast <- (psi_hat^2) / (MS_SA_D * sum_cj2_nj)
p_interaction_contrast <- pf(F_interaction_contrast, df1 = 1, df2 = N - a, lower.tail = FALSE)
cat(
"\nF-statistic (Interaction Contrast):", round(F_interaction_contrast, 2), "\n",
"p-value:", round(p_interaction_contrast, 4), "\n"
)
F-statistic (Interaction Contrast): 4.04
p-value: 0.0597
#> F = 4.04 with 1 and 18 df, p = .0597 — matches book p. 814.
The ANOVA shortcut
The text notes that testing an interaction contrast when has two levels is identical to running
a standard one-way ANOVA (or independent samples -test) on the variable (p. 814). We can show this by
running aov() on the column using Age as the
predictor:
# Run a standard univariate ANOVA on the D2 variable
interaction_contrast_aov <- aov(D2 ~ Age, data = chapter_14_table_9)
summary(interaction_contrast_aov)
Df Sum Sq Mean Sq F value Pr(>F)
Age 1 28125 28125 4.038 0.0597 .
Residuals 18 125370 6965
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> F = 4.038 with 1 and 18 df, p = .0597 — matches book p. 814, and the
#> residual mean square of 6,965 is MS_S/A(D) again.
Here the value is 4.04, the
same as the contrast computation above, with . Treating the difference score
as an ordinary dependent variable removes the need for the algebra
altogether. For a post hoc test the critical value would come from
Equation 14.75 (p. 814), which is the form of the Roy–Bose value.
14.8 — Confidence Intervals for Contrasts
Now that we have covered hypothesis testing in split-plot designs
using the multivariate approach, we turn to forming confidence
intervals. The general form of a confidence interval here is identical
to what we have seen in previous chapters:
Where: * is the
estimated value of the contrast. * is the appropriate critical value
(often an or value). * is the standard error of
the contrast.
The complexities in a split-plot design arise because we can base our
contrast on different types of variables: an M variable
(marginal means), a D variable (difference scores), or
a Y variable (a single column/level of the
within-subjects factor).
Depending on the research question, we might want to form confidence
intervals for: 1. A contrast among levels of the
between-subjects marginal mean.
A contrast among levels of the within-subjects marginal
mean.
A contrast among levels of the within-subjects factor at
a specific level of the between-subjects factor (Simple effect
of within).
A contrast among levels of the between-subjects factor at
a specific level of the within-subjects factor (Simple effect
of between).
An interaction contrast.
Let’s reproduce the five specific confidence intervals the book shows
in Table 14.12 (p. 816) and discusses one at a time on pp. 817–819. All
five assume a per-comparison alpha level of .05.
First, we need to set up the proper dependent variables. The text
operationalizes the quadratic trend with coefficients of , , and (p. 818), which is the scaling its
reported estimates use.
# Define the specific Quadratic D variable used in Table 14.12
# Coefficients: 0 degrees (-0.5), 4 degrees (1.0), 8 degrees (-0.5)
chapter_14_table_9$D_quad <-
-0.5 * chapter_14_table_9$Angle0 +
1.0 * chapter_14_table_9$Angle4 -
0.5 * chapter_14_table_9$Angle8
# Put "Old" first so that every two-group contrast below is Old minus Young,
# the direction in which the book reports these intervals. Re-creating the
# factor resets its contrasts, so the sum-to-zero coding is set again.
chapter_14_table_9$Age <- factor(chapter_14_table_9$Age, levels = c("Old", "Young"))
contrasts(chapter_14_table_9$Age) <- contr.sum
- Levels of Between-Subjects Marginal Means
Question: What is the age difference in reaction time, averaging over
all angles?
Variable: (The mean across the
three angles for each participant).
Because we are looking at the
variable, we have effectively collapsed our data into a simple
between-subjects design. We can run a standard independent samples -test, which is Equation 4.40 applied to
(p. 817).
# Between-Subjects Marginal Mean (Age diff on M)
ci_1 <- t.test(M ~ Age, data = chapter_14_table_9,
var.equal = TRUE, alternative = "two.sided", conf.level = 0.95)
cat(
"Estimate:", round(ci_1$estimate[1] - ci_1$estimate[2], 2), "\n",
"Standard Error:", round(ci_1$stderr, 2), "\n",
"t-value:", round(abs(ci_1$statistic), 2), "\n",
"95% CI: [", round(ci_1$conf.int[1], 2), ",",
round(ci_1$conf.int[2], 2), "]\n"
)
Estimate: 94
Standard Error: 34.85
t-value: 2.7
95% CI: [ 20.79 , 167.21 ]
#> Estimate 94, t = 2.70, 95% CI [20.79, 167.21] — matches book p. 817.
The estimate is 94 (). The value squared
() agrees within
rounding error with the value of
7.28 from our Age main effect test, which is the first of the two
verification checks the book recommends on p. 817.
- Levels of Within-Subjects Marginal Means
Question: What is the quadratic trend for the angle factor, averaging
over age?
Variable: (Evaluated
against a population mean of 0).
Averaging over groups, we are testing whether the grand mean of this
difference score is zero. The error term for that test is not
the total variance of : as
Equation 14.48 shows, it is the within-group variance, because the full
model for a variable in a
split-plot design keeps the between-subjects effect in it. With
sum-to-zero coding, the intercept of lm(D_quad ~ Age) is
the unweighted grand mean and its standard error is , so
confint() gives the interval directly, with degrees of freedom.
# Within-Subjects Marginal Mean (Quadratic trend on D_quad), pooled error
model_D_quad <- lm(D_quad ~ Age, data = chapter_14_table_9)
summary(model_D_quad)$coefficients["(Intercept)", ]
Estimate Std. Error t value Pr(>|t|)
5.2500000 9.3307288 0.5626570 0.5806094
confint(model_D_quad)["(Intercept)", ]
2.5 % 97.5 %
-14.35313 24.85313
#> Estimate 5.25, se 9.33, t = 0.56, 95% CI [-14.35, 24.85] — matches book p. 818.
# The marginal means of Angle that produce the estimate of 5.25.
colMeans(chapter_14_table_9[, c("Angle0", "Angle4", "Angle8")])
Angle0 Angle4 Angle8
510.0 619.5 718.5
#> 510, 619.5, and 718.5 — matches the marginal means on p. 818, and
#> -0.5(510) + 1(619.5) - 0.5(718.5) = 5.25.
The interval
contains 0, consistent with the nonsignificant , whose square is the of 0.32 we reported for the marginal
quadratic trend. A one-sample -test on D_quad would use
the total variance instead of the within-group variance and so would
not reproduce the book’s interval.
- Within-Subjects Factor at a Specified Level of Between-Subjects
Factor
Question: What is the quadratic trend specifically for younger
participants?
Variable: (Evaluated
only for the “Young” group, but using a pooled error term).
As the book explains on p. 818, the standard error here can be based
on the younger participants alone or on all participants if homogeneity
of variance is assumed; Table 14.12 reports the version that uses all
participants. We extract the pooled mean square within () from the same linear model as
above.
# Simple effect of within (Quadratic angle for Young, pooled error)
# Extract data for just the young group
young_D_quad <- subset(chapter_14_table_9, Age == "Young")$D_quad
# Get pooled variance from a linear model
lm_pooled <- lm(D_quad ~ Age, data = chapter_14_table_9)
MSW_pooled <- anova(lm_pooled)["Residuals", "Mean Sq"]
# Calculate SE and CI directly, to enforce the pooled error
estimate_3 <- mean(young_D_quad)
n_young <- length(young_D_quad)
se_3 <- sqrt(MSW_pooled / n_young)
t_val_3 <- estimate_3 / se_3
df_pooled <- lm_pooled$df.residual
tcrit <- qt(0.975, df = df_pooled)
cat(
"Estimate:", round(estimate_3, 2), "\n",
"Standard Error:", round(se_3, 2), "\n",
"t-value:", round(t_val_3, 2), "\n",
"95% CI: [", round(estimate_3 - tcrit * se_3, 2), ",",
round(estimate_3 + tcrit * se_3, 2), "]\n"
)
Estimate: 24
Standard Error: 13.2
t-value: 1.82
95% CI: [ -3.72 , 51.72 ]
#> Estimate 24, t = 1.82, 95% CI [-3.72, 51.72] — matches book p. 818, and
#> 1.82^2 is the F of 3.31 reported for this effect on p. 812.
- Between-Subjects Factor at a Specified Level of Within-Subjects
Factor
Question: What is the age difference specifically at the 8°
angle?
Variable: (The raw Angle8
column).
Because we are only looking at one specific angle condition, the
within-subjects nature of the design drops out entirely. We test this
using a standard independent samples -test on that single column.
# Simple effect of between (Age diff at 8 degrees)
ci_4 <- t.test(Angle8 ~ Age, data = chapter_14_table_9,
var.equal = TRUE, alternative = "two.sided", conf.level = 0.95)
cat(
"Estimate:", round(ci_4$estimate[1] - ci_4$estimate[2], 2), "\n",
"Standard Error:", round(ci_4$stderr, 2), "\n",
"t-value:", round(abs(ci_4$statistic), 2), "\n",
"95% CI: [", round(ci_4$conf.int[1], 2), ",",
round(ci_4$conf.int[2], 2), "]\n"
)
Estimate: 147
Standard Error: 38.07
t-value: 3.86
95% CI: [ 67.03 , 226.97 ]
#> Estimate 147 (792 - 645), 95% CI [67.03, 226.97] — matches book p. 818.
Interpretation: we are 95% confident that at 8°, older adults take
between 67.03 ms and 226.97 ms longer to react than younger adults. The
estimate of 147 is the difference between the mean values of 792 and 645
in Table 14.9, which is the book’s second verification check — the
contrast estimate is the intended linear combination of cell means.
- Interaction Contrast
Question: Is the linear trend for angle different for older
vs. younger participants?
Variable: (The linear
difference score, tested across the Age groups).
An interaction contrast effectively reduces the within-subjects
repeated measures down to a single difference score (). We then compare the two independent
groups on this score.
# 5. Interaction Contrast (Age diff in linear trend D1)
ci_5 <- t.test(D1 ~ Age, data = chapter_14_table_9,
var.equal = TRUE, alternative = "two.sided", conf.level = 0.95)
cat(
"Estimate:", round(ci_5$estimate[1] - ci_5$estimate[2], 2), "\n",
"Standard Error:", round(ci_5$stderr, 2), "\n",
"t-value:", round(abs(ci_5$statistic), 2), "\n",
"95% CI: [", round(ci_5$conf.int[1], 2), ",",
round(ci_5$conf.int[2], 2), "]\n"
)
Estimate: 81
Standard Error: 27.29
t-value: 2.97
95% CI: [ 23.66 , 138.34 ]
#> Estimate 81 (249 - 168), 95% CI [23.66, 138.34] — matches book p. 819.
Interpretation: the interval does not contain zero, confirming a significant
interaction. Increasing the angle from 0° to 8° causes a significantly
steeper increase in reaction time for older participants than it does
for younger participants, by somewhere between about 24 ms and 138
ms.
14.11 — Longitudinal Randomized Designs
Designs combining a between-subjects factor and a within-subjects
factor are incredibly common. A frequent special case is the
longitudinal randomized design, where the between-subjects factor is a
randomly assigned treatment condition (e.g., Treatment vs. Control) and
the within-subjects factor is time.
Crucially, in these designs, the first time point is often a baseline
(pretest) measure taken before the intervention begins.
The book’s example is a study of 100 participants, 44 assigned to an
active treatment and 56 to a control group, measured at a baseline and
two post-intervention occasions (p. 821). Table 14.13 gives the sample
means, which are all of the raw data the book reports for this example,
so we cannot reproduce its test statistics from the printed page. What
we can do is build a data set that has exactly those group means, carry
out each analysis the section describes on it, and state the book’s own
results beside them. The standard deviations and correlations below are
illustrative, not the book’s, and the text is explicit (p. 821) that
those are what determine whether the mean pattern is statistically
significant.
# MASS (mvrnorm) and car (Manova) are loaded above.
set.seed(113)
# Means from Table 14.13 (p. 821)
mu_Control <- c(98.71, 97.90, 99.49)
mu_Treatment <- c(98.14, 105.78, 107.48)
# An illustrative covariance matrix: SD = 22 at each occasion, r = .5 between
# occasions. The book reports no standard deviations for this example; this
# spread was chosen so that the mean pattern of Table 14.13 is about as hard
# to detect here as it is in the book's own data.
sigma <- matrix(c(484, 242, 242,
242, 484, 242,
242, 242, 484), nrow = 3)
# Generate data, then shift each group so that its sample means are exactly
# the means printed in Table 14.13.
n_Control <- 56
n_Treatment <- 44
match_means <- function(Y, mu) sweep(sweep(Y, 2, colMeans(Y)), 2, mu, "+")
data_Control <- match_means(mvrnorm(n_Control, mu_Control, sigma), mu_Control)
data_Treatment <- match_means(mvrnorm(n_Treatment, mu_Treatment, sigma), mu_Treatment)
# Combine into a single data frame, spelling out the condition level by level.
df_longitudinal <- data.frame(
Condition = factor(rep(c("Control", "Treatment"), c(n_Control, n_Treatment)),
levels = c("Control", "Treatment")),
Time1 = c(data_Control[, 1], data_Treatment[, 1]), # Baseline
Time2 = c(data_Control[, 2], data_Treatment[, 2]), # Post-intervention 1
Time3 = c(data_Control[, 3], data_Treatment[, 3]) # Post-intervention 2
)
head(df_longitudinal)
Condition Time1 Time2 Time3
1 Control 103.69661 102.91241 93.54411
2 Control 88.08470 81.45296 63.69278
3 Control 72.41065 77.80831 116.77315
4 Control 131.64773 125.59953 119.81621
5 Control 119.83545 91.78545 125.83002
6 Control 137.76032 135.18206 127.75664
# The cell means now reproduce Table 14.13 exactly.
df_longitudinal |>
group_by(Condition) |>
summarize(across(Time1:Time3, mean))
# A tibble: 2 × 4
Condition Time1 Time2 Time3
<fct> <dbl> <dbl> <dbl>
1 Control 98.7 97.9 99.5
2 Treatment 98.1 106. 107.
#> Control 98.71, 97.90, 99.49; Treatment 98.14, 105.78, 107.48
#> — matches Table 14.13 (p. 821).
The “naive” approach: a 2 x 3 repeated measures analysis
Because the data look just like the split-plot designs we analyzed
earlier in the chapter, our first instinct might be to run a 2
(Condition) 3 (Time)
analysis treating baseline simply as level 1 of the Time factor. By the
logic of Section 14.6, the Condition Time interaction is a MANOVA
comparing the groups on the two gain scores from baseline, which the
book states explicitly on p. 822.
# D variables are gain scores from baseline: this MANOVA IS the interaction test.
df_longitudinal$Gain1 <- df_longitudinal$Time2 - df_longitudinal$Time1
df_longitudinal$Gain2 <- df_longitudinal$Time3 - df_longitudinal$Time1
rm_interaction <- manova(cbind(Gain1, Gain2) ~ Condition, data = df_longitudinal)
summary(rm_interaction)
Df Pillai approx F num Df den Df Pr(>F)
Condition 1 0.049074 2.5029 2 97 0.08712 .
Residuals 98
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
For the book’s own data this test gives with (Table 14.14, p. 821), and none
of the three omnibus effects reaches the .05 level: Condition is , , and Time is , . Testing the simple effects at
each post-intervention occasion does not help either — the book reports
values of .095 and .084 (p. 822)
— and the linear component of the interaction misses as well, at (p. 822). The researcher is left
unable to conclude that the treatment worked. The illustrative data
above behave the same way: the interaction test does not reach the .05
level, even though the treatment group’s means rise by more than 9
points while the control group’s barely move.
Let’s look at why this happens and what we should do instead.
The better approach: MANCOVA (and ANCOVA)
As we learned in Chapter 9 for pretest-posttest designs, analyzing
the data using Analysis of Covariance (ANCOVA) is almost always superior
to using repeated measures ANOVA or analyzing simple gain scores.
Because we have two post-intervention measures here (Time 2 and Time
3), we generalize ANCOVA to Multivariate Analysis of Covariance
(MANCOVA).
Random assignment balances baseline scores in expectation, although
sample means can differ by chance. When baseline predicts the post-test
outcomes, adjusting for it can reduce residual variation.
Here is how we run a MANCOVA in R, predicting the post-intervention
scores from Condition, while covarying Baseline:
# Fit the multivariate linear model using Time1 as a covariate
mancova_model <- lm(cbind(Time2, Time3) ~ Condition + Time1, data = df_longitudinal)
# Run the MANOVA on the model
Manova(mancova_model)
Type II MANOVA Tests: Pillai test statistic
Df test stat approx F num Df den Df Pr(>F)
Condition 1 0.063026 3.2288 2 96 0.04395 *
Time1 1 0.302107 20.7785 2 96 3.176e-08 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
For the book’s data, the MANCOVA test of the Condition effect gives
with (p. 823) — statistically
significant where the 2 3
analysis of the same data was not. The same reversal happens with the
illustrative data above, for the same reason: covarying baseline removes
variance from the post-test scores that the gain-score analysis leaves
in the error term. The exact here
is not the book’s, because the book reports only the means for this
example, and these standard deviations and correlations are ours.
The adjusted condition effect compares the groups on their post-test
outcomes at a common baseline score.
We have bypassed the underpowered repeated measures analysis and
reached a conclusion the data can support, using the same participants
and the same measurements.
Follow-up tests: univariate ANCOVAs
If the omnibus MANCOVA is significant, we can test whether the groups
differ at specific measurement occasions using standard univariate
ANCOVAs.
# Test group difference at Time 2, covarying Baseline (Time 1)
ancova_time2 <- lm(Time2 ~ Condition + Time1, data = df_longitudinal)
car::Anova(ancova_time2, type = "III") # Type III recommended for ANCOVA with unbalanced designs
Anova Table (Type III tests)
Response: Time2
Sum Sq Df F value Pr(>F)
(Intercept) 8702 1 20.2651 1.877e-05 ***
Condition 1646 1 3.8321 0.05315 .
Time1 10853 1 25.2730 2.276e-06 ***
Residuals 41655 97
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Test group difference at Time 3, covarying Baseline (Time 1)
ancova_time3 <- lm(Time3 ~ Condition + Time1, data = df_longitudinal)
car::Anova(ancova_time3, type = "III")
Anova Table (Type III tests)
Response: Time3
Sum Sq Df F value Pr(>F)
(Intercept) 9444 1 28.0040 7.513e-07 ***
Condition 1689 1 5.0095 0.0275 *
Time1 10693 1 31.7071 1.745e-07 ***
Residuals 32711 97
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
By accounting for the baseline variance, these ANCOVAs provide more
power and precision than the simple effects tests derived from the 2
3 analysis, for the reason
Equation 9.49 gives: they use the correlation between baseline and each
post-intervention measure, which the simple effects tests ignore.
The row to read in each table is Condition. For the
book’s data these two ANCOVAs give with at the
first post-intervention occasion and with at the
second (p. 823) — both significant, where the corresponding simple
effects tests in the 2 3
analysis gave and . That is not a contradiction but
the power difference at work.
The two follow-up ANCOVAs are easiest to read side by side. With
modelsummary, each model occupies its own column with
fit statistics at the foot:
modelsummary(
list("Time 2 (covary baseline)" = ancova_time2,
"Time 3 (covary baseline)" = ancova_time3),
estimate = "{estimate}",
statistic = "({std.error})", # standard errors in parentheses, APA style
gof_map = c("nobs", "aic", "bic", "logLik"),
stars = TRUE,
output = "gt"
)
| |
Time 2 (covary baseline) |
Time 3 (covary baseline) |
| (Intercept) |
47.136 |
49.102 |
|
(10.471) |
(9.279) |
| ConditionTreatment |
8.173 |
8.281 |
|
(4.175) |
(3.700) |
| Time1 |
0.514 |
0.510 |
|
(0.102) |
(0.091) |
| Num.Obs. |
100 |
100 |
| AIC |
895.0 |
870.8 |
| BIC |
905.4 |
881.2 |
| Log.Lik. |
-443.494 |
-431.409 |
| + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001 |
The same comparison as a gtsummary table, each model
under its own spanning header:
t_time2 <- tbl_regression(ancova_time2, intercept = TRUE)
t_time3 <- tbl_regression(ancova_time3, intercept = TRUE)
tbl_merge(list(t_time2, t_time3),
tab_spanner = c("**Time 2**", "**Time 3**"))
| Characteristic |
Time 2
|
Time 3
|
| Beta |
95% CI |
p-value |
Beta |
95% CI |
p-value |
| (Intercept) |
47 |
26, 68 |
<0.001 |
49 |
31, 68 |
<0.001 |
| Condition |
|
|
|
|
|
|
| Control |
— |
— |
|
— |
— |
|
| Treatment |
8.2 |
-0.11, 16 |
0.053 |
8.3 |
0.94, 16 |
0.027 |
| Time1 |
0.51 |
0.31, 0.72 |
<0.001 |
0.51 |
0.33, 0.69 |
<0.001 |
| Abbreviation: CI = Confidence Interval |
An alternative formulation: MANCOVA on gain scores
Some researchers prefer to analyze the data in a way that makes
“change” more explicit.
The book notes (p. 823) that running a MANCOVA predicting the raw
post-test scores while covarying baseline is mathematically identical to
running a MANCOVA predicting the gain scores while covarying baseline.
That identity does not depend on the particular data, so it is something
we can demonstrate exactly here.
# The gain scores from baseline, created above for the interaction test.
# Fit MANCOVA on the Gain scores, covarying Baseline
mancova_gain_model <- lm(cbind(Gain1, Gain2) ~ Condition + Time1, data = df_longitudinal)
# Results
Manova(mancova_gain_model)
Type II MANOVA Tests: Pillai test statistic
Df test stat approx F num Df den Df Pr(>F)
Condition 1 0.063026 3.2288 2 96 0.04395 *
Time1 1 0.282237 18.8745 2 96 1.222e-07 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The Condition row is identical to the one in the MANCOVA
on the raw post-tests. Base R will state the comparison as a model
comparison, which isolates the Condition test and makes the equality
explicit:
# The Condition effect as a comparison of full and restricted models.
mancova_reduced <- lm(cbind(Time2, Time3) ~ Time1, data = df_longitudinal)
mancova_gain_reduced <- lm(cbind(Gain1, Gain2) ~ Time1, data = df_longitudinal)
post_test_route <- anova(mancova_reduced, mancova_model, test = "Pillai")
gain_score_route <- anova(mancova_gain_reduced, mancova_gain_model, test = "Pillai")
post_test_route
Analysis of Variance Table
Model 1: cbind(Time2, Time3) ~ Time1
Model 2: cbind(Time2, Time3) ~ Condition + Time1
Res.Df Df Gen.var. Pillai approx F num Df den Df Pr(>F)
1 98 362.75
2 97 -1 354.75 0.063026 3.2288 2 96 0.04395 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Analysis of Variance Table
Model 1: cbind(Gain1, Gain2) ~ Time1
Model 2: cbind(Gain1, Gain2) ~ Condition + Time1
Res.Df Df Gen.var. Pillai approx F num Df den Df Pr(>F)
1 98 362.75
2 97 -1 354.75 0.063026 3.2288 2 96 0.04395 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# The two routes give the same test, to numerical precision.
all.equal(post_test_route[["approx F"]], gain_score_route[["approx F"]])
[1] TRUE
The two analyses give the same Pillai statistic, the same , and the same value, exactly as the book says they
must (p. 823). Some researchers prefer the gain-score form because it
makes the question about change explicit, and because it lends itself to
testing change within each group separately.