library(DoE.base)
## Warning: package 'DoE.base' was built under R version 4.2.2
## Loading required package: grid
## Loading required package: conf.design
## Registered S3 method overwritten by 'DoE.base':
##   method           from       
##   factorize.factor conf.design
## 
## Attaching package: 'DoE.base'
## The following objects are masked from 'package:stats':
## 
##     aov, lm
## The following object is masked from 'package:graphics':
## 
##     plot.design
## The following object is masked from 'package:base':
## 
##     lengths
Time_h<-c(rep(-1, 12),rep(1, 12) )
culture_medium<-rep(c(rep(-1, 2),rep(1, 2)),6)
observation <- c(21,22,25,26,23,28,24,25,20,26,29,27,37,39,31,34,38,38,29,33,35,36,30,35)
dat<- data.frame(Time_h,culture_medium,observation)
Test1 <- aov(observation~Time_h*culture_medium,data=dat)
summary(Test1) 
##                       Df Sum Sq Mean Sq F value   Pr(>F)    
## Time_h                 1  590.0   590.0 115.506 9.29e-10 ***
## culture_medium         1    9.4     9.4   1.835 0.190617    
## Time_h:culture_medium  1   92.0    92.0  18.018 0.000397 ***
## Residuals             20  102.2     5.1                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(Test1)

## hat values (leverages) are all = 0.1666667
##  and there are no factor predictors; no plot no. 5

Answer From the above plot p-value less than level of significance.we reject the null hypothesis H0.The interaction effect between time and the medium is significant

Question 6.12

library(DoE.base)
A <- c(-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1)
B <- c(-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1)
observation1<- c(14.037,13.880,14.821,14.888,16.165,13.860,14.757,14.921,13.972,14.032,14.843,14.415,13.907,13.914,14.878,14.932)
A <- as.factor(A)
B <- as.factor(B)
data1 <- data.frame(A,B,observation1)

(a)

A<- c(14.037,16.165,13.972,13.907)
B <- c(13.88,13.86,14.032,13.914)
C <- c(14.821,14.757,14.843,14.878)
D <- c(14.888,14.921,14.415,14.932)

SA <- sum(A)
SB <- sum(B)
SC <- sum(C)
SD <- sum(D)

factorA <- (2*(SB+SD-SA-SC)/(4*4))
factorB <- (2*(SC+SD-SA-SB)/(4*4))
factorAB <- (2*(SB+SC-SA-SD)/(4*4))
factorA
## [1] -0.31725
factorB
## [1] 0.586
factorAB
## [1] -0.2815

The factor effect of A=-0.31725,B=0.586,c=-0.2815

(b)

Test2 <- aov(observation1~A*B,data = data1)
summary(Test2)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## A            1  0.403  0.4026   1.262 0.2833  
## B            1  1.374  1.3736   4.305 0.0602 .
## A:B          1  0.317  0.3170   0.994 0.3386  
## Residuals   12  3.828  0.3190                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

No factors apper to be significant

(c)

Test2 <- lm(observation1~A*B,data = data1)
coef(Test2)
## (Intercept)          A1          B1       A1:B1 
##    14.52025    -0.59875     0.30450     0.56300
summary(Test2)
## 
## Call:
## lm.default(formula = observation1 ~ A * B, data = data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.61325 -0.14431 -0.00563  0.10188  1.64475 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  14.5202     0.2824  51.414 1.93e-15 ***
## A1           -0.5987     0.3994  -1.499    0.160    
## B1            0.3045     0.3994   0.762    0.461    
## A1:B1         0.5630     0.5648   0.997    0.339    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5648 on 12 degrees of freedom
## Multiple R-squared:  0.3535, Adjusted R-squared:  0.1918 
## F-statistic: 2.187 on 3 and 12 DF,  p-value: 0.1425

##Final Equation in Terms of Coded Factors: ### Thickness = +14.52 -0.5987A1 +0.3045B1 +0.5630AB

(d)

plot(Test2)

observation 5 falls outside in Q-Q plot.

(e)

##one method is to replace the observation with average value

Question 6.21

length <- rep(c(-1,1,-1,1),28)
Type <- rep(c(-1,-1,1,1),28)
Break <- rep(c(-1,-1,-1,-1,1,1,1,1),14)
slope <- c(rep(-1,8),rep(1,8))
slope <- rep(slope,7)
observation3 <- c(10.0,0.0,4.0,0.0,0.0,5.0,6.5,16.5,4.5,19.5,15.0,41.5,8.0,21.5,0.0,18.0,
              18.0,16.5,6.0,10.0,0.0,20.5,18.5,4.5,18.0,18.0,16.0,39.0,4.5,10.5,0.0,5.0,
              14.0,4.5,1.0,34.0,18.5,18.0,7.5,0.0,14.5,16.0,8.5,6.5,6.5,6.5,0.0,7.0,
              12.5,17.5,14.5,11.0,19.5,20.0,6.0,23.5,10.0,5.5,0.0,3.5,10.0,0.0,4.5,10.0,
              19.0,20.5,12.0,25.5,16.0,29.5,0.0,8.0,0.0,10.0,0.5,7.0,13.0,15.5,1.0,32.5,
              16.0,17.5,14.0,21.5,15.0,19.0,10.0,8.0,17.5,7.0,9.0,8.5,41.0,24.0,4.0,18.5,
              18.5,33.0,5.0,0.0,11.0,10.0,0.0,8.0,6.0,36.0,3.0,36.0,14.0,16.0,6.5,8.0)
