question 3.6

# Hypothesis Test

#  H0: (alpha)_i = 0 for all i
# (Ha): (alpha)_i != 0 for some i

# (H0): (beta)_j = 0 for all j
# (Ha): (beta)_j != 0 for some j

# (H0): (alpha)_i*(beta)_j = 0 for all i,j
# (Ha): (alpha)_i*(beta)_j != 0 for some i,j

RESPONSE <- 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)
TIME <- rep(c(-1,1,-1,1),6)
MEDIUM <- rep(c(-1,-1,1,1),6)
MODEL1 <- aov(RESPONSE~TIME*MEDIUM)
summary(MODEL1)
##             Df Sum Sq Mean Sq F value Pr(>F)
## TIME         1   30.4   30.37   0.806  0.380
## MEDIUM       1    9.4    9.38   0.249  0.623
## TIME:MEDIUM  1    0.4    0.37   0.010  0.922
## Residuals   20  753.5   37.67
# FROM RESULT interaction p-value =  0.922 > alpha(0.05). so, we fail to reject the Null Hypothesis.

MODEL1 <- aov(RESPONSE~TIME+MEDIUM)
summary(MODEL1)
##             Df Sum Sq Mean Sq F value Pr(>F)
## TIME         1   30.4   30.37   0.846  0.368
## MEDIUM       1    9.4    9.38   0.261  0.615
## Residuals   21  753.9   35.90
# As p-values of time=0.368,medium = 0.615 > alpha= 0.05 So, we fail to reject the Null Hypothesis. This states that the factors are insignificant. 

plot(MODEL1)

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

# From plot of the residuals, we states that it  has unequal variance
# The Normal Probability it shows that it is a Normal Distributionplot
# From plot, we sates  that assumption of model adequate is violated.

question 6.12

# Hypothesis Test

# (H0): (alpha)_i = 0 for all i
#  (Ha): (alpha)_i != 0 for some i

#  (H0): (beta)_j = 0 for all j
#  (Ha): (beta)_j != 0 for some j

#  (H0): (alpha)_i*(beta)_j = 0 for all i,j
#  (Ha): (alpha)_i*(beta)_j != 0 for some i,j

#  6.12 (a)

observations <- 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 <- rep(c(-1,1,-1,1),4)
B <- rep(c(-1,-1,1,1),4)
model2 <- aov(observations~A+B+A*B)
summary(model2)
##             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
coef(model2)
## (Intercept)           A           B         A:B 
##   14.513875   -0.158625    0.293000    0.140750
# As p-value = 0.3386 > alpha = 0.05. So, we fail to reject the Null Hypothesis.

# 6.12 b

model2 <- aov(observations~A+B)
summary(model2)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## A            1  0.403  0.4026   1.263 0.2815  
## B            1  1.374  1.3736   4.308 0.0584 .
## Residuals   13  4.145  0.3189                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# As p-value of factors(A,B) = 0.0584 > alpha = 0.05. so, we fail to reject the Null Hypothesis. From this result we states that none of the  factor is significant. 



# 6.12 d
plot(model2)

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

# From residual plots, we states that  datais unequal variance
#  Normal Probability plot, we state that data follows to the Normal Distribution. It shows that  outlier 5 is present.

# 6.12 e

# One possibility of outlier can be due to wrongly entered reading. This to be  corrected by note down  the readings correctly by performing the experiment once more  time .

question 6.21

#  Hypothesis Test

#  (H0): (alpha)_i = 0 for all i
#  (Ha): (alpha)_i != 0 for some i

#  (H0): (beta)_j = 0 for all j
#  (Ha): (beta)_j != 0 for some j

#  (H0): (gamma)_k = 0 for all k
#  (Ha): (gamma)_k != 0 for some k

#  (H0): (delta)_l = 0 for all l
#  (Ha): (delta)_l != 0 for some l


