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
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)
c <- c(-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1)
d <- c(-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1)
obs <- 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)
dat <- data.frame(a,b,c,d,obs)
model <- aov(obs~a*b*c*d,data=dat)
summary(model)# its normally distributed plot
##             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(model)# from the plot we can say a,b,a*b,a*b*c have significant effect
## 
## Significant effects (alpha=0.05, Lenth method):
## [1] a     b     a:b   a:b:c

#model1
model1 <- aov(obs~a+b+c+a*b+a*b*c)
summary(model1)# in this siginificant model, p-values of a,b,c,a*b,a*b*c is less than alpha(0.05)
##             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(model1)# From the Residuals plot, we can say data have unequal variance.

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

# From the Normal Probability plot, we can say data is Normally Distributed.
# we can also conclude that there is an indication of model inadequacy.
transform <- log(obs)
transform_model2 <- aov(transform~a*b*c*d)
summary(transform_model2)
##             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(transform_model2)
## 
## Significant effects (alpha=0.05, Lenth method):
## [1] a     b     a:b:c

# From the plot, we can say that the factors a,b,c,a*b*c has significant effect from the plot.
transform_model2 <- aov(transform~a+b+c+a*b*c)
summary(transform_model2)
##             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(transform_model2)

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

# From the Residuals plot, we can say data have unequal variance.
# From the Normal Probability plot, we can say data is approx Normally Distributed.
# we can also conclude that there is an indication of model inadequacy.
# we can say that the varience is better but, dont have enough evidance to conclude that it has a equal varience.
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)
t <- c(-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1)
cm <-c(-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1)
model <- aov(observation~t+cm+t*cm)
summary(model)
##             Df Sum Sq Mean Sq F value Pr(>F)
## t            1   30.4   30.37   0.806  0.380
## cm           1    9.4    9.38   0.249  0.623
## t:cm         1    0.4    0.37   0.010  0.922
## Residuals   20  753.5   37.67
model <- aov(observation~t+cm)
summary(model)
##             Df Sum Sq Mean Sq F value Pr(>F)
## t            1   30.4   30.37   0.846  0.368
## cm           1    9.4    9.38   0.261  0.615
## Residuals   21  753.9   35.90
# p-values of t,cm, and t*cm are greater than alpha(0.05), so its insignificant and we fail to reject the Null Hypothesis.
plot(model)

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

# From residual plot we can say that data has unequal variance
# From the NPP, we can say that data is Normally Distributed.
a <- c(-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-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,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1)
c <- c(-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1)
d <- c(-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1)
e <- c(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
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)
exp <- aov(y~a*b*c*d*e)
summary(exp)
##             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
ob <- 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 <- 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)
exp <- aov(ob~A+B+A*B)
summary(exp)
##             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
# p-value A(0.2833) , B(0.0602), a:b(0.3386) which is grater than alpha 0.05.
exp_1 <- aov(ob~A+B)
summary(exp_1)# p-value  A(0.2815) B(0.0584)
##             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
plot(exp_1)

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

# From the Residuals plot, we can say data have unequal variance.
# From the Normal Probability plot, we can say data is approx Normally Distributed.
# we can also conclude that there is an indication of model inadequacy.
len <- c(-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,
       1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,
       1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,
       -1,1,-1,1)
types <- c(-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,
              1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,
              -1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,
              -1,-1,1,1,-1,-1,1,1)
br <- c(-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,
           1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,
           -1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,1)
slope <- c(-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,
               -1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,
               1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1)
distance <- 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)
model <- aov(distance~len*types*br*slope)
summary(model)
##                    Df Sum Sq Mean Sq F value  Pr(>F)   
## len                 1    917   917.1  10.588 0.00157 **
## types               1    388   388.1   4.481 0.03686 * 
## br                  1    145   145.1   1.676 0.19862   
## slope               1      1     1.4   0.016 0.89928   
## len:types           1    219   218.7   2.525 0.11538   
## len:br              1     12    11.9   0.137 0.71178   
## types:br            1    115   115.0   1.328 0.25205   
## len:slope           1     94    93.8   1.083 0.30066   
## types:slope         1     56    56.4   0.651 0.42159   
## br:slope            1      2     1.6   0.019 0.89127   
## len:types:br        1      7     7.3   0.084 0.77294   
## len:types:slope     1    113   113.0   1.305 0.25623   
## len:br:slope        1     39    39.5   0.456 0.50121   
## types:br:slope      1     34    33.8   0.390 0.53386   
## len:types:br: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
#  p-value of len(0.00157) & types(0.03686) are less than alpha(0.05),
#so we can say that the factors len and types significantly affect putting performance.

plot(model)

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

# From the Residuals plot, we can say data have unequal variance.
# From the Normal Probability plot, we can say data is Normally Distributed.
# we can also conclude that there is an indication of model inadequacy.