This report presents the statistical analysis for the three project parts.

Project Part 1

First, in part 1, to perform an analysis of variance experiment, we collected data for three kinds of balls, keeping the Pin Elevation and Bungee Position both in the highest setting. In Part 1, We had the objective to determine the effect of the type of ball on the distance in which the ball is thrown. Three balls: Red, Yellow, and Mix were used to conduct the experiment.

The analysis for part 1 is illustrated below.

A) Determine how many samples should be collected to detect a mean difference with a medium effect (i.e. 50% of the standard deviation) and a pattern of maximum variability with a probability of 75%.

pwr.anova.test(k=3,n=NULL,f=((0.5*sqrt((3^2)-1))/(2*3)),sig.level = 0.05,power = 0.75)
## 
##      Balanced one-way analysis of variance power calculation 
## 
##               k = 3
##               n = 52.55574
##               f = 0.2357023
##       sig.level = 0.05
##           power = 0.75
## 
## NOTE: n is number in each group

We needed to collect 53 samples of each population. In total we need to collected 159 samples for the experiment.

B) Propose a layout using the number of samples from part (a) with randomized run order

trt<-c("yellow","red","mix")
experimentdesign<-design.crd(trt=trt,r= 53,seed=981273)
print(experimentdesign)
## $parameters
## $parameters$design
## [1] "crd"
## 
## $parameters$trt
## [1] "yellow" "red"    "mix"   
## 
## $parameters$r
## [1] 53 53 53
## 
## $parameters$serie
## [1] 2
## 
## $parameters$seed
## [1] 981273
## 
## $parameters$kinds
## [1] "Super-Duper"
## 
## $parameters[[7]]
## [1] TRUE
## 
## 
## $book
##     plots  r    trt
## 1     101  1    mix
## 2     102  2    mix
## 3     103  1    red
## 4     104  2    red
## 5     105  1 yellow
## 6     106  3    mix
## 7     107  3    red
## 8     108  2 yellow
## 9     109  3 yellow
## 10    110  4    mix
## 11    111  4 yellow
## 12    112  5    mix
## 13    113  6    mix
## 14    114  4    red
## 15    115  5    red
## 16    116  5 yellow
## 17    117  6 yellow
## 18    118  6    red
## 19    119  7    mix
## 20    120  7    red
## 21    121  8    mix
## 22    122  8    red
## 23    123  9    mix
## 24    124 10    mix
## 25    125  9    red
## 26    126  7 yellow
## 27    127 10    red
## 28    128 11    red
## 29    129  8 yellow
## 30    130  9 yellow
## 31    131 12    red
## 32    132 11    mix
## 33    133 10 yellow
## 34    134 12    mix
## 35    135 13    red
## 36    136 14    red
## 37    137 15    red
## 38    138 13    mix
## 39    139 11 yellow
## 40    140 16    red
## 41    141 14    mix
## 42    142 12 yellow
## 43    143 13 yellow
## 44    144 15    mix
## 45    145 16    mix
## 46    146 17    red
## 47    147 14 yellow
## 48    148 18    red
## 49    149 15 yellow
## 50    150 19    red
## 51    151 17    mix
## 52    152 16 yellow
## 53    153 20    red
## 54    154 21    red
## 55    155 22    red
## 56    156 18    mix
## 57    157 23    red
## 58    158 24    red
## 59    159 19    mix
## 60    160 20    mix
## 61    161 17 yellow
## 62    162 21    mix
## 63    163 25    red
## 64    164 18 yellow
## 65    165 22    mix
## 66    166 26    red
## 67    167 19 yellow
## 68    168 23    mix
## 69    169 20 yellow
## 70    170 27    red
## 71    171 24    mix
## 72    172 21 yellow
## 73    173 22 yellow
## 74    174 28    red
## 75    175 25    mix
## 76    176 26    mix
## 77    177 23 yellow
## 78    178 24 yellow
## 79    179 25 yellow
## 80    180 29    red
## 81    181 30    red
## 82    182 26 yellow
## 83    183 31    red
## 84    184 27    mix
## 85    185 32    red
## 86    186 27 yellow
## 87    187 28 yellow
## 88    188 29 yellow
## 89    189 28    mix
## 90    190 29    mix
## 91    191 30    mix
## 92    192 31    mix
## 93    193 30 yellow
## 94    194 31 yellow
## 95    195 32 yellow
## 96    196 33 yellow
## 97    197 32    mix
## 98    198 33    red
## 99    199 33    mix
## 100   200 34 yellow
## 101   201 34    mix
## 102   202 35 yellow
## 103   203 36 yellow
## 104   204 37 yellow
## 105   205 34    red
## 106   206 35    red
## 107   207 36    red
## 108   208 38 yellow
## 109   209 35    mix
## 110   210 39 yellow
## 111   211 40 yellow
## 112   212 36    mix
## 113   213 41 yellow
## 114   214 37    red
## 115   215 37    mix
## 116   216 38    red
## 117   217 42 yellow
## 118   218 38    mix
## 119   219 39    red
## 120   220 39    mix
## 121   221 40    mix
## 122   222 41    mix
## 123   223 43 yellow
## 124   224 42    mix
## 125   225 43    mix
## 126   226 44    mix
## 127   227 44 yellow
## 128   228 40    red
## 129   229 45 yellow
## 130   230 45    mix
## 131   231 41    red
## 132   232 42    red
## 133   233 43    red
## 134   234 44    red
## 135   235 46    mix
## 136   236 46 yellow
## 137   237 47 yellow
## 138   238 47    mix
## 139   239 48    mix
## 140   240 49    mix
## 141   241 50    mix
## 142   242 51    mix
## 143   243 48 yellow
## 144   244 45    red
## 145   245 46    red
## 146   246 47    red
## 147   247 48    red
## 148   248 49    red
## 149   249 49 yellow
## 150   250 52    mix
## 151   251 50 yellow
## 152   252 50    red
## 153   253 51 yellow
## 154   254 53    mix
## 155   255 51    red
## 156   256 52    red
## 157   257 53    red
## 158   258 52 yellow
## 159   259 53 yellow

