QUESTION 3.20 a,b

#NULL HYPOTHESIS:H0:MU1=MU2=MU3=MU4=MU
#ALTERNATIVE HYPOTHESIS:Atleast one MUi differs where i={1,2,3,4}


#importing the given data

RLV10<-c(1530, 1530, 1440)
RLV15<-c(1610, 1650, 1500)
RLV20<-c(1560, 1730, 1530)
RLV25<-c(1500, 1490, 1510)


R<-rbind(RLV10,RLV15,RLV20,RLV25)
#calculating the grand average and mean 
GAvg<-c(mean(R))

R1<-mean(RLV10)
R2<-mean(RLV15)
R3<-mean(RLV20)

R4<-mean(RLV25)
#calculating SSE, SSTr, MSTr, F Statistic and Critical Regions

SSEa<-(1530-R1)^2+(1530-R1)^2+(1440-R1)^2
SSEb<-(1610-R2)^2+(1650-R2)^2+(1500-R2)^2
SSEc<-(1560-R3)^2+(1730-R3)^2+(1530-R3)^2
SSEd<-(1500-R4)^2+(1490-R4)^2+(1510-R4)^2

SSE<-SSEa+SSEb+SSEc+SSEd

MSE <- SSE / (8)

str(MSE)
##  num 5117
SSTr <- 3*((R1 - GAvg)^2 + (R2 - GAvg)^2 + (R3 - GAvg)^2 + (R4 - GAvg)^2)

str(SSTr)
##  num 28633
MSTr <- SSTr / (3)

str(MSTr)
##  num 9544
SST <- SSE + SSTr

str(SST)
##  num 69567
Statistic <- MSTr / MSE

str(Statistic)
##  num 1.87
qf(0.95, 3, 8)
## [1] 4.066181
#Answer a

#Therefore we have F statistic value (1.87) is less than critical value (4.066)
#So, we fail to reject H0 and by this we can conclude that there is no difference in compressive strength due to the rodding level

#Answer b

#By the above values in statistics in a F distribution calculator, we found the P value which is (0.2138) 
#other method

p<-cbind.data.frame(RLV10,RLV15,RLV20,RLV25)
p<-aov(values  ~ ind, data = (stack(p)))
summary(p)
##             Df Sum Sq Mean Sq F value Pr(>F)
## ind          3  28633    9544   1.865  0.214
## Residuals    8  40933    5117