Fractional factorial design: decompose 4-level factor into 2 2-level factors
Chen=read.csv("LMChen1.csv",header=TRUE)
attach(Chen)
## The following objects are masked from Listeria:
##
## Listeria.count, S.N.ratio
print(Chen)
## HerbalTea Conc1 Conc2 Time1 Time2 Listeria.count S.N.ratio
## 1 1 -1 -1 -1 -1 6.613 16.41
## 2 1 -1 -1 1 -1 6.618 16.41
## 3 1 -1 -1 -1 1 6.776 16.62
## 4 1 -1 -1 1 1 6.769 16.61
## 5 1 1 -1 -1 -1 6.518 16.28
## 6 1 1 -1 1 -1 6.542 16.31
## 7 1 1 -1 -1 1 6.406 16.13
## 8 1 1 -1 1 1 6.263 15.94
## 9 1 -1 1 -1 -1 6.457 16.20
## 10 1 -1 1 1 -1 6.183 16.01
## 11 1 -1 1 -1 1 6.543 16.20
## 12 1 -1 1 1 1 6.612 16.41
## 13 1 1 1 -1 -1 6.318 16.01
## 14 1 1 1 1 -1 6.559 16.34
## 15 1 1 1 -1 1 6.294 15.98
## 16 1 1 1 1 1 6.375 16.09
## 17 -1 -1 -1 -1 -1 6.613 16.41
## 18 -1 -1 -1 1 -1 6.618 16.41
## 19 -1 -1 -1 -1 1 6.776 16.62
## 20 -1 -1 -1 1 1 6.769 16.61
## 21 -1 1 -1 -1 -1 6.474 16.22
## 22 -1 1 -1 1 -1 6.402 16.13
## 23 -1 1 -1 -1 1 6.573 16.36
## 24 -1 1 -1 1 1 6.586 16.37
## 25 -1 -1 1 -1 -1 6.338 16.04
## 26 -1 -1 1 1 -1 6.639 16.44
## 27 -1 -1 1 -1 1 6.489 16.24
## 28 -1 -1 1 1 1 6.663 16.47
## 29 -1 1 1 -1 -1 6.498 16.26
## 30 -1 1 1 1 -1 6.474 16.22
## 31 -1 1 1 -1 1 6.575 16.36
## 32 -1 1 1 1 1 6.573 16.36
Chen$HerbalTea=as.character(Chen$HerbalTea)
Chen$Conc1=as.character(Chen$Conc1)
Chen$Conc2=as.character(Chen$Conc2)
Chen$Time1=as.character(Chen$Time1)
Chen$Time2=as.character(Chen$Time2)
library(FrF2)
## Warning: package 'FrF2' was built under R version 3.1.2
## Loading required package: DoE.base
## Loading required package: grid
## Loading required package: 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
matrix1=FrF2(16,nfactors=5,estimable=formula("~HerbalTea+Conc1+Conc2+Time1+Time2:(HerbalTea+Conc1+Conc2+Time1+Time2)"),factor.names=c("HerbalTea","Conc1","Conc2","Time1","Time2"),res5=TRUE,clear=FALSE);
matrix1
## HerbalTea Conc1 Conc2 Time1 Time2
## 1 1 1 -1 1 -1
## 2 1 1 -1 -1 1
## 3 -1 1 1 1 -1
## 4 1 -1 1 1 -1
## 5 -1 -1 -1 1 -1
## 6 -1 -1 -1 -1 1
## 7 -1 1 1 -1 1
## 8 -1 -1 1 1 1
## 9 1 -1 -1 1 1
## 10 -1 1 -1 1 1
## 11 1 1 1 -1 -1
## 12 1 -1 -1 -1 -1
## 13 1 -1 1 -1 1
## 14 1 1 1 1 1
## 15 -1 1 -1 -1 -1
## 16 -1 -1 1 -1 -1
## class=design, type= FrF2.estimable
aliasprint(matrix1)
## $legend
## [1] A=HerbalTea B=Conc1 C=Conc2 D=Time1 E=Time2
##
## [[2]]
## [1] no aliasing among main effects and 2fis
sample1=merge(matrix1,Chen,by=c("HerbalTea","Conc1","Conc2","Time1","Time2"),all=FALSE)
aovsample1=lm(Listeria.count~HerbalTea*Conc1+HerbalTea*Conc2+HerbalTea*Time1+HerbalTea*Time2,data=sample1)
anova(aovsample1)
## Analysis of Variance Table
##
## Response: Listeria.count
## Df Sum Sq Mean Sq F value Pr(>F)
## HerbalTea 1 0.0358 0.0358 1.87 0.220
## Conc1 1 0.0354 0.0354 1.85 0.222
## Conc2 1 0.1080 0.1080 5.65 0.055 .
## Time1 1 0.0017 0.0017 0.09 0.774
## Time2 1 0.0801 0.0801 4.19 0.087 .
## HerbalTea:Conc1 1 0.0020 0.0020 0.11 0.755
## HerbalTea:Conc2 1 0.0161 0.0161 0.85 0.393
## HerbalTea:Time1 1 0.0023 0.0023 0.12 0.742
## HerbalTea:Time2 1 0.0042 0.0042 0.22 0.655
## Residuals 6 0.1146 0.0191
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(aovsample1)
##
## Call:
## lm.default(formula = Listeria.count ~ HerbalTea * Conc1 + HerbalTea *
## Conc2 + HerbalTea * Time1 + HerbalTea * Time2, data = sample1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.1743 -0.0211 0.0295 0.0648 0.0750
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.5158 0.0346 188.56 1.5e-12 ***
## HerbalTea1 -0.0473 0.0346 -1.37 0.220
## Conc11 -0.0470 0.0346 -1.36 0.222
## Conc21 -0.0822 0.0346 -2.38 0.055 .
## Time11 0.0104 0.0346 0.30 0.774
## Time21 0.0707 0.0346 2.05 0.087 .
## HerbalTea1:Conc11 -0.0113 0.0346 -0.33 0.755
## HerbalTea1:Conc21 -0.0318 0.0346 -0.92 0.393
## HerbalTea1:Time11 -0.0119 0.0346 -0.34 0.742
## HerbalTea1:Time21 -0.0162 0.0346 -0.47 0.655
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.138 on 6 degrees of freedom
## Multiple R-squared: 0.714, Adjusted R-squared: 0.284
## F-statistic: 1.66 on 9 and 6 DF, p-value: 0.276
####Change resolution to 4
library(FrF2)
matrix2=FrF2(16,nfactors=5,estimable=formula("~HerbalTea+Conc1+Conc2+Time1+Time2:(HerbalTea+Conc1+Conc2+Time1+Time2)"),factor.names=c("HerbalTea","Conc1","Conc2","Time1","Time2"),res4=TRUE,clear=FALSE);
matrix2
## HerbalTea Conc1 Conc2 Time1 Time2
## 1 1 1 -1 -1 1
## 2 1 -1 -1 -1 -1
## 3 -1 1 -1 1 1
## 4 1 1 1 1 1
## 5 -1 -1 -1 1 -1
## 6 -1 -1 1 -1 -1
## 7 1 1 -1 1 -1
## 8 1 -1 1 1 -1
## 9 -1 1 1 -1 1
## 10 -1 -1 -1 -1 1
## 11 -1 -1 1 1 1
## 12 1 -1 -1 1 1
## 13 1 1 1 -1 -1
## 14 -1 1 1 1 -1
## 15 1 -1 1 -1 1
## 16 -1 1 -1 -1 -1
## class=design, type= FrF2.estimable
aliasprint(matrix2)
## $legend
## [1] A=HerbalTea B=Conc1 C=Conc2 D=Time1 E=Time2
##
## [[2]]
## [1] no aliasing among main effects and 2fis
sample2=merge(matrix2,Chen,by=c("HerbalTea","Conc1","Conc2","Time1","Time2"),all=FALSE)
aovsample2=lm(Listeria.count~HerbalTea*Conc1+HerbalTea*Conc2+HerbalTea*Time1+HerbalTea*Time2,data=sample2)
anova(aovsample2)
## Analysis of Variance Table
##
## Response: Listeria.count
## Df Sum Sq Mean Sq F value Pr(>F)
## HerbalTea 1 0.0358 0.0358 1.87 0.220
## Conc1 1 0.0354 0.0354 1.85 0.222
## Conc2 1 0.1080 0.1080 5.65 0.055 .
## Time1 1 0.0017 0.0017 0.09 0.774
## Time2 1 0.0801 0.0801 4.19 0.087 .
## HerbalTea:Conc1 1 0.0020 0.0020 0.11 0.755
## HerbalTea:Conc2 1 0.0161 0.0161 0.85 0.393
## HerbalTea:Time1 1 0.0023 0.0023 0.12 0.742
## HerbalTea:Time2 1 0.0042 0.0042 0.22 0.655
## Residuals 6 0.1146 0.0191
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(aovsample2)
##
## Call:
## lm.default(formula = Listeria.count ~ HerbalTea * Conc1 + HerbalTea *
## Conc2 + HerbalTea * Time1 + HerbalTea * Time2, data = sample2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.1743 -0.0211 0.0295 0.0648 0.0750
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.5158 0.0346 188.56 1.5e-12 ***
## HerbalTea1 -0.0473 0.0346 -1.37 0.220
## Conc11 -0.0470 0.0346 -1.36 0.222
## Conc21 -0.0822 0.0346 -2.38 0.055 .
## Time11 0.0104 0.0346 0.30 0.774
## Time21 0.0707 0.0346 2.05 0.087 .
## HerbalTea1:Conc11 -0.0113 0.0346 -0.33 0.755
## HerbalTea1:Conc21 -0.0318 0.0346 -0.92 0.393
## HerbalTea1:Time11 -0.0119 0.0346 -0.34 0.742
## HerbalTea1:Time21 -0.0162 0.0346 -0.47 0.655
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.138 on 6 degrees of freedom
## Multiple R-squared: 0.714, Adjusted R-squared: 0.284
## F-statistic: 1.66 on 9 and 6 DF, p-value: 0.276