Test3 <- aov(observation3~length*Type*Break*slope)
summary(Test3)
##                         Df Sum Sq Mean Sq F value  Pr(>F)   
## length                   1    917   917.1  10.588 0.00157 **
## Type                     1    388   388.1   4.481 0.03686 * 
## Break                    1    145   145.1   1.676 0.19862   
## slope                    1      1     1.4   0.016 0.89928   
## length:Type              1    219   218.7   2.525 0.11538   
## length:Break             1     12    11.9   0.137 0.71178   
## Type:Break               1    115   115.0   1.328 0.25205   
## length:slope             1     94    93.8   1.083 0.30066   
## Type:slope               1     56    56.4   0.651 0.42159   
## Break:slope              1      2     1.6   0.019 0.89127   
## length:Type:Break        1      7     7.3   0.084 0.77294   
## length:Type:slope        1    113   113.0   1.305 0.25623   
## length:Break:slope       1     39    39.5   0.456 0.50121   
## Type:Break:slope         1     34    33.8   0.390 0.53386   
## length:Type:Break:slope  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
## Checking Model Adequacy using plot

plot(Test3)

## hat values (leverages) are all = 0.1428571
##  and there are no factor predictors; no plot no. 5

### Answer: ### (a) the p-values of lenth of putt and type of putt is < .05 ### they are considered as significant.

(b) The plot appears to be norml but has unequal variance.

variance shows model inadequacy

Question 6.36

library(DoE.base)

A <- rep(c(-1,1),8)
B <- rep(c(-1,-1,1,1),4)
C <- rep(c(-1,-1,-1,-1,1,1,1,1),2)
D <- c(rep(-1,8),rep(1,8))
observation4 <- c(1.92,11.28,1.09,5.75,
              2.13,9.53,1.03,5.35,
              1.60,11.73,1.16,4.68,
              2.16,9.11,1.07,5.30)

Test4<- aov(observation4~A*B*C*D) 
summary(Test4)
##             Df Sum Sq Mean Sq
## A            1 159.83  159.83
## B            1  36.09   36.09
## C            1   0.78    0.78
## D            1   0.10    0.10
## A:B          1  18.30   18.30
## A:C          1   1.42    1.42
## B:C          1   0.84    0.84
## A:D          1   0.05    0.05
## B:D          1   0.04    0.04
## C:D          1   0.01    0.01
## A:B:C        1   1.90    1.90
## A:B:D        1   0.15    0.15
## A:C:D        1   0.00    0.00
## B:C:D        1   0.14    0.14
## A:B:C:D      1   0.32    0.32
halfnormal(Test4)
## 
## Significant effects (alpha=0.05, Lenth method):
## [1] A     B     A:B   A:B:C

Test5 <- aov(observation4~A+B+C+A*B+A*B*C)
summary(Test5)
##             Df Sum Sq Mean Sq  F value   Pr(>F)    
## A            1 159.83  159.83 1563.061 1.84e-10 ***
## B            1  36.09   36.09  352.937 6.66e-08 ***
## C            1   0.78    0.78    7.616  0.02468 *  
## A:B          1  18.30   18.30  178.933 9.33e-07 ***
## A:C          1   1.42    1.42   13.907  0.00579 ** 
## B:C          1   0.84    0.84    8.232  0.02085 *  
## A:B:C        1   1.90    1.90   18.556  0.00259 ** 
## Residuals    8   0.82    0.10                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(Test5)

## hat values (leverages) are all = 0.5
##  and there are no factor predictors; no plot no. 5

#library()
log_resp <- log(observation4)
log_resp
##  [1] 0.65232519 2.42303125 0.08617770 1.74919985 0.75612198 2.25444472
##  [7] 0.02955880 1.67709656 0.47000363 2.46214966 0.14842001 1.54329811
## [13] 0.77010822 2.20937271 0.06765865 1.66770682
log_Test <- aov(log_resp~A*B*C*D)
summary(log_Test)
##             Df Sum Sq Mean Sq
## A            1 10.572  10.572
## B            1  1.580   1.580
## C            1  0.001   0.001
## D            1  0.005   0.005
## A:B          1  0.010   0.010
## A:C          1  0.025   0.025
## B:C          1  0.000   0.000
## A:D          1  0.001   0.001
## B:D          1  0.000   0.000
## C:D          1  0.005   0.005
## A:B:C        1  0.064   0.064
## A:B:D        1  0.014   0.014
## A:C:D        1  0.000   0.000
## B:C:D        1  0.000   0.000
## A:B:C:D      1  0.016   0.016
halfnormal(log_Test)
## 
## Significant effects (alpha=0.05, Lenth method):
## [1] A     B     A:B:C

log_Test1 <- aov(log_resp~A+B+C+A*B*C)
summary(log_Test1)
##             Df Sum Sq Mean Sq  F value   Pr(>F)    
## A            1 10.572  10.572 1994.556 6.98e-11 ***
## B            1  1.580   1.580  298.147 1.29e-07 ***
## C            1  0.001   0.001    0.124  0.73386    
## A:B          1  0.010   0.010    1.839  0.21207    
## A:C          1  0.025   0.025    4.763  0.06063 .  
## B:C          1  0.000   0.000    0.054  0.82223    
## A:B:C        1  0.064   0.064   12.147  0.00826 ** 
## Residuals    8  0.042   0.005                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(log_Test1)

## hat values (leverages) are all = 0.5
##  and there are no factor predictors; no plot no. 5

## (a) the Factor effects are the Mean Square values ## From halfnormal plot, factors ā€ A,B,C,A+B,A+B+C ā€ have significant effects ## New model= Test5

(b) The plot appears to be norml but has unequal variance.

variance shows model inadequacy

(c) From the plot, ā€œA,B,C,A+B+Cā€ has significant effect

New Model= log_Test1

slight improvement in the variance is observed afterlog transfermation

(d) The final model= log_Test1