library(DoE.base)
## Warning: package 'DoE.base' was built under R version 4.2.2
## 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(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)
coef(mod)
## (Intercept) A B C D
## 1.737500e+01 2.250000e+00 2.500000e-01 1.000000e+00 1.625000e+00
## A:B A:C B:C A:D B:D
## -3.750000e-01 -2.125000e+00 1.250000e-01 2.000000e+00 -8.543513e-17
## C:D A:B:C A:B:D A:C:D B:C:D
## 1.110223e-16 5.000000e-01 3.750000e-01 -1.250000e-01 -3.750000e-01
## A:B:C:D
## 5.000000e-01
halfnormal(mod)
##
## Significant effects (alpha=0.05, Lenth method):
## [1] A A:C A:D D
From the halfnormal plot we can see that the significant factors in the model are A,D,AD, and AC since they are not following the normal distribution line pattern. Hence, the significant factor we need to consider are: A,C,D, AC and AD.
The hypothesis to be tested will be the following:
\[ H_0: \alpha\gamma_{ik}=0 \] \[ H_a: \alpha\gamma_{ik}\not= 0 \] \[ H_0: \alpha\lambda_{il}=0 \]
\[ H_a: \alpha\lambda_{il}\not=0 \]
\[ H_0: \alpha_i=0 \]
\[ H_a: \alpha_i\not=0 \]
\[ H_0: \gamma_k=0 \]
\[ H_a: \gamma_k\not=0 \]
\[ H_0: \lambda_l=0 \]
\[ H_a: \lambda_l\not=0 \]
model<-aov(obs~A+C+D+A*C+A*D,data = dat)
summary(model)
## Df Sum Sq Mean Sq F value Pr(>F)
## A 1 81.00 81.00 49.846 3.46e-05 ***
## C 1 16.00 16.00 9.846 0.010549 *
## D 1 42.25 42.25 26.000 0.000465 ***
## A:C 1 72.25 72.25 44.462 5.58e-05 ***
## A:D 1 64.00 64.00 39.385 9.19e-05 ***
## Residuals 10 16.25 1.62
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
From the analysis we can see that the P-values from AD (9.19E-5) and AC (5.58E-5) are both less than $ $. Therefore, we can reject the null hypothesis and conclude that the interaction between these factors are present.
Plots AD and AC below confirms the interaction between the factors since the lines are not parallel.
interaction.plot(A,D,obs)
interaction.plot(A,C,obs)