For the latin square, the latin letter (ingredients) should not repeat in each row and each column. Here the 5 ingredients appear once in each row and each column.
The model equation is:
\(X_{ij} = \mu + \tau_{i} +\beta_{j} + \alpha_{k} +\epsilon_{ijk}\)
where,
\(X{ij}\) = observations
\(\mu\) = grand mean
\(\tau_{i}\)= effect of i
\(\beta_{j}\)= first block factor
\(\alpha_{k}\)= second block factor
\(\epsilon_{ijk}\) = random error
The required hypothesis is :
\(H\_{0}:\tau\_{i}=0\)
\(H_{0}:\tau_{i} \neq 0\)
df<-expand.grid(seq(1,5),seq(1,5))
colnames(df)<-c("Day","Batch")
df$Day<-as.factor(df$Day)
df$Batch<-as.factor(df$Batch)
df$Ingredient<-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")
df$Response<-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)
df$Ingredient <- as.factor(df$Ingredient)
str(df)
## 'data.frame': 25 obs. of 4 variables:
## $ Day : Factor w/ 5 levels "1","2","3","4",..: 1 2 3 4 5 1 2 3 4 5 ...
## $ Batch : Factor w/ 5 levels "1","2","3","4",..: 1 1 1 1 1 2 2 2 2 2 ...
## $ Ingredient: Factor w/ 5 levels "A","B","C","D",..: 1 2 4 3 5 3 5 1 4 2 ...
## $ Response : num 8 7 1 7 3 11 2 7 3 8 ...
## - attr(*, "out.attrs")=List of 2
## ..$ dim : int [1:2] 5 5
## ..$ dimnames:List of 2
## .. ..$ Var1: chr [1:5] "Var1=1" "Var1=2" "Var1=3" "Var1=4" ...
## .. ..$ Var2: chr [1:5] "Var2=1" "Var2=2" "Var2=3" "Var2=4" ...
model <- lm(Response~Batch+Day+Ingredient, data = df)
aov <- aov(model)
summary(aov)
## 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
Here, the p-value of the factor of interest i.e. ingredient (0.000488) is less than the value of alpha(0.05). So, we reject null hypothesis.