LOP <- rep(c(-1,1,-1,1),28)
TOP <- rep(c(-1,-1,1,1),28)
BOP <- rep(c(-1,-1,-1,-1,1,1,1,1),14)
SOP <- rep(c(rep(-1,8),rep(1,8)),7)
response <- 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)
model3 <- aov(response~LOP*TOP*BOP*SOP)
summary(model3)
##                 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
# 6.21 a

# As p-value of LOB = (0.00157 and type = 0.03686 are < alpha= 0.05. SO, we conclude that the factors lenght of putt and type of putt significantly effect putting performance.

# 6.21 b
plot(model3)

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

# From the Residuals plot, we can conclude that our data has unequal variance, Normal Probability plot showa that our data shows Normal Distribution , we can conclude that there is an indication of model inadequate.

question 6.36

#  Hypothesis Test

#  (H0): (alpha)_i = 0 for all i
#  (Ha): (alpha)_i != 0 for some i

#  (H0): (beta)_j = 0 for all j
#  (Ha): (beta)_j != 0 for some j

#  (H0): (gamma)_k = 0 for all k
#  (Ha): (gamma)_k != 0 for some k

#  (H0): (delta)_l = 0 for all l
#  (Ha): (delta)_l != 0 for some l

A <- rep(c(-1,1,-1,1),4)
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))
res <- 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)
library(DoE.base)
## 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
# 6.21 a 

model4 <- aov(res~A*B*C*D) 
summary(model4)
##             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
coef(model4)
## (Intercept)           A           B           C           D         A:B 
##    4.680625    3.160625   -1.501875   -0.220625   -0.079375   -1.069375 
##         A:C         B:C         A:D         B:D         C:D       A:B:C 
##   -0.298125    0.229375   -0.056875   -0.046875    0.029375    0.344375 
##       A:B:D       A:C:D       B:C:D     A:B:C:D 
##   -0.096875   -0.010625    0.094375    0.141875
halfnormal(model4)
## 
## Significant effects (alpha=0.05, Lenth method):
## [1] A     B     A:B   A:B:C

# From half normal plot, we can conclude that the factors A,B,A*B,A*B*C has significant effects.

# Tentative Model

model4 <- aov(res~A+B+C+A*B+A*B*C)
summary(model4)
##             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
# As this model is significant, p-values of A,B,c,A*B,A*B*C are less than the value of alpha(0.05)

#  6.21 (b)
plot(model4)

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

# From the Residuals plot, we can conclude that our data has unequal variance.  Normal Probability plot, we state that our data follows approximately Normal Distribution. From plot we state that there is an indication of model inadequaate

# 6.21 (c)

Transformed <- log(res)

# Estimation of Factors
Transformed_model <- aov(Transformed~A*B*C*D)
summary(Transformed_model)
##             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
# Half normal plot for Transformed Data
halfnormal(Transformed_model)
## 
## Significant effects (alpha=0.05, Lenth method):
## [1] A     B     A:B:C

# From the plot, we conclude that the factors A,B,C,A*B*C has significant effect

# Tentative model
Transformed_model1 <- aov(Transformed~A+B+C+A*B*C)
summary(Transformed_model1)
##             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(Transformed_model1)

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

# From the Residuals plot, we can conclude that our data has unequal variance.
# From the Normal Probability plot, we can conclude that our data follows approximately Normal Distribution.
# From the plots, we can conclude that there is an indication of model inadequacy.
# There is an improvement in the variance of the data. However, it is not sufficient to conclude that our data has equal variance. Moreover before transformation was done interactions A*B, A*C, B*C and factor C are significant. After transformation they are insignificant.

question 6.39

# Hypothesis Test

#  (H0): (alpha)_i = 0 for all i
#  (Ha): (alpha)_i != 0 for some i

#  (H0): (beta)_j = 0 for all j
#  (Ha): (beta)_j != 0 for some j

#  (H0): (gamma)_k = 0 for all k
#  (Ha): (gamma)_k != 0 for some k

#  (H0): (delta)_l = 0 for all l
#  (Ha): (delta)_l != 0 for some l

#  (H0): (epsilon)_m = 0 for all m
#  (Ha): (epsilon)_m != 0 for some m

library(DoE.base)
## 6.39 a

A <- rep(c(-1,1,-1,1),8)
B <- rep(c(-1,-1,1,1),8)
C <- rep(c(rep(-1,4),rep(1,4)),4)
D <- rep(c(rep(-1,8),rep(1,8)),2)
E <- rep(c(rep(-1,16),rep(1,16)))
y <- c(8.11,5.56,5.77,5.82,9.17,7.8,3.23,5.69,8.82,14.23,9.2,8.94,8.68,11.49,6.25,9.12,7.93,5,7.47,12,9.86,3.65,6.4,11.61,12.43,17.55,8.87,25.38,13.06,18.85,11.78,26.05)
model5 <- aov(y~A*B*C*D*E)
summary(model5)
##             Df Sum Sq Mean Sq
## A            1  83.56   83.56
## B            1   0.06    0.06
## C            1   0.00    0.00
## D            1 285.78  285.78
## E            1 153.17  153.17
## A:B          1  48.93   48.93
## A:C          1   0.00    0.00
## B:C          1   1.22    1.22
## A:D          1  88.88   88.88
## B:D          1   0.01    0.01
## C:D          1   0.00    0.00
## A:E          1  33.76   33.76
## B:E          1  52.71   52.71
## C:E          1   2.91    2.91
## D:E          1  61.80   61.80
## A:B:C        1   2.01    2.01
## A:B:D        1   3.82    3.82
## A:C:D        1   0.13    0.13
## B:C:D        1   2.98    2.98
## A:B:E        1  44.96   44.96
## A:C:E        1   2.15    2.15
## B:C:E        1   0.94    0.94
## A:D:E        1  26.01   26.01
## B:D:E        1   0.05    0.05
## C:D:E        1   5.02    5.02
## A:B:C:D      1   0.18    0.18
## A:B:C:E      1   1.09    1.09
## A:B:D:E      1   5.31    5.31
## A:C:D:E      1   0.52    0.52
## B:C:D:E      1   0.18    0.18
## A:B:C:D:E    1   4.04    4.04
halfnormal(model5)
## 
## Significant effects (alpha=0.05, Lenth method):
##  [1] D     E     A:D   A     D:E   B:E   A:B   A:B:E A:E   A:D:E

# From the Half normal plot, we conclude that the significant effects are D,E,A:D,A,D:E,B:E,A:B,A:B:E,A:E,A:D:E 

#6.39 b
qqnorm(y)

## By the normality plot we can see that is normally distributed .

#c 

model5 <- aov(y~A*B*D*E)
summary(model5)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## A            1  83.56   83.56  57.233 1.14e-06 ***
## B            1   0.06    0.06   0.041 0.841418    
## D            1 285.78  285.78 195.742 2.16e-10 ***
## E            1 153.17  153.17 104.910 1.97e-08 ***
## A:B          1  48.93   48.93  33.514 2.77e-05 ***
## A:D          1  88.88   88.88  60.875 7.66e-07 ***
## B:D          1   0.01    0.01   0.004 0.950618    
## A:E          1  33.76   33.76  23.126 0.000193 ***
## B:E          1  52.71   52.71  36.103 1.82e-05 ***
## D:E          1  61.80   61.80  42.328 7.24e-06 ***
## A:B:D        1   3.82    3.82   2.613 0.125501    
## A:B:E        1  44.96   44.96  30.794 4.40e-05 ***
## A:D:E        1  26.01   26.01  17.815 0.000650 ***
## B:D:E        1   0.05    0.05   0.035 0.854935    
## A:B:D:E      1   5.31    5.31   3.634 0.074735 .  
## Residuals   16  23.36    1.46                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(model5)

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

# From the result model5 we can is 2^5 factorial design to  model5 2^4 factorial design interactions