A Latin Square design requires every treatment to appear exactly once in each row and exactly once in each column.
In this experiment, the five ingredients (A, B, C, D, and E) each appear once in every batch and once on every day. Therefore, this is a valid \(5 \times 5\) Latin Square design.
The linear effects model is
\[ Y_{ijk}=\mu+\alpha_i+\beta_j+\tau_k+\epsilon_{ijk} \]
where:
Batch and day are blocking factors, and ingredient is the factor of interest.
# Reaction times arranged by batch (rows) and day (columns)
batch <- factor(rep(1:5, each=5))
day <- factor(rep(1:5, times=5))
ingredient <- factor(c(
"A", "B", "D", "C", "E",
"C", "E", "A", "D", "B",
"B", "A", "C", "E", "D",
"D", "C", "E", "B", "A",
"E", "D", "B", "A", "C"
))
reaction <- c(
8, 7, 1, 7, 3,
11, 2, 7, 3, 8,
4, 9, 10, 1, 5,
6, 8, 6, 6, 10,
4, 2, 3, 8, 8
)
dat <- data.frame(batch, day, ingredient, reaction)
dat
## batch day ingredient reaction
## 1 1 1 A 8
## 2 1 2 B 7
## 3 1 3 D 1
## 4 1 4 C 7
## 5 1 5 E 3
## 6 2 1 C 11
## 7 2 2 E 2
## 8 2 3 A 7
## 9 2 4 D 3
## 10 2 5 B 8
## 11 3 1 B 4
## 12 3 2 A 9
## 13 3 3 C 10
## 14 3 4 E 1
## 15 3 5 D 5
## 16 4 1 D 6
## 17 4 2 C 8
## 18 4 3 E 6
## 19 4 4 B 6
## 20 4 5 A 10
## 21 5 1 E 4
## 22 5 2 D 2
## 23 5 3 B 3
## 24 5 4 A 8
## 25 5 5 C 8
The null and alternative hypotheses for the ingredient effect are
\[ H_0:\mu_A=\mu_B=\mu_C=\mu_D=\mu_E \]
\[ H_a:\text{At least one ingredient mean differs} \]
The significance level is \(\alpha=0.05\).
model <- aov(reaction ~ batch + day + ingredient, data=dat)
summary(model)
## Df Sum Sq Mean Sq F value Pr(>F)
## batch 4 15.44 3.86 1.235 0.347618
## day 4 12.24 3.06 0.979 0.455014
## ingredient 4 141.44 35.36 11.309 0.000488 ***
## Residuals 12 37.52 3.13
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
aggregate(reaction ~ ingredient, data=dat, mean)
## ingredient reaction
## 1 A 8.4
## 2 B 5.6
## 3 C 8.8
## 4 D 3.4
## 5 E 3.2
anova_table <- summary(model)[[1]]
F_ingredient <- anova_table["ingredient", "F value"]
p_ingredient <- anova_table["ingredient", "Pr(>F)"]
cat("F-statistic for ingredient =", F_ingredient, "\n")
## F-statistic for ingredient = 11.30917
cat("P-value for ingredient =", p_ingredient, "\n")
## P-value for ingredient = 0.0004876512
if (p_ingredient < 0.05) {
cat("Decision: Reject the null hypothesis.\n")
cat("Conclusion: There is significant evidence that mean reaction time differs among the ingredients.\n")
} else {
cat("Decision: Fail to reject the null hypothesis.\n")
cat("Conclusion: There is insufficient evidence that mean reaction time differs among the ingredients.\n")
}
## Decision: Reject the null hypothesis.
## Conclusion: There is significant evidence that mean reaction time differs among the ingredients.
The ANOVA results are approximately:
\[ F=11.3092 \]
\[ p=0.000488 \]
Since \(p<0.05\), we reject the null hypothesis.
Conclusion: At the 0.05 significance level, there is sufficient evidence that the mean reaction time differs among the five ingredients. Therefore, ingredient type has a statistically significant effect on reaction time after accounting for batch and day.
The effects of batch and day are included in the model to account for variation associated with these two blocking factors.
batch <- factor(rep(1:5, each=5))
day <- factor(rep(1:5, times=5))
ingredient <- factor(c(
"A", "B", "D", "C", "E",
"C", "E", "A", "D", "B",
"B", "A", "C", "E", "D",
"D", "C", "E", "B", "A",
"E", "D", "B", "A", "C"
))
reaction <- c(
8, 7, 1, 7, 3,
11, 2, 7, 3, 8,
4, 9, 10, 1, 5,
6, 8, 6, 6, 10,
4, 2, 3, 8, 8
)
dat <- data.frame(batch, day, ingredient, reaction)
model <- aov(reaction ~ batch + day + ingredient, data=dat)
summary(model)
aggregate(reaction ~ ingredient, data=dat, mean)
anova_table <- summary(model)[[1]]
F_ingredient <- anova_table["ingredient", "F value"]
p_ingredient <- anova_table["ingredient", "Pr(>F)"]
cat("F-statistic for ingredient =", F_ingredient, "\n")
cat("P-value for ingredient =", p_ingredient, "\n")
if (p_ingredient < 0.05) {
cat("Decision: Reject the null hypothesis.\n")
cat("Conclusion: There is significant evidence that mean reaction time differs among the ingredients.\n")
} else {
cat("Decision: Fail to reject the null hypothesis.\n")
cat("Conclusion: There is insufficient evidence that mean reaction time differs among the ingredients.\n")
}