A<-c(-1,1,-1,1,-1,1,-1,1)
B<-c(-1,-1,1,1,-1,-1,1,1)
C<-c(-1,-1,-1,-1,1,1,1,1)
Obs<-c(22,32,35,55,44,40,60,39,31,43,34,47,45,37,50,41,25,29,50,46,38,36,54,47)
A<-as.fixed(A)
B<-as.fixed(B)
C<-as.fixed(C)
dat<-data.frame(A,B,C,Obs)
dat
## A B C Obs
## 1 -1 -1 -1 22
## 2 1 -1 -1 32
## 3 -1 1 -1 35
## 4 1 1 -1 55
## 5 -1 -1 1 44
## 6 1 -1 1 40
## 7 -1 1 1 60
## 8 1 1 1 39
## 9 -1 -1 -1 31
## 10 1 -1 -1 43
## 11 -1 1 -1 34
## 12 1 1 -1 47
## 13 -1 -1 1 45
## 14 1 -1 1 37
## 15 -1 1 1 50
## 16 1 1 1 41
## 17 -1 -1 -1 25
## 18 1 -1 -1 29
## 19 -1 1 -1 50
## 20 1 1 -1 46
## 21 -1 -1 1 38
## 22 1 -1 1 36
## 23 -1 1 1 54
## 24 1 1 1 47
mod<-lm(Obs~A*B*C+A+B+C+A*B+A*C+B*C,data=dat)
gad(mod)
## Analysis of Variance Table
##
## Response: Obs
## Df Sum Sq Mean Sq F value Pr(>F)
## A 1 0.67 0.67 0.0221 0.8836803
## B 1 770.67 770.67 25.5470 0.0001173 ***
## C 1 280.17 280.17 9.2873 0.0076787 **
## A:B 1 16.67 16.67 0.5525 0.4680784
## A:C 1 468.17 468.17 15.5193 0.0011722 **
## B:C 1 48.17 48.17 1.5967 0.2244753
## A:B:C 1 28.17 28.17 0.9337 0.3482825
## Residual 16 482.67 30.17
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The ANOVA table shows that the P values for AB, BC, and ABC are greater than our alpha = 0.05. Therefore, they are not significant and can be omitted from our model. The p value for A is also greater, but we still need to keep it as A*C is significant. Now, we are going to repeat the model just with the significant factors.
mod<-lm(Obs~A+B+C+A*C,data=dat)
gad(mod)
## Analysis of Variance Table
##
## Response: Obs
## Df Sum Sq Mean Sq F value Pr(>F)
## A 1 0.67 0.67 0.022 0.8836408
## B 1 770.67 770.67 25.436 7.216e-05 ***
## C 1 280.17 280.17 9.247 0.0067238 **
## A:C 1 468.17 468.17 15.452 0.0008972 ***
## Residual 19 575.67 30.30
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The factors B, c, and A*C are significant as their value is less than our alpha=0.05.
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(12,18,13,16,17,15,20,15,10,25,13,24,19,21,17,23)
dat<-data.frame(A,B,C,D,Obs)
dat
## A B C D Obs
## 1 -1 -1 -1 -1 12
## 2 1 -1 -1 -1 18
## 3 -1 1 -1 -1 13
## 4 1 1 -1 -1 16
## 5 -1 -1 1 -1 17
## 6 1 -1 1 -1 15
## 7 -1 1 1 -1 20
## 8 1 1 1 -1 15
## 9 -1 -1 -1 1 10
## 10 1 -1 -1 1 25
## 11 -1 1 -1 1 13
## 12 1 1 -1 1 24
## 13 -1 -1 1 1 19
## 14 1 -1 1 1 21
## 15 -1 1 1 1 17
## 16 1 1 1 1 23
mod<-lm(Obs~A*B*C*D,data=dat)
halfnormal(mod)
##
## Significant effects (alpha=0.05, Lenth method):
## [1] A A:C A:D D
As we can see in the previous plot, the factors D, AD, AC, and A appear to be significant, as they outline the straight line formed by the other interactions.
#Question 1
library (DoE.base)
library (GAD)
A<-c(-1,1,-1,1,-1,1,-1,1)
B<-c(-1,-1,1,1,-1,-1,1,1)
C<-c(-1,-1,-1,-1,1,1,1,1)
Obs<-c(22,32,35,55,44,40,60,39,31,43,34,47,45,37,50,41,25,29,50,46,38,36,54,47)
A<-as.fixed(A)
B<-as.fixed(B)
C<-as.fixed(C)
dat<-data.frame(A,B,C,Obs)
dat
mod<-lm(Obs~A*B*C+A+B+C+A*B+A*C+B*C,data=dat)
gad(mod)
mod<-lm(Obs~A+B+C+A*C,data=dat)
gad(mod)
#Question 2
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)
Obs<-c(12,18,13,16,17,15,20,15,10,25,13,24,19,21,17,23)
dat<-data.frame(A,B,C,D,Obs)
dat
mod<-lm(Obs~A*B*C*D,data=dat)
halfnormal(mod)