##  question 7.12

LOP<-c(rep(c(rep(-1,7), rep(1, 7)), 8))
TOP<-c(rep(c(rep(-1,14), rep(1, 14)), 4))
BOP<-c(rep(c(rep(-1,28), rep(1, 28)), 2))
SOP<-c(rep(-1, 56), rep(1, 56))
block<-c(rep(seq(1,7), 16))
response<-c(10.0, 18.0, 14.0, 12.5, 19.0, 16.0, 18.5, 0.0, 16.5, 4.5, 17.5, 20.5, 17.5, 33.0,
4.0, 6.0, 1.0, 14.5, 12.0, 14.0, 5.0, 0.0, 10.0, 34.0, 11.0, 25.5, 21.5, 0.0,
0.0, 0.0, 18.5, 19.5, 16.0, 15.0, 11.0, 5.0, 20.5, 18.0, 20.0, 29.5, 19.0, 10.0,
6.5, 18.5, 7.5, 6.0, 0.0, 10.0, 0.0, 16.5, 4.5, 0.0, 23.5, 8.0, 8.0, 8.0,
4.5, 18.0, 14.5, 10.0, 0.0, 17.5, 6.0, 19.5, 18.0, 16.0, 5.5, 10.0, 7.0, 36.0,
15.0, 16.0, 8.5, 0.0, 0.5, 9.0, 3.0, 41.5, 39.0, 6.5, 3.5, 7.0, 8.5, 36.0,
8.0, 4.5, 6.5, 10.0, 13.0, 41.0, 14.0, 21.5, 10.5, 6.5, 0.0, 15.5, 24.0, 16.0,
0.0, 0.0, 0.0, 4.5, 1.0, 4.0, 6.5, 18.0, 5.0, 7.0, 10.0, 32.5, 18.5, 8.0)
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.
LOP<-as.fixed(LOP)
TOP<-as.fixed(TOP)
BOP<-as.fixed(BOP)
SOP<-as.fixed(SOP)
block<-as.random(block)

dat<-data.frame(LOP,TOP,BOP,SOP,response)

## anova test without blocking
model<- aov(response ~ LOP*TOP*BOP*SOP)
summary(model)
##                 Df Sum Sq Mean Sq F value  Pr(>F)   
## LOP              1    917   917.1  10.588 0.00157 **
## TOP              1    388   388.1   4.481 0.03686 * 
## BOP              1    145   145.1   1.676 0.19862   
## SOP              1      1     1.4   0.016 0.89928   
## LOP:TOP          1    219   218.7   2.525 0.11538   
## LOP:BOP          1     12    11.9   0.137 0.71178   
## TOP:BOP          1    115   115.0   1.328 0.25205   
## LOP:SOP          1     94    93.8   1.083 0.30066   
## TOP:SOP          1     56    56.4   0.651 0.42159   
## BOP:SOP          1      2     1.6   0.019 0.89127   
## LOP:TOP:BOP      1      7     7.3   0.084 0.77294   
## LOP:TOP:SOP      1    113   113.0   1.305 0.25623   
## LOP:BOP:SOP      1     39    39.5   0.456 0.50121   
## TOP:BOP:SOP      1     34    33.8   0.390 0.53386   
## LOP:TOP:BOP:SOP  1     96    95.6   1.104 0.29599   
## Residuals       96   8316    86.6                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##From the ANOVA  test  we can see that lop and top are not significant. The p-value for length is0.00157 and type is  0.03686 and so we could say that only these factors are significant.

## now we test with LOP and TOP With blocking

## anova test with blocking

model1<- aov(response ~ LOP*TOP* + block)
summary(model1)
##               Df Sum Sq Mean Sq F value  Pr(>F)   
## LOP            1    917   917.1  10.273 0.00191 **
## TOP            1    388   388.1   4.348 0.04009 * 
## block          6    376    62.7   0.702 0.64870   
## LOP:TOP        1    219   218.7   2.450 0.12132   
## LOP:block      6    487    81.2   0.910 0.49222   
## TOP:block      6    503    83.9   0.940 0.47126   
## LOP:TOP:block  6    165    27.4   0.307 0.93149   
## Residuals     84   7499    89.3                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## So, finally after blocking and just running with these two factors we get the p-values for those factors as  0.00191  for LOP and TOP is 0.04009 for type which indicates that they are significant.

###source code

LOP<-c(rep(c(rep(-1,7), rep(1, 7)), 8))
TOP<-c(rep(c(rep(-1,14), rep(1, 14)), 4))
BOP<-c(rep(c(rep(-1,28), rep(1, 28)), 2))
SOP<-c(rep(-1, 56), rep(1, 56))
block<-c(rep(seq(1,7), 16))
response<-c(10.0, 18.0, 14.0, 12.5, 19.0, 16.0, 18.5, 0.0, 16.5, 4.5, 17.5, 20.5, 17.5, 33.0,
4.0, 6.0, 1.0, 14.5, 12.0, 14.0, 5.0, 0.0, 10.0, 34.0, 11.0, 25.5, 21.5, 0.0,
0.0, 0.0, 18.5, 19.5, 16.0, 15.0, 11.0, 5.0, 20.5, 18.0, 20.0, 29.5, 19.0, 10.0,
6.5, 18.5, 7.5, 6.0, 0.0, 10.0, 0.0, 16.5, 4.5, 0.0, 23.5, 8.0, 8.0, 8.0,
4.5, 18.0, 14.5, 10.0, 0.0, 17.5, 6.0, 19.5, 18.0, 16.0, 5.5, 10.0, 7.0, 36.0,
15.0, 16.0, 8.5, 0.0, 0.5, 9.0, 3.0, 41.5, 39.0, 6.5, 3.5, 7.0, 8.5, 36.0,
8.0, 4.5, 6.5, 10.0, 13.0, 41.0, 14.0, 21.5, 10.5, 6.5, 0.0, 15.5, 24.0, 16.0,
0.0, 0.0, 0.0, 4.5, 1.0, 4.0, 6.5, 18.0, 5.0, 7.0, 10.0, 32.5, 18.5, 8.0)
library(GAD)
LOP<-as.fixed(LOP)
TOP<-as.fixed(TOP)
BOP<-as.fxed(BOP)
SOP<-as.fixed(SOP)
block<-as.random(block)

dat<-data.frame(LOP,TOP,BOP,SOP,response)


model<- aov(response ~ LOP*TOP*BOP*SOP)
summary(model)

model1<- aov(response ~ LOP*TOP* + block)
summary(model1)