library(pwr)
## Warning: package 'pwr' was built under R version 4.0.5
pwr.anova.test(k=3,n=NULL,f=0.50*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
library(agricolae)
## Warning: package 'agricolae' was built under R version 4.0.5
trt1 <- c("ball 1","ball 2", "ball 3")
design<-design.crd(trt=trt1,r=53,seed=8238350)
design$book
## plots r trt1
## 1 101 1 ball 2
## 2 102 2 ball 2
## 3 103 1 ball 3
## 4 104 3 ball 2
## 5 105 2 ball 3
## 6 106 4 ball 2
## 7 107 3 ball 3
## 8 108 4 ball 3
## 9 109 5 ball 2
## 10 110 6 ball 2
## 11 111 7 ball 2
## 12 112 1 ball 1
## 13 113 8 ball 2
## 14 114 5 ball 3
## 15 115 6 ball 3
## 16 116 9 ball 2
## 17 117 7 ball 3
## 18 118 10 ball 2
## 19 119 2 ball 1
## 20 120 3 ball 1
## 21 121 11 ball 2
## 22 122 8 ball 3
## 23 123 4 ball 1
## 24 124 9 ball 3
## 25 125 12 ball 2
## 26 126 10 ball 3
## 27 127 11 ball 3
## 28 128 13 ball 2
## 29 129 5 ball 1
## 30 130 12 ball 3
## 31 131 6 ball 1
## 32 132 14 ball 2
## 33 133 7 ball 1
## 34 134 13 ball 3
## 35 135 15 ball 2
## 36 136 8 ball 1
## 37 137 9 ball 1
## 38 138 14 ball 3
## 39 139 10 ball 1
## 40 140 11 ball 1
## 41 141 15 ball 3
## 42 142 16 ball 2
## 43 143 17 ball 2
## 44 144 12 ball 1
## 45 145 16 ball 3
## 46 146 13 ball 1
## 47 147 14 ball 1
## 48 148 17 ball 3
## 49 149 18 ball 3
## 50 150 19 ball 3
## 51 151 18 ball 2
## 52 152 19 ball 2
## 53 153 20 ball 2
## 54 154 21 ball 2
## 55 155 20 ball 3
## 56 156 15 ball 1
## 57 157 16 ball 1
## 58 158 22 ball 2
## 59 159 23 ball 2
## 60 160 24 ball 2
## 61 161 17 ball 1
## 62 162 21 ball 3
## 63 163 25 ball 2
## 64 164 18 ball 1
## 65 165 22 ball 3
## 66 166 19 ball 1
## 67 167 23 ball 3
## 68 168 20 ball 1
## 69 169 24 ball 3
## 70 170 21 ball 1
## 71 171 22 ball 1
## 72 172 25 ball 3
## 73 173 26 ball 3
## 74 174 26 ball 2
## 75 175 23 ball 1
## 76 176 27 ball 3
## 77 177 24 ball 1
## 78 178 27 ball 2
## 79 179 28 ball 3
## 80 180 28 ball 2
## 81 181 29 ball 3
## 82 182 29 ball 2
## 83 183 25 ball 1
## 84 184 26 ball 1
## 85 185 30 ball 2
## 86 186 31 ball 2
## 87 187 27 ball 1
## 88 188 32 ball 2
## 89 189 30 ball 3
## 90 190 31 ball 3
## 91 191 33 ball 2
## 92 192 28 ball 1
## 93 193 32 ball 3
## 94 194 29 ball 1
## 95 195 33 ball 3
## 96 196 30 ball 1
## 97 197 31 ball 1
## 98 198 34 ball 3
## 99 199 32 ball 1
## 100 200 35 ball 3
## 101 201 33 ball 1
## 102 202 36 ball 3
## 103 203 34 ball 2
## 104 204 37 ball 3
## 105 205 34 ball 1
## 106 206 35 ball 1
## 107 207 35 ball 2
## 108 208 36 ball 1
## 109 209 38 ball 3
## 110 210 36 ball 2
## 111 211 37 ball 2
## 112 212 37 ball 1
## 113 213 38 ball 1
## 114 214 38 ball 2
## 115 215 39 ball 1
## 116 216 39 ball 2
## 117 217 39 ball 3
## 118 218 40 ball 3
## 119 219 41 ball 3
## 120 220 40 ball 2
## 121 221 41 ball 2
## 122 222 42 ball 2
## 123 223 43 ball 2
## 124 224 44 ball 2
## 125 225 42 ball 3
## 126 226 40 ball 1
## 127 227 45 ball 2
## 128 228 43 ball 3
## 129 229 41 ball 1
## 130 230 42 ball 1
## 131 231 46 ball 2
## 132 232 43 ball 1
## 133 233 47 ball 2
## 134 234 48 ball 2
## 135 235 49 ball 2
## 136 236 44 ball 1
## 137 237 44 ball 3
## 138 238 45 ball 3
## 139 239 45 ball 1
## 140 240 46 ball 1
## 141 241 47 ball 1
## 142 242 48 ball 1
## 143 243 49 ball 1
## 144 244 50 ball 2
## 145 245 46 ball 3
## 146 246 47 ball 3
## 147 247 51 ball 2
## 148 248 48 ball 3
## 149 249 49 ball 3
## 150 250 50 ball 1
## 151 251 52 ball 2
## 152 252 51 ball 1
## 153 253 50 ball 3
## 154 254 51 ball 3
## 155 255 53 ball 2
## 156 256 52 ball 3
## 157 257 53 ball 3
## 158 258 52 ball 1
## 159 259 53 ball 1
path <- "C:/Users/Yonatan/OneDrive/Graduate Classes/Fall 2021 Semester Classes/Design of Experiments/Project/Part 1"
setwd(path)
dat <- read.csv("Project1_Part1_corrected.csv",header=TRUE)
dat <- as.data.frame(dat)
colnames(dat) <- c("trt","response")
dat$trt <- as.factor(dat$trt)
dat
## trt response
## 1 1 97
## 2 2 87
## 3 3 77
## 4 1 83
## 5 3 67
## 6 2 67
## 7 1 72
## 8 1 106
## 9 3 77
## 10 2 71
## 11 3 69
## 12 2 68
## 13 2 63
## 14 1 114
## 15 1 119
## 16 2 66
## 17 3 75
## 18 2 73
## 19 1 121
## 20 2 65
## 21 3 68
## 22 3 68
## 23 3 65
## 24 3 62
## 25 3 65
## 26 2 69
## 27 2 71
## 28 3 68
## 29 1 100
## 30 3 100
## 31 3 82
## 32 2 83
## 33 1 108
## 34 3 75
## 35 1 106
## 36 1 97
## 37 1 115
## 38 3 117
## 39 3 122
## 40 1 116
## 41 3 74
## 42 2 73
## 43 3 85
## 44 1 106
## 45 2 82
## 46 2 80
## 47 2 75
## 48 2 72
## 49 1 120
## 50 1 114
## 51 2 84
## 52 3 82
## 53 1 114
## 54 1 85
## 55 2 82
## 56 2 80
## 57 2 78
## 58 1 140
## 59 1 115
## 60 2 83
## 61 1 105
## 62 3 87
## 63 2 85
## 64 2 72
## 65 3 87
## 66 2 84
## 67 1 119
## 68 3 108
## 69 1 121
## 70 3 106
## 71 2 86
## 72 3 110
## 73 2 82
## 74 2 84
## 75 2 81
## 76 2 86
## 77 3 90
## 78 2 83
## 79 1 137
## 80 1 132
## 81 3 97
## 82 2 85
## 83 3 95
## 84 2 85
## 85 1 123
## 86 1 130
## 87 1 129
## 88 1 135
## 89 3 115
## 90 1 127
## 91 2 81
## 92 1 135
## 93 2 86
## 94 3 104
## 95 1 136
## 96 3 121
## 97 1 135
## 98 1 137
## 99 2 96
## 100 2 81
## 101 1 134
## 102 1 131
## 103 1 138
## 104 1 136
## 105 1 136
## 106 2 85
## 107 1 134
## 108 3 103
## 109 2 80
## 110 1 134
## 111 2 81
## 112 3 104
## 113 2 82
## 114 3 96
## 115 3 97
## 116 3 94
## 117 3 91
## 118 3 110
## 119 3 89
## 120 3 89
## 121 1 120
## 122 1 118
## 123 1 117
## 124 2 77
## 125 3 104
## 126 2 82
## 127 3 102
## 128 3 108
## 129 2 82
## 130 3 99
## 131 1 98
## 132 2 101
## 133 1 135
## 134 3 116
## 135 2 82
## 136 1 133
## 137 2 89
## 138 1 124
## 139 2 83
## 140 1 136
## 141 2 106
## 142 2 84
## 143 3 104
## 144 3 108
## 145 3 144
## 146 3 107
## 147 1 147
## 148 3 138
## 149 1 126
## 150 1 130
## 151 1 137
## 152 2 85
## 153 3 97
## 154 3 114
## 155 2 87
## 156 2 85
## 157 2 83
## 158 3 109
## 159 3 119
model <- aov(response~trt,data=dat)
summary(model)
## Df Sum Sq Mean Sq F value Pr(>F)
## trt 2 43844 21922 95 <2e-16 ***
## Residuals 156 35997 231
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(model)
TukeyHSD(model,conf.level = 0.95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = response ~ trt, data = dat)
##
## $trt
## diff lwr upr p adj
## 2-1 -40.18868 -47.171314 -33.20604 0.0e+00
## 3-1 -25.52830 -32.510936 -18.54567 0.0e+00
## 3-2 14.66038 7.677743 21.64301 5.2e-06
plot(TukeyHSD(model,conf.level = 0.95))
library(agricolae)
trts<-c(2,3)
#Specify the K number of replications (r=3)
design <- design.ab(trt=trts, r=3, design="crd",seed=879879)
design$book
## plots r A B
## 1 101 1 2 1
## 2 102 1 1 1
## 3 103 1 2 3
## 4 104 2 2 1
## 5 105 1 2 2
## 6 106 1 1 2
## 7 107 2 2 2
## 8 108 2 1 2
## 9 109 3 1 2
## 10 110 1 1 3
## 11 111 3 2 2
## 12 112 3 2 1
## 13 113 2 1 3
## 14 114 2 1 1
## 15 115 2 2 3
## 16 116 3 1 3
## 17 117 3 1 1
## 18 118 3 2 3
library(GAD)
## Warning: package 'GAD' was built under R version 4.0.5
## Loading required package: matrixStats
## Warning: package 'matrixStats' was built under R version 4.0.5
## Loading required package: R.methodsS3
## Warning: package 'R.methodsS3' was built under R version 4.0.3
## R.methodsS3 v1.8.1 (2020-08-26 16:20:06 UTC) successfully loaded. See ?R.methodsS3 for help.
Distance <- c(24,15,73,13.5,37,36,39,38,34,71,43,20,67,16,71,66,15,63)
Pin <- c(3,1,3,3,3,1,3,1,1,1,3,3,1,1,3,1,1,3)
Degree <- c(110,110,170,110,140,140,140,140,140,170,140,110,170,110,170,170,110,170)
Pin <- as.fixed(Pin)
Degree <- as.random(Degree)
model<-aov(Distance~Pin+Degree+Pin*Degree)
GAD::gad(model)
## Analysis of Variance Table
##
## Response: Distance
## Df Sum Sq Mean Sq F value Pr(>F)
## Pin 1 36.1 36.1 9.5275 0.09088 .
## Degree 2 7981.4 3990.7 311.9750 4.514e-11 ***
## Pin:Degree 2 7.6 3.8 0.2964 0.74877
## Residual 12 153.5 12.8
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot (model)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.5
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:matrixStats':
##
## count
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.0.5
Distance <- c(24,15,73,13.5,37,36,39,38,34,71,43,20,67,16,71,66,15,63)
Pin <- c(3,1,3,3,3,1,3,1,1,1,3,3,1,1,3,1,1,3)
Degree <- c(110,110,170,110,140,140,140,140,140,170,140,110,170,110,170,170,110,170)
dat1 <- cbind(Distance,Pin,Degree)
dat1 <- as.data.frame(dat1)
Dist1<-dat1 %>% filter(Degree==110)%>% filter(Pin==1)
Dist2<-dat1 %>% filter(Degree==110)%>% filter(Pin==3)
Dist3<-dat1 %>% filter(Degree==140)%>% filter(Pin==1)
Dist4<-dat1 %>% filter(Degree==140)%>% filter(Pin==3)
Dist5<-dat1 %>% filter(Degree==170)%>% filter(Pin==1)
Dist6<-dat1 %>% filter(Degree==170)%>% filter(Pin==3)
Dist1 <- Dist1 %>% select(-Degree)%>% select(-Pin)
Dist1 <- as.numeric(Dist1$Distance)
Dist2 <- Dist2 %>% select(-Degree)%>% select(-Pin)
Dist2 <- as.numeric(Dist2$Distance)
Dist3 <- Dist3 %>% select(-Degree)%>% select(-Pin)
Dist3 <- as.numeric(Dist3$Distance)
Dist4 <- Dist4 %>% select(-Degree)%>% select(-Pin)
Dist4 <- as.numeric(Dist4$Distance)
Dist5 <- Dist5 %>% select(-Degree)%>% select(-Pin)
Dist5 <- as.numeric(Dist5$Distance)
Dist6 <- Dist6 %>% select(-Degree)%>% select(-Pin)
Dist6 <- as.numeric(Dist6$Distance)
avg1 <- ave(Dist1)
avg2 <- ave(Dist2)
avg3 <- ave(Dist3)
avg4 <- ave(Dist4)
avg5 <- ave(Dist5)
avg6 <- ave(Dist6)
Deg <- c(110,110,110,140,140,140,170,170,170)
Deg1 <- c(110,110,110)
Deg2<- c(140,140,140)
Deg3 <- c(170,170,170)
plot(Deg, c(Dist1,Dist3,Dist5),main="Scatterplot with average", xlab="Degree",ylab="Distance", pch=19, col="red")
lines(Deg, c(avg1,avg3,avg5), type = "b", col = "red", lwd = 3, pch = 15)
points(Deg,c(Dist2,Dist4,Dist6),pch = 19,col="blue")
lines(Deg, c(avg2,avg4,avg6), type = "b", col = "blue", lwd = 3, pch = 15)
legend(x=110,y=60,c("Pin Location=1","Pin Location=3"),pch=c(19,19),col = c("red","blue"))
library(agricolae)
trts<-c(2,2,2,2)
#Specify the K number of replications (r=1)
design <- design.ab(trt=trts, r=1, design="crd",seed=879879)
design$book
## plots r A B C D
## 1 101 1 2 1 2 1
## 2 102 1 2 1 1 1
## 3 103 1 1 1 1 1
## 4 104 1 2 1 2 2
## 5 105 1 1 1 2 2
## 6 106 1 2 2 1 1
## 7 107 1 1 2 1 1
## 8 108 1 1 2 1 2
## 9 109 1 1 2 2 1
## 10 110 1 1 1 2 1
## 11 111 1 2 2 1 2
## 12 112 1 2 2 2 2
## 13 113 1 2 1 1 2
## 14 114 1 1 1 1 2
## 15 115 1 1 2 2 2
## 16 116 1 2 2 2 1
obs <- c(60,36,29,62,41,37,35,29,48,42,45,71,40,31,53,61)
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)
library(DoE.base)
## Warning: package 'DoE.base' was built under R version 4.0.5
## Loading required package: grid
## Loading required package: conf.design
## Warning: package 'conf.design' was built under R version 4.0.3
## 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
dat1 <- cbind(A,B,C,D,obs)
dat1 <- data.frame(dat1)
mod <- lm(obs~A*B*C*D,data = dat1)
coef(mod)
## (Intercept) A B C D A:B
## 45.000 6.500 2.375 9.750 1.500 -0.375
## A:C B:C A:D B:D C:D A:B:C
## 2.250 1.125 1.500 0.625 0.500 -0.625
## A:B:D A:C:D B:C:D A:B:C:D
## 0.875 -0.500 1.125 -0.625
halfnormal(mod)
##
## Significant effects (alpha=0.05, Lenth method):
## [1] C A
### (3c)
dat1$A <- as.factor(dat1$A)
dat1$B <- as.factor(dat1$B)
dat1$C <- as.factor(dat1$C)
dat1$D <- as.factor(dat1$D)
model<-aov(obs~A+C+A*C,data=dat1)
summary(model)
## Df Sum Sq Mean Sq F value Pr(>F)
## A 1 676 676.0 33.246 8.94e-05 ***
## C 1 1521 1521.0 74.803 1.68e-06 ***
## A:C 1 81 81.0 3.984 0.0692 .
## Residuals 12 244 20.3
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(pwr)
pwr.anova.test(k=3,n=NULL,f=0.50*sqrt(3^2-1)/(2*3),sig.level=0.05,power=0.75)
library(agricolae)
trt1 <- c("ball 1","ball 2", "ball 3")
design<-design.crd(trt=trt1,r=53,seed=8238350)
design$book
path <- "C:/Users/Yonatan/OneDrive/Graduate Classes/Fall 2021 Semester Classes/Design of Experiments/Project/Part 1"
setwd(path)
dat <- read.csv("Project1_Part1_corrected.csv",header=TRUE)
dat <- as.data.frame(dat)
colnames(dat) <- c("trt","response")
dat$trt <- as.factor(dat$trt)
dat
model <- aov(response~trt,data=dat)
summary(model)
plot(model)
TukeyHSD(model,conf.level = 0.95)
plot(TukeyHSD(model,conf.level = 0.95))
library(agricolae)
trts<-c(2,3)
#Specify the K number of replications (r=3)
design <- design.ab(trt=trts, r=3, design="crd",seed=879879)
design$book
######
library(GAD)
Distance <- c(24,15,73,13.5,37,36,39,38,34,71,43,20,67,16,71,66,15,63)
Pin <- c(3,1,3,3,3,1,3,1,1,1,3,3,1,1,3,1,1,3)
Degree <- c(110,110,170,110,140,140,140,140,140,170,140,110,170,110,170,170,110,170)
Pin <- as.fixed(Pin)
Degree <- as.random(Degree)
model<-aov(Distance~Pin+Degree+Pin*Degree)
GAD::gad(model)
plot (model)
######
library(dplyr)
library(tidyr)
Distance <- c(24,15,73,13.5,37,36,39,38,34,71,43,20,67,16,71,66,15,63)
Pin <- c(3,1,3,3,3,1,3,1,1,1,3,3,1,1,3,1,1,3)
Degree <- c(110,110,170,110,140,140,140,140,140,170,140,110,170,110,170,170,110,170)
dat1 <- cbind(Distance,Pin,Degree)
dat1 <- as.data.frame(dat1)
Dist1<-dat1 %>% filter(Degree==110)%>% filter(Pin==1)
Dist2<-dat1 %>% filter(Degree==110)%>% filter(Pin==3)
Dist3<-dat1 %>% filter(Degree==140)%>% filter(Pin==1)
Dist4<-dat1 %>% filter(Degree==140)%>% filter(Pin==3)
Dist5<-dat1 %>% filter(Degree==170)%>% filter(Pin==1)
Dist6<-dat1 %>% filter(Degree==170)%>% filter(Pin==3)
Dist1 <- Dist1 %>% select(-Degree)%>% select(-Pin)
Dist1 <- as.numeric(Dist1$Distance)
Dist2 <- Dist2 %>% select(-Degree)%>% select(-Pin)
Dist2 <- as.numeric(Dist2$Distance)
Dist3 <- Dist3 %>% select(-Degree)%>% select(-Pin)
Dist3 <- as.numeric(Dist3$Distance)
Dist4 <- Dist4 %>% select(-Degree)%>% select(-Pin)
Dist4 <- as.numeric(Dist4$Distance)
Dist5 <- Dist5 %>% select(-Degree)%>% select(-Pin)
Dist5 <- as.numeric(Dist5$Distance)
Dist6 <- Dist6 %>% select(-Degree)%>% select(-Pin)
Dist6 <- as.numeric(Dist6$Distance)
avg1 <- ave(Dist1)
avg2 <- ave(Dist2)
avg3 <- ave(Dist3)
avg4 <- ave(Dist4)
avg5 <- ave(Dist5)
avg6 <- ave(Dist6)
Deg <- c(110,110,110,140,140,140,170,170,170)
Deg1 <- c(110,110,110)
Deg2<- c(140,140,140)
Deg3 <- c(170,170,170)
plot(Deg, c(Dist1,Dist3,Dist5),main="Scatterplot with average", xlab="Degree",ylab="Distance", pch=19, col="red")
lines(Deg, c(avg1,avg3,avg5), type = "b", col = "red", lwd = 3, pch = 15)
points(Deg,c(Dist2,Dist4,Dist6),pch = 19,col="blue")
lines(Deg, c(avg2,avg4,avg6), type = "b", col = "blue", lwd = 3, pch = 15)
legend(x=110,y=60,c("Pin Location=1","Pin Location=3"),pch=c(19,19),col = c("red","blue"))
library(agricolae)
trts<-c(2,2,2,2)
#Specify the K number of replications (r=1)
design <- design.ab(trt=trts, r=1, design="crd",seed=879879)
design$book
obs <- c(60,36,29,62,41,37,35,29,48,42,45,71,40,31,53,61)
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)
library(DoE.base)
dat1 <- cbind(A,B,C,D,obs)
dat1 <- data.frame(dat1)
mod <- lm(obs~A*B*C*D,data = dat1)
coef(mod)
halfnormal(mod)
dat1$A <- as.factor(dat1$A)
dat1$B <- as.factor(dat1$B)
dat1$C <- as.factor(dat1$C)
dat1$D <- as.factor(dat1$D)
model<-aov(obs~A+C+A*C,data=dat1)
summary(model)