Input data:
library(DoE.base)
A <- rep(c(-1,1),8)
B <- rep(c(-1,-1,1,1),4)
C <- rep(c(-1,-1,-1,-1,1,1,1,1),2)
D <- c(rep(-1,8),rep(1,8))
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
Display the coefficient:
mod1 <- lm(Obs~A*B*C*D,data = dat)
coef(mod1)
## (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 -1.027824e-16
## C:D A:B:C A:B:D A:C:D B:C:D
## -1.595946e-16 5.000000e-01 3.750000e-01 -1.250000e-01 -3.750000e-01
## A:B:C:D
## 5.000000e-01
Display the halfnormal plot:
halfnormal(mod1)
As shown in the halfnormal plot, effect of A, AC, AD, D are significant.
Test with only significant effect: A, C, D, AC, AD:
mod2 <- lm(Obs~A+C+D+A*C+A*D,data = dat)
summary(mod2)
##
## Call:
## lm.default(formula = Obs ~ A + C + D + A * C + A * D, data = dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.6250 -0.9375 0.1250 0.8750 1.3750
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 17.3750 0.3187 54.520 1.04e-13 ***
## A 2.2500 0.3187 7.060 3.46e-05 ***
## C 1.0000 0.3187 3.138 0.010549 *
## D 1.6250 0.3187 5.099 0.000465 ***
## A:C -2.1250 0.3187 -6.668 5.58e-05 ***
## A:D 2.0000 0.3187 6.276 9.19e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.275 on 10 degrees of freedom
## Multiple R-squared: 0.9443, Adjusted R-squared: 0.9165
## F-statistic: 33.91 on 5 and 10 DF, p-value: 5.856e-06
Checking assumption:
plot(mod2)
The normal probability plot has some outlier (9, 5, 11) but overall the residual quite follow the normal distribution.
The variance seems to be equal as shown in the residual plots.
=> The assumptions are meet
The effect of A, C, AC, AD are significant as shown in the ANOVA table.
Create interaction plot of AC and AD
interaction.plot(A,C,Obs, col = 'blue', main = 'Interaction plot between A and C', ylab = 'Yeild (lbs)')
interaction.plot(A,D,Obs, col = 'green', main = 'Interaction plot between A and D', ylab = 'Yeild (lbs)')
#input data
library(DoE.base)
A <- rep(c(-1,1),8)
B <- rep(c(-1,-1,1,1),4)
C <- rep(c(-1,-1,-1,-1,1,1,1,1),2)
D <- c(rep(-1,8),rep(1,8))
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
#Coefficient
mod1 <- lm(Obs~A*B*C*D,data = dat)
coef(mod1)
#Halfnormal Plot
halfnormal(mod1)
#test only significant effect
mod2 <- lm(Obs~A+C+D+A*C+A*D,data = dat)
summary(mod2)
#check assumption
plot(mod2)
#conduct interaction plot
interaction.plot(A,C,Obs, col = 'blue', main = 'Interaction plot between A and C', ylab = 'Yeild (lbs)')
interaction.plot(A,D,Obs, col = 'green', main = 'Interaction plot between A and D', ylab = 'Yeild (lbs)')