#question 4.3 #chemical is factctor (level=4) bolt is a block (level=5)

library(GAD)
## Loading required package: matrixStats
## Loading required package: R.methodsS3
## R.methodsS3 v1.8.1 (2020-08-26 16:20:06 UTC) successfully loaded. See ?R.methodsS3 for help.
#x_ij=mu+alfa_i+beta_j+e_ij
chemical <- c(rep(1,5),rep(2,5),rep(3,5),rep(4,5))
bolt <- c(seq(1,5),seq(1,5),seq(1,5),seq(1,5)) 
observation <- c(73,68,74,71,67,73,67,75,72,70,75,68,78,73,68,73,71,75,75,69)
chemical <- as.fixed(chemical)
bolt <- as.fixed(bolt)

model <- lm(observation~chemical+bolt)
gad(model)
## Analysis of Variance Table
## 
## Response: observation
##          Df Sum Sq Mean Sq F value    Pr(>F)    
## chemical  3  12.95   4.317  2.3761    0.1211    
## bolt      4 157.00  39.250 21.6055 2.059e-05 ***
## Residual 12  21.80   1.817                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

x_ijk = mu + t_i + alpha_j + e_ijk

Ho: t_i = 0

Ha: t_i != 0

Based on the p-value of 0.1211, we fail to reject Ho since 0.7644 > alpha = 0.05

#question 4.16

c1<-c(73,68,74,71,67)
c2<-c(73,67,75,72,70)
c3<-c(75,68,78,73,68)
c4<-c(73,71,75,75,69)
c <- c(c1,c2,c3,c4)
mean(c1)
## [1] 70.6
mean(c2)
## [1] 71.4
mean(c3)
## [1] 72.4
mean(c4)
## [1] 72.6
mean(c)
## [1] 71.75
tou_1 <- mean(c1)-mean(c)
tou_2 <- mean(c2)-mean(c)
tou_3 <- mean(c3)-mean(c)
tou_4 <- mean(c4)-mean(c)
# tou_1=-1.15,tou_2=-0.34,tou_3=0.65,tou_4=0.84
#swaping rows into column.
c5 <- c(73,73,75,73)
c6 <- c(68,67,68,71)
c7 <- c(74,75,78,75)
c8 <- c(71,72,73,75)
c9 <- c(67,70,68,69)
cr <- c(c5,c6,c7,c8,c9)
mean(c5)
## [1] 73.5
mean(c6)
## [1] 68.5
mean(c7)
## [1] 75.5
mean(c8)
## [1] 72.75
mean(cr)
## [1] 71.75
beta_1 <- mean(c5)-mean(cr)
beta_2 <- mean(c6)-mean(cr)
beta_3 <- mean(c7)-mean(cr)
beta_4 <- mean(c8)-mean(cr)
beta_5 <- mean(c9)-mean(cr)
#beta_1=1.75,beta_2=-3.25,beta_3=3.75,beta_4=1

#question 3.22

batch <- c(rep(1,5),rep(2,5),rep(3,5),rep(4,5),rep(5,5))
batch
##  [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5
days <- c(seq(1,5),seq(1,5),seq(1,5),seq(1,5),seq(1,5))
days
##  [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
ingr <- 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")
obs<- 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)
batch <- as.factor(batch)
days <- as.factor(days)
ingr <- as.factor(ingr)
aov.model <- aov(obs~batch+days+ingr)
summary(aov.model)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## batch        4  15.44    3.86   1.235 0.347618    
## days         4  12.24    3.06   0.979 0.455014    
## ingr         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

x_ijk = mu + t_i + alpha_j + e_ijk

Ho: t_i = 0

Ha: t_i != 0

Based on the p-value of 0.000488 we can reject Ho, Ho: A=B=C=D=E=mean.

Thus, ingredient does have an effect on the reaction time of the chemical process.

Further analysis:

Based on the p-value for batch of 0.347618, we fail to reject Ho since 0.347618 > alpha = 0.05

Based on the p-value for day of 0.455014, we fail to reject Ho