The effect of five different ingredients (A, B, C, D, E) on the reaction time of a chemical process is being studied. Each batch of new material is only large enough to permit five runs to be made. Furthermore, each run requires approximately 1.5 hours, so only five runs can be made in one day. The experimenter decides to run the experiment as a Latin square so that day and batch effects may be systematically controlled.
Yes, this is a valid Latin square, This problem has 3 factors and this data is setup as a 3 x 3 matrix. All Latin Squares have to be a square matrix. In each row of the matrix each letter occurs only once. Additionally, in each column, each letter occur only once. So this problem satisfies the requirement of a Latin square design.
\[\begin{array}{l} {y_{ijk}} = \mu + {\alpha _i} + {\tau _j} + {\beta _k} + {\varepsilon _{ijk}}\\ i = 1,2,3,4,5\\ j = 1,2,3,4,5\\ k = 1,2,3,4,5 \end{array}\]
We first setup the data and data frame for the Latin Square
#setup initial data and data frame
#setup batch
batch <- c(rep("batch1",1), rep("batch2",1), rep("batch3",1), rep("batch4",1), rep("batch5",1))
#setup day
day <- c(rep("day1",5), rep("day2",5), rep("day3",5), rep("day4",5), rep("day5",5))
#input letters for Latin Square
ingredient <- c("A","C","B","D","E", "B","E","A","C","D", "D","A","C","E","B", "C","D","E","B","A", "E","B","D","A","C")
#setup runtimes
runtime <- c(8,11,4,6,4,7,2,9,8,2,1,7,10,6,3,7,3,1,6,8,3,8,5,10,8)
#convert batch, ingredient, and day to factors
batch<-as.factor(batch)
day<-as.factor(day)
ingredient<-as.factor(ingredient)
#setup data frame
mydata <- data.frame(day, batch, ingredient, runtime)
Now let’s analyze our result.
#Let's get down to business
#Setup Latin Square with the runtime versus blocks and ingredients
myfit <- lm(runtime ~ batch+day+ingredient, mydata)
#cover<-aov(myfit)
#summary(cover)
#Let's do our ANOVOA analysis.
#I'm using anova for final summary since it gives more precision
anova(myfit)
## Analysis of Variance Table
##
## Response: runtime
## Df Sum Sq Mean Sq F value Pr(>F)
## batch 4 15.44 3.860 1.2345 0.3476182
## day 4 12.24 3.060 0.9787 0.4550143
## ingredient 4 141.44 35.360 11.3092 0.0004877 ***
## Residuals 12 37.52 3.127
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
It is evident from this result that batch and day do are not affecting the result, since the P-values of batch and day are 0.3476 and 0.4550 respectively. Only the ingredient is having an effect on the result with an extremely small P-value of 0.0004877.
#setup initial data and data frame
#setup batch
batch <- c(rep("batch1",1), rep("batch2",1), rep("batch3",1), rep("batch4",1), rep("batch5",1))
#setup day
day <- c(rep("day1",5), rep("day2",5), rep("day3",5), rep("day4",5), rep("day5",5))
#input letters for Latin Square
ingredient <- c("A","C","B","D","E", "B","E","A","C","D", "D","A","C","E","B", "C","D","E","B","A", "E","B","D","A","C")
#setup runtimes
runtime <- c(8,11,4,6,4,7,2,9,8,2,1,7,10,6,3,7,3,1,6,8,3,8,5,10,8)
#convert batch, ingredient, and day to factors
batch<-as.factor(batch)
day<-as.factor(day)
ingredient<-as.factor(ingredient)
#setup data frame
mydata <- data.frame(day, batch, ingredient, runtime)
#print out data frame to verify
mydata
#just for extra verification display matrices of ingredient & runtime
matrix(mydata$ingredient, 5,5)
matrix(mydata$runtime, 5,5)
#Let's get down to business
#Setup Latin Square with the runtime versus blocks and ingredients
myfit <- lm(runtime ~ batch+day+ingredient, mydata)
cover<-aov(myfit)
summary(cover)
#Let's do our ANOVOA analysis.
#I'm using anova for final summary since it gives more precision
anova(myfit)