The sequence above represents the order in which we have to collect the data.

C) Collect data and record observations on layout proposed in part (b)

Data was collected on class.

D)Perform hypothesis test and check residuals.Be sure to comment and take corrective action if necessary.

Null hypothesis: \(H_0: \mu_{1}=\mu_{2}=\mu_{3}=\mu\) Alternative hypothesis: \(H_1:\) at least one \(\mu_{i}\) differs

Nº 1 represents mix ball, Nº 2 represents red ball and Nº 3 represents yellow ball.

obs<-c(71,85,152,104,164,147,161,70,83,168,155,78,87,102,98,130,88,97,157,75,89,78,97,110,139,128,133,94,78,123,93,81,103,138,78,75,139,111,145,75,88,98,149,120,138,91,68,93,120,94,110,87,90,66,113,84,64,80,74,92,82,72,72,88,82,88,75,89,63,88,90,101,83,72,60,98,73,82,70,90,65,95,56,76,78,82,98,74,77,65,63,89,75,90,104,89,65,63,87,76,77,87,90,93,65,84,110,98,107,132,86,125,133,59,113,90,97,86,124,88,130,87,60,98,103,89,78,89,109,120,78,91,124,90,99,102,84,93,74,105,103,87,92,64,98,78,72,99,104,97,67,88,83,81,92,104,82,91,75)

ball<-c(rep(1,53),rep(2,53),rep(3,53))

dat<-data.frame(obs,ball)
dat$ball<-as.factor(dat$ball)
model<-aov(dat$obs~dat$ball, data = dat)
summary(model)
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## dat$ball      2  20418   10209   23.45 1.25e-09 ***
## Residuals   156  67917     435                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Analysis

The P-value of the test is 1.25e-09 which is less than \(\alpha\) of 0.05. Hence, we reject the Null hypothesis. \(H_1:\) at least one \(\mu_{i}\) differs.

Cheking the residuals

plot(model)

boxplot(dat$obs~dat$ball, data = dat, main="Boxplot of observations")

Analysis

Even if from the Normal plot of residuals we draw that it passes the fat pencil test and it is roughly normally distribute, the plot of residuals versus predicted has a strong outward-opening funnel shape, which indicates the variance of the original observations is not constant. From the boxplot We can see difference in percentile ranges indicating difference in means. Is suggested to use Box-Cox power transformation to stabilize variance.

Using Box-Cox power transformation to stabilize variance.

boxcox(dat$obs~dat$ball, data = dat)

lambda = 0.5
dat$obs<-dat$obs^lambda

Verifying data after transformation

model1<-aov(dat$obs~dat$ball, data = dat)
summary(model1)
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## dat$ball      2   50.0   25.00   23.59 1.12e-09 ***
## Residuals   156  165.3    1.06                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
boxplot(dat$obs~dat$ball, data = dat, main="Boxplot of transformed observations")

Analysis

After plotting transformed data, we can see that we corrected the data in “mix”, and “yellow” but the effect on “red” is limited. Overall, we fail to correct the variance and the p-value of the test is 1.12e-09 which is less \(/alpha\) of 0.05. Hence, we reject the Null hypothesis even for the transformed data as well.

E) If the null hypothesis is rejected, investigate pairwise comparisons.

investigating pairwise comparisons

TukeyHSD(model1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = dat$obs ~ dat$ball, data = dat)
## 
## $`dat$ball`
##           diff        lwr        upr     p adj
## 2-1 -1.3718948 -1.8450731 -0.8987165 0.0000000
## 3-1 -0.6260351 -1.0992134 -0.1528569 0.0058722
## 3-2  0.7458597  0.2726814  1.2190380 0.0007786
plot(TukeyHSD(model1))

Analysis

The Tukey Test indicates there is difference in the pairs of treatments: red-mix, yellow-mix, red-yellow.

F) State all findings and make recommendation.

From the results of the test, we can say that every ball has different mean of distance and the all three pairs differs in mean. It can be recommended that if all the balls have same weight and size than maybe the means of distances can be same.Once the different materials and density of each ball influence the distance that each ball reaches.

Another highlight is the variability in the data collection. For example, in the middle of the experiment, the rope broke, and we needed to fix it and re-start the data collection. Maybe this incident contributed to increasing the non-uniformity of measures for each ball. Moreover, there is the variability of the operator . We could see the operator’s tidiness once we needed to sit on the floor in an uncomfortable position to perform the experiment. Finally, the time was another factor that may have influenced, since there were many groups to collect data during the class period, so, had a concern about collecting the data fast.

This way, to guarantee the accuracy of the data to set up a better-controlled environment to collect data might be a suggestion.

Project Part 2

According Montgomery (2013),factorial designs are efficient in the analysis of experiments that involve the study of effects of two or more factors. To perform the project part 2 we based on the concepts of Factorial Design for Mix effects.

In Part 2 we had the objective to analyze the effect of Pin Elevation and Release Angle on distance in which a red ball is thrown when the Bungee Position is fixed at the second position.In addition, he settings of one and three of Pin Elevation was analyzed as a fixed effect, as well as settings of the Release Angle corresponding to 110, 140, and 170 degrees as a random effect.The design was replicated three times.

The analysis for part 2 is illustrated below.

A) State model equation with the null and alternative hypotheses to be tested. In addition. state the level of significance that will be used in your analysis.

Model equation: \(Y_{ijk}=\mu+\alpha_{i}+\beta_{j}+\alpha\beta_{ij}+e_{ijk}\)

The level of significance for this analysis is \(\alpha=0,05\)

B) Propose a layout with a randomized run order.

library(agricolae)
trts2<-c(2,3)
design.ab(trt=trts2, r=3, design="crd", randomization=TRUE, seed=156812)
## $parameters
## $parameters$design
## [1] "factorial"
## 
## $parameters$trt
## [1] "1 1" "1 2" "1 3" "2 1" "2 2" "2 3"
## 
## $parameters$r
## [1] 3 3 3 3 3 3
## 
## $parameters$serie
## [1] 2
## 
## $parameters$seed
## [1] 156812
## 
## $parameters$kinds
## [1] "Super-Duper"
## 
## $parameters[[7]]
## [1] TRUE
## 
## $parameters$applied
## [1] "crd"
## 
## 
## $book
##    plots r A B
## 1    101 1 2 3
## 2    102 1 1 3
## 3    103 1 2 2
## 4    104 1 2 1
## 5    105 2 2 3
## 6    106 1 1 2
## 7    107 2 1 3
## 8    108 2 1 2
## 9    109 1 1 1
## 10   110 2 1 1
## 11   111 2 2 2
## 12   112 2 2 1
## 13   113 3 1 1
## 14   114 3 2 2
## 15   115 3 2 3
## 16   116 3 1 3
## 17   117 3 2 1
## 18   118 3 1 2

The layout for the design proposed is showed above.

C) Collect data and record observations on the layout proposed in part (A).

Data was collected during the class and the data are showed below:

Angle<-rep(seq(1,3), 3)
Pin<-c(rep(1,9), rep(2,9))

Dist<-c(27,42,49,
        27,38,51,
        26,40,50,
        33,49,79,
        29,46,63,
        29,43,67)
Dat2<-data.frame(Pin,Angle,Dist)

D) Test the hypotheses and state conclusions, determining those effects that are significant. Show any plots that might be useful/necessary to show your findings. You may also show residual plots and make appropriate comments, but do not transform the data (i.e. use the raw data regardless of normality and variance constancy).

Hypothesis for Mixed effects.

Interaction Pin (Fixxed) and Angle (Random) Null hypothesis: \(H_0: \sigma^2_{\alpha\beta}=0\) Alternative hypothesis: \(H_1: \sigma^2_{\alpha\beta}!0\)

Factor Pin (Fixxed) Null hypothesis: \(H_0: \alpha_{i}=0\) Alternative hypothesis: \(H_1: \alpha_{i}!0\)

Factor Angle (Random) Null hypothesis: \(H_0: \sigma^2_{\beta}=0\) Alternative hypothesis: \(H_1: \sigma^2_{\beta}!0\)

Testing the hypothesis

library(GAD)
## Loading required package: matrixStats
## 
## Attaching package: 'matrixStats'
## The following object is masked from 'package:dplyr':
## 
##     count
## Loading required package: R.methodsS3
## R.methodsS3 v1.8.1 (2020-08-26 16:20:06 UTC) successfully loaded. See ?R.methodsS3 for help.
Dat2$Pin<-as.fixed(Dat2$Pin)
Dat2$Angle<-as.random(Dat2$Angle)
Model2<-aov(Dist~Angle+Pin+Angle*Pin, data = Dat2)
GAD::gad(Model2)
## Analysis of Variance Table
## 
## Response: Dist
##           Df  Sum Sq Mean Sq F value    Pr(>F)    
## Angle      2 2950.78 1475.39 99.4644 3.391e-08 ***
## Pin        1  430.22  430.22  3.8394  0.189138    
## Angle:Pin  2  224.11  112.06  7.5543  0.007524 ** 
## Residual  12  178.00   14.83                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Analysis

With the p-value=0.007524 < than \(\alpha=0,05\), we reject the Null hypothesis (\(H_0: \sigma^2_{\alpha\beta}=0\)) and conclude the interaction between the factors Pin and Angle are significant and affect the distance in which a red ball is thrown.

With the p-value=0.189138 greater than \(\alpha=0,05\),we fail to reject the null hypothesis (\(H_0: \alpha_{i}=0\)) and conclude the factor Pin by himself has not a significant effect in the distance in which a red ball is thrown.

With the p-value=3.391e-08 very less than \(\alpha=0,05\), we reject the Null Hypothesis (\(H_0: \sigma^2_{\beta}=0\)) and conclude the Factor Angle has a significant effect in the distance in which a red ball is thrown.

verifying plots

plot(Model2)

Graph Analysis

From the Residual vs fitted plot, we can se a outward-opening funnel shape, which indicates the variance of the observations is not constant. From the Normal Q-Q plot, we can say that all the points approximately lies in the straight line, so the data is normally distributed.

In the all plots we also can see the presence of outliers. These outliers may represent the variabilities in the experiment, for example, the operator. In this experiment the operator needed to sit on the floor in an uncomfortable position to perform the experiment. Another possible variability might be the time, since there were many groups to collect data during the class period, so, we had a concern about collecting the data fast.

Interaction Plot

Dat1<-data.frame(Pin,Angle,Dist)
Dat1$Pin<-as.factor(Dat1$Pin)
Dat1$Angle<-as.factor(Dat1$Angle)
interaction.plot(x.factor     = Dat1$Angle,
                 trace.factor = Dat1$Pin,
                 response     = Dat1$Dist,
                 fun = mean,
                 type="b",
                 col=c("black","red","green"),  
                 pch=c(19, 17, 15),             
                 fixed=TRUE,                   
                 leg.bty = "o")

Graph Analysis

However in this plot we cannot visualize the crossing of lines, In this interaction plot, we can se the lines are not parallel, indicating the interaction between factors. Furthermore,this interaction effect indicates that the relationship between pin position and distance depends on the value of the angle. This graph agreed with the results of the analysis of variance indicate that the interaction between Pin and Angle is significant.

Project Part 3

In part 3, we generated a 2^4 factorial design with the low and the high levels of the factors given for Pin Elevation, Bungee Position, Release Angle, and Ball Type.

The analysis for part 2 is illustrated below.

a) Propose a data collection layout with a randomized run order

library(agricolae)
trts3<-c(2,2,2,2)
design.ab(trt=trts3, r=1, design="crd",seed=158632)
## $parameters
## $parameters$design
## [1] "factorial"
## 
## $parameters$trt
##  [1] "1 1 1 1" "1 1 1 2" "1 1 2 1" "1 1 2 2" "1 2 1 1" "1 2 1 2" "1 2 2 1"
##  [8] "1 2 2 2" "2 1 1 1" "2 1 1 2" "2 1 2 1" "2 1 2 2" "2 2 1 1" "2 2 1 2"
## [15] "2 2 2 1" "2 2 2 2"
## 
## $parameters$r
##  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## 
## $parameters$serie
## [1] 2
## 
## $parameters$seed
## [1] 158632
## 
## $parameters$kinds
## [1] "Super-Duper"
## 
## $parameters[[7]]
## [1] TRUE
## 
## $parameters$applied
## [1] "crd"
## 
## 
## $book
##    plots r A B C D
## 1    101 1 1 1 1 1
## 2    102 1 1 1 1 2
## 3    103 1 2 1 2 1
## 4    104 1 2 2 2 2
## 5    105 1 1 2 2 1
## 6    106 1 1 2 2 2
## 7    107 1 1 2 1 1
## 8    108 1 1 1 2 1
## 9    109 1 2 1 1 2
## 10   110 1 2 2 2 1
## 11   111 1 2 1 1 1
## 12   112 1 2 2 1 1
## 13   113 1 2 2 1 2
## 14   114 1 1 2 1 2
## 15   115 1 2 1 2 2
## 16   116 1 1 1 2 2

The proposed design is showed above.

b) Collect data and record observations

The data was collected during the class.

c) State model equation and determine what factors/interactions appear to be significant (show any plots that were used in making this determination)

The Model equation for a 2^4 Factorial design is showed below.

\(Y_{ijklm}=\mu+\alpha_{i}+\beta_{j}+\gamma_{k}+\delta_{l}+\alpha\beta_{ij}+\alpha\gamma_{ik}+\alpha\delta_{il}+\beta\gamma_{jk}+\beta\delta_{jl}+\gamma\delta_{kl}+\alpha\beta\gamma_{ijk}+\alpha\beta\delta_{ijl}+\alpha\gamma\delta_{ikl}+\beta\gamma\delta_{jkl}+\alpha\beta\gamma\delta_{ijkl}+\epsilon_{ijklm}\)

Verifying the Halfnormal plot

library(GAD)
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)
obs3<-c(36,30,75,58,48,41,37,42,43,103,48,40,43,37,54,35)

model3<-lm(obs3~A*B*C*D)
coef(model3)
## (Intercept)           A           B           C           D         A:B 
##      48.125       9.875       2.750       8.875      -5.500       0.250 
##         A:C         B:C         A:D         B:D         C:D       A:B:C 
##       5.625       2.750      -3.000      -0.625      -4.500       2.250 
##       A:B:D       A:C:D       B:C:D     A:B:C:D 
##      -1.375      -3.500      -2.375      -1.625
halfnormal(model3)
## 
## Significant effects (alpha=0.05, Lenth method):
## [1] A

Analysis From the halfnormal plot we can see that only Factor A (Pin Elevation) appears to be significant.

d) After using insignificant factors/interactions to create an error term, perform ANOVA to determine a final model equation using an alpha = 0.05

A<-as.fixed(A)
model3<-aov(obs3~A)
gad(model3)
## Analysis of Variance Table
## 
## Response: obs3
##          Df Sum Sq Mean Sq F value  Pr(>F)  
## A         1 1560.2 1560.25  6.4104 0.02394 *
## Residual 14 3407.5  243.39                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Analysis The analysis of variance provided the p-value=0.02394 less than alpha=0.05. We conclude that only factor A (Pin Elevation) has a significant effect on the distance in which a ball is thrown.

The Final model equation is: \(Y_{im}=\mu+\alpha_{i}+\epsilon_{im}\)

All Code

#Allcode Part1
knitr::opts_chunk$set(echo = TRUE)
library(pwr)
library(agricolae)
library(dplyr)
library(MASS)
pwr.anova.test(k=3,n=NULL,f=((0.5*sqrt((3^2)-1))/(2*3)),sig.level = 0.05,power = 0.75)
trt<-c("yellow","red","mix")
experimentdesign<-design.crd(trt=trt,r= 53,seed=981273)
print(experimentdesign)
obs<-c(71,85,152,104,164,147,161,70,83,168,155,78,87,102,98,130,88,97,157,75,89,78,97,110,139,128,133,94,78,123,93,81,103,138,78,75,139,111,145,75,88,98,149,120,138,91,68,93,120,94,110,87,90,66,113,84,64,80,74,92,82,72,72,88,82,88,75,89,63,88,90,101,83,72,60,98,73,82,70,90,65,95,56,76,78,82,98,74,77,65,63,89,75,90,104,89,65,63,87,76,77,87,90,93,65,84,110,98,107,132,86,125,133,59,113,90,97,86,124,88,130,87,60,98,103,89,78,89,109,120,78,91,124,90,99,102,84,93,74,105,103,87,92,64,98,78,72,99,104,97,67,88,83,81,92,104,82,91,75)
ball<-c(rep(1,53),rep(2,53),rep(3,53))
dat<-data.frame(obs,ball)
dat$ball<-as.factor(dat$ball)
model<-aov(dat$obs~dat$ball, data = dat)
summary(model)
plot(model)
boxplot(dat$obs~dat$ball, data = dat, main="Boxplot of observations")
TukeyHSD(model1)
plot(TukeyHSD(model1))
boxcox(dat$obs~dat$ball, data = dat)
lambda = 0.5
dat$obs<-dat$obs^lambda
model1<-aov(dat$obs~dat$ball, data = dat)
summary(model1)
boxplot(dat$obs~dat$ball, data = dat, main="Boxplot of transformed observations")
TukeyHSD(model1)
plot(TukeyHSD(model1))
#Allcode Part2
library(agricolae)
trts2<-c(2,3)
design.ab(trt=trts2, r=3, design="crd", randomization=TRUE, seed=156812)
Angle<-rep(seq(1,3), 3)
Pin<-c(rep(1,9), rep(2,9))

Dist<-c(27,42,49,
        27,38,51,
        26,40,50,
        33,49,79,
        29,46,63,
        29,43,67)
Dat2<-data.frame(Pin,Angle,Dist)
library(GAD)
Dat2$Pin<-as.fixed(Dat2$Pin)
Dat2$Angle<-as.random(Dat2$Angle)
Model2<-aov(Dist~Angle+Pin+Angle*Pin, data = Dat2)
GAD::gad(Model2)
plot(Model2)
Dat1<-data.frame(Pin,Angle,Dist)
Dat1$Pin<-as.factor(Dat1$Pin)
Dat1$Angle<-as.factor(Dat1$Angle)
interaction.plot(x.factor     = Dat1$Angle,
                 trace.factor = Dat1$Pin,
                 response     = Dat1$Dist,
                 fun = mean,
                 type="b",
                 col=c("black","red","green"),  
                 pch=c(19, 17, 15),             
                 fixed=TRUE,                   
                 leg.bty = "o")
#Allcode Part3
library(agricolae)
trts3<-c(2,2,2,2)
design.ab(trt=trts3, r=1, design="crd",seed=158632)
library(GAD)
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)
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)
obs3<-c(36,30,75,58,48,41,37,42,43,103,48,40,43,37,54,35)

model3<-lm(obs3~A*B*C*D)
coef(model3)
halfnormal(model3)
A<-as.fixed(A)
model3<-aov(obs3~A)
gad(model3)