For this example we will be using data presented by in “Evaluation of Surfactant Detergency using Statistical Analysis, Texile Research Journal”
Description: Color Change results of fabric of 3 varieties (cotton, silk,and wool) exposed to 4 soils (tea, coffee, wine, and charcoal), washed at 2 temperatures (40C and 60C) 2 surfactants (anionic and non-ionic) in a 4-Way ANOVA
The data provides the amount of color change based on 4 distinct factors.
Because we are interested in having 2 2-level factors, and 2 3-level factors we will be removing one of the soil level. The data that will be used canwas collected the variables were defined as follows:
Soil Type of contaminant (tea, coffee, wine)
Fabric Type of fabric (cotton, silk, wool)
Temp Temperature of wash (40C and 60C)
Surfactants Type of surfactant in detergent (anionic and non-ionic)
Next we look at the stucture of the data.
Data <- read.table("C:/Users/T420ortizf2/Documents/CollegeWork/Fall 2016/DesignOfExperiments/Project3/Data.txt", quote="\"")
names(Data) <- c("Soil", "Fabric", "Temp", "Surfactant", "Result")
str(Data)
## 'data.frame': 36 obs. of 5 variables:
## $ Soil : int 1 1 1 1 1 1 1 1 1 1 ...
## $ Fabric : int 1 1 1 1 2 2 2 2 3 3 ...
## $ Temp : int 1 1 2 2 1 1 2 2 1 1 ...
## $ Surfactant: int 1 2 1 2 1 2 1 2 1 2 ...
## $ Result : num 9.56 6.99 10.81 7.6 6.68 ...
We see that R has incorrectly assigned some data as integers rather than factors, so we will tell it which ones are factors
Data[,1] <- as.factor(Data[,1])
Data[,2] <- as.factor(Data[,2])
Data[,3] <- as.factor(Data[,3])
Data[,4] <- as.factor(Data[,4])
str(Data)
## 'data.frame': 36 obs. of 5 variables:
## $ Soil : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
## $ Fabric : Factor w/ 3 levels "1","2","3": 1 1 1 1 2 2 2 2 3 3 ...
## $ Temp : Factor w/ 2 levels "1","2": 1 1 2 2 1 1 2 2 1 1 ...
## $ Surfactant: Factor w/ 2 levels "1","2": 1 2 1 2 1 2 1 2 1 2 ...
## $ Result : num 9.56 6.99 10.81 7.6 6.68 ...
The Factors present in the data set and their levels.
levels(Data$Soil)
## [1] "1" "2" "3"
levels(Data$Fabric)
## [1] "1" "2" "3"
levels(Data$Temp)
## [1] "1" "2"
levels(Data$Surfactant)
## [1] "1" "2"
The Continuous variables present are the following
summary(Data$Result)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.70 8.66 10.05 12.05 13.62 26.48
The response variable that will be used is Result. The color change from the experiment run.
Randomized design is used to control for effects from extraneous variables, or variables that have an effect but are not being studied. The assumption is that on average these variables will affect the response variable equally so any significant differences should come from the independent variable(s) being tested. The designs will be automatically randomized.
Replication is an important part of experimental design, especially for validating results. It is not only more convincing, but more significant if the same parameters on an experiment are run several times, and the dependent results are similar. In this case we do not have any replications.
Blocking is used to eliminate the influence of extraneous variables.
As can be seen the experiment has been run as a full experimental design, with 2 2-level factors and 2 3-level factors. This results in 36 individual experiment.
Data
## Soil Fabric Temp Surfactant Result
## 1 1 1 1 1 9.56
## 2 1 1 1 2 6.99
## 3 1 1 2 1 10.81
## 4 1 1 2 2 7.60
## 5 1 2 1 1 6.68
## 6 1 2 1 2 9.30
## 7 1 2 2 1 8.36
## 8 1 2 2 2 8.76
## 9 1 3 1 1 6.16
## 10 1 3 1 2 5.46
## 11 1 3 2 1 6.24
## 12 1 3 2 2 4.70
## 13 2 1 1 1 11.44
## 14 2 1 1 2 12.05
## 15 2 1 2 1 12.34
## 16 2 1 2 2 12.92
## 17 2 2 1 1 10.46
## 18 2 2 1 2 11.96
## 19 2 2 2 1 10.15
## 20 2 2 2 2 9.95
## 21 2 3 1 1 9.22
## 22 2 3 1 2 9.15
## 23 2 3 2 1 9.77
## 24 2 3 2 2 8.90
## 25 3 1 1 1 25.47
## 26 3 1 1 2 24.08
## 27 3 1 2 1 26.48
## 28 3 1 2 2 25.49
## 29 3 2 1 1 9.87
## 30 3 2 1 2 14.58
## 31 3 2 2 1 7.91
## 32 3 2 2 2 13.30
## 33 3 3 1 1 17.96
## 34 3 3 1 2 17.08
## 35 3 3 2 1 16.82
## 36 3 3 2 2 15.88
Previously a fractional factorial design was formed.
library(FrF2)
Partial <- FrF2(8,6)
names(Partial)[1] <- "SoilA"
names(Partial)[2] <- "SoilB"
names(Partial)[3] <- "FabricA"
names(Partial)[4] <- "FabricB"
names(Partial)[5] <- "Temp"
names(Partial)[6] <- "Surfactant"
summary(Partial)
## Call:
## FrF2(8, 6)
##
## Experimental design of type FrF2
## 8 runs
##
## Factor settings (scale ends):
## A B C D E F
## 1 -1 -1 -1 -1 -1 -1
## 2 1 1 1 1 1 1
##
## Design generating information:
## $legend
## [1] A=A B=B C=C D=D E=E F=F
##
## $generators
## [1] D=AB E=AC F=BC
##
##
## Alias structure:
## $main
## [1] A=BD=CE B=AD=CF C=AE=BF D=AB=EF E=AC=DF F=BC=DE
##
## $fi2
## [1] AF=BE=CD
##
##
## The design itself:
## SoilA SoilB FabricA FabricB Temp Surfactant
## 1 -1 1 1 -1 -1 1
## 2 -1 1 -1 -1 1 -1
## 3 1 -1 -1 -1 -1 1
## 4 1 1 -1 1 -1 -1
## 5 1 -1 1 -1 1 -1
## 6 -1 -1 1 1 -1 -1
## 7 1 1 1 1 1 1
## 8 -1 -1 -1 1 1 1
## class=design, type= FrF2
Using the taguchiChoose function, R will create a Taguchi design for the factors shown.
library(qualityTools)
taguchiChoose(factors1 = 2, factors2 = 2, level1 = 3, level2 = 2, ia = 0)
## 2 factors on 3 levels and 2 factors on 2 levels with 0 desired interactions to be estimated
##
## Possible Designs:
##
## L36_2_3_a L36_2_3_b
##
## Use taguchiDesign("L36_2_3_a") or different to create a taguchi design object
taguchiDesign("L36_2_3_a")
## StandOrder RunOrder Replicate A B C D E F G H J K L M N O P Q R S T U V
## 1 11 1 1 1 2 1 2 2 1 2 2 1 1 2 2 2 1 3 2 1 3 1 3 2
## 2 13 2 1 1 2 2 1 2 2 1 2 1 2 1 1 2 3 1 3 2 1 3 3 2
## 3 19 3 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 3 3 3 1 2 2 1
## 4 2 4 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2
## 5 4 5 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 2 2 2 2 3 3
## 6 20 6 1 2 1 2 2 1 1 2 2 1 2 1 2 3 2 1 1 1 2 3 3 2
## 7 33 7 1 2 2 1 2 1 2 1 1 1 2 2 3 2 2 2 1 2 1 1 3 1
## 8 31 8 1 2 2 1 2 1 2 1 1 1 2 2 1 3 3 3 2 3 2 2 1 2
## 9 6 9 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 1 1 1 1 2 2
## 10 21 10 1 2 1 2 2 1 1 2 2 1 2 1 3 1 3 2 2 2 3 1 1 3
## 11 28 11 1 2 2 2 1 1 1 1 2 2 1 2 1 3 2 2 2 1 1 3 2 3
## 12 17 12 1 1 2 2 2 1 2 2 1 2 1 1 2 3 1 3 2 2 1 3 1 1
## 13 25 13 1 2 1 1 2 2 2 1 2 2 1 1 1 3 2 1 2 3 3 1 3 1
## 14 27 14 1 2 1 1 2 2 2 1 2 2 1 1 3 2 1 3 1 2 2 3 2 3
## 15 23 15 1 2 1 2 1 2 2 2 1 1 1 2 2 3 3 1 1 2 3 2 2 1
## 16 34 16 1 2 2 1 1 2 1 2 1 2 2 1 1 3 1 2 3 2 3 1 2 2
## 17 26 17 1 2 1 1 2 2 2 1 2 2 1 1 2 1 3 2 3 1 1 2 1 2
## 18 1 18 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## 19 22 19 1 2 1 2 1 2 2 2 1 1 1 2 1 2 2 3 3 1 2 1 1 3
## 20 18 20 1 1 2 2 2 1 2 2 1 2 1 1 3 1 2 1 3 3 2 1 2 2
## 21 36 21 1 2 2 1 1 2 1 2 1 2 2 1 3 2 3 1 2 1 2 3 1 1
## 22 29 22 1 2 2 2 1 1 1 1 2 2 1 2 2 1 3 3 3 2 2 1 3 1
## 23 9 23 1 1 1 2 2 2 1 1 1 2 2 2 3 3 1 2 3 1 2 2 3 1
## 24 7 24 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 3 1 2 3 3 1 2
## 25 3 25 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3
## 26 32 26 1 2 2 1 2 1 2 1 1 1 2 2 2 1 1 1 3 1 3 3 2 3
## 27 8 27 1 1 1 2 2 2 1 1 1 2 2 2 2 2 3 1 2 3 1 1 2 3
## 28 5 28 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 1 1
## 29 12 29 1 1 2 1 2 2 1 2 2 1 1 2 3 3 2 1 3 2 1 2 1 3
## 30 30 30 1 2 2 2 1 1 1 1 2 2 1 2 3 2 1 1 1 3 3 2 1 2
## 31 15 31 1 1 2 2 1 2 2 1 2 1 2 1 3 1 2 3 2 1 3 2 2 1
## 32 10 32 1 1 2 1 2 2 1 2 2 1 1 2 1 1 3 2 1 3 2 3 2 1
## 33 14 33 1 1 2 2 1 2 2 1 2 1 2 1 2 3 1 2 1 3 2 1 1 3
## 34 24 34 1 2 1 2 1 2 2 2 1 1 1 2 3 1 1 2 2 3 1 3 3 2
## 35 16 35 1 1 2 2 2 1 2 2 1 2 1 1 1 2 3 2 1 1 3 2 3 3
## 36 35 36 1 2 2 1 1 2 1 2 1 2 2 1 2 1 2 3 1 3 1 2 3 3
## W X y
## 1 1 3 NA
## 2 1 2 NA
## 3 2 3 NA
## 4 2 2 NA
## 5 3 3 NA
## 6 3 1 NA
## 7 3 3 NA
## 8 1 1 NA
## 9 2 2 NA
## 10 1 2 NA
## 11 1 3 NA
## 12 3 2 NA
## 13 2 2 NA
## 14 1 1 NA
## 15 1 3 NA
## 16 3 1 NA
## 17 3 3 NA
## 18 1 1 NA
## 19 3 2 NA
## 20 1 3 NA
## 21 2 3 NA
## 22 2 1 NA
## 23 1 2 NA
## 24 2 3 NA
## 25 3 3 NA
## 26 2 2 NA
## 27 3 1 NA
## 28 1 1 NA
## 29 2 1 NA
## 30 3 2 NA
## 31 3 1 NA
## 32 3 2 NA
## 33 2 3 NA
## 34 2 1 NA
## 35 2 1 NA
## 36 1 2 NA
As we can see, this is just the full factorial means that there is not a Taguchi for our specific experiment. In which case we will see if there is one if the 3-level factors are converted into 2-level factors.
taguchiChoose(factors1 = 6, level1 = 2, ia = 0)
## 6 factors on 2 levels and 0 factors on 0 levels with 0 desired interactions to be estimated
##
## Possible Designs:
##
## L8_2 L12_2 L16_2 L32_2
##
## Use taguchiDesign("L8_2") or different to create a taguchi design object
As can be seen, there are a couple of designs that would meet our needs. The one with the lowest number of experiments is chosen.
taguchiDesign("L8_2")
## StandOrder RunOrder Replicate A B C D E F G y
## 1 3 1 1 1 2 2 1 1 2 2 NA
## 2 5 2 1 2 1 2 1 2 1 2 NA
## 3 7 3 1 2 2 1 1 2 2 1 NA
## 4 1 4 1 1 1 1 1 1 1 1 NA
## 5 6 5 1 2 1 2 2 1 2 1 NA
## 6 4 6 1 1 2 2 2 2 1 1 NA
## 7 8 7 1 2 2 1 2 1 1 2 NA
## 8 2 8 1 1 1 1 2 2 2 2 NA
Now we will form what the design should be.
TDesign <- as.data.frame(taguchiDesign("L8_2"))
TDesign <- TDesign[,-c(1,2,3,10,11)]
# change column names to match factors in experiment
colnames(TDesign) <- c("SoilA", "SoilB", "FabricA", "FabricB", "Temp", "Surfactant")
TDesign
## SoilA SoilB FabricA FabricB Temp Surfactant
## 1 1 2 2 2 2 1
## 2 2 2 1 2 1 1
## 3 2 1 2 1 2 1
## 4 2 1 2 2 1 2
## 5 1 1 1 2 2 2
## 6 1 1 1 1 1 1
## 7 1 2 2 1 1 2
## 8 2 2 1 1 2 2
Now we want to select which experimental runs from the full design will be selected
TDesign2 <- TDesign-1
TDesign2
## SoilA SoilB FabricA FabricB Temp Surfactant
## 1 0 1 1 1 1 0
## 2 1 1 0 1 0 0
## 3 1 0 1 0 1 0
## 4 1 0 1 1 0 1
## 5 0 0 0 1 1 1
## 6 0 0 0 0 0 0
## 7 0 1 1 0 0 1
## 8 1 1 0 0 1 1
TDesign2 <- TDesign-1
TDesign2
## SoilA SoilB FabricA FabricB Temp Surfactant
## 1 0 1 1 1 1 0
## 2 1 1 0 1 0 0
## 3 1 0 1 0 1 0
## 4 1 0 1 1 0 1
## 5 0 0 0 1 1 1
## 6 0 0 0 0 0 0
## 7 0 1 1 0 0 1
## 8 1 1 0 0 1 1
Now the 2 2 level factors are transformed back into a 3 level factor.
T_Soil <- TDesign2[,1] + TDesign2[,2]
T_Soil <- T_Soil + 1
T_Soil
## [1] 2 3 2 2 1 1 2 3
T_Fabric <- TDesign2[,3] + TDesign2[,4]
T_Fabric <- T_Fabric + 1
T_Fabric
## [1] 3 2 2 3 2 1 2 1
We can see which of the experiments correspond to the original Full Factorial experiment
Check_Soil <- T_Soil
Check_Fabric <- T_Fabric
Check_Temp <-TDesign2$Temp + 1
Check_Suractant <- TDesign2$Surfactant + 1
Check_Results <- rep(NA,8)
for(i in 1:8){
for(j in 1:36){
if((Check_Soil[i] == Data[j,1]) && (Check_Fabric[i] == Data[j,2])
&& (Check_Temp[i] == Data[j,3]) && (Check_Suractant[i] == Data[j,4])){
Check_Results[i] <- Data[j,5]
}
}
}
Check_Results
## [1] 9.77 9.87 10.15 9.15 8.76 9.56 11.96 25.49
The nested for loop looks through the full factorial experiment for the correct experiments, and records the results of the correct experiment into the Check_Results vector.
Now we have the results for our experiment.
Comp_TDesign <- data.frame(Check_Soil, Check_Fabric, Check_Temp, Check_Suractant, Check_Results)
colnames(Comp_TDesign) <- c("Soil", "Fabric", "Temp", "Surfactant", "Results")
Comp_TDesign
## Soil Fabric Temp Surfactant Results
## 1 2 3 2 1 9.77
## 2 3 2 1 1 9.87
## 3 2 2 2 1 10.15
## 4 2 3 1 2 9.15
## 5 1 2 2 2 8.76
## 6 1 1 1 1 9.56
## 7 2 2 1 2 11.96
## 8 3 1 2 2 25.49
Comp_TDesign_2 <- data.frame(TDesign2[,1],TDesign2[,2],TDesign2[,3],TDesign2[,4],TDesign2[,5],TDesign2[,6], Check_Results)
colnames(Comp_TDesign_2) <- c("SoilA", "SoilB", "FabricA", "FabricB", "Temp", "Surfactant", "Results")
Comp_TDesign_2
## SoilA SoilB FabricA FabricB Temp Surfactant Results
## 1 0 1 1 1 1 0 9.77
## 2 1 1 0 1 0 0 9.87
## 3 1 0 1 0 1 0 10.15
## 4 1 0 1 1 0 1 9.15
## 5 0 0 0 1 1 1 8.76
## 6 0 0 0 0 0 0 9.56
## 7 0 1 1 0 0 1 11.96
## 8 1 1 0 0 1 1 25.49
We can now conduct an ANOVA test, and build a linear regression from just the main effects.
First we will revisit the previously formed fractional factorial design.
Check_Soil <- c(2, 3, 2, 2, 1, 2, 3, 1)
Check_Fabric <- c(2, 3, 2, 1, 3, 1, 2, 2)
Check_Temp <-c(1, 2, 2, 2, 1, 1, 1, 2)
Check_Suractant <- c(2, 2, 1, 1, 1, 2, 1, 2)
Check_Results <- rep(NA,8)
for(i in 1:8){
for(j in 1:36){
if((Check_Soil[i] == Data[j,1]) && (Check_Fabric[i] == Data[j,2])
&& (Check_Temp[i] == Data[j,3]) && (Check_Suractant[i] == Data[j,4])){
Check_Results[i] <- Data[j,5]
}
}
}
Check_Results
## [1] 11.96 15.88 10.15 12.34 6.16 12.05 9.87 8.76
Comp_Partial <- add.response(Partial, Check_Results)
summary(Comp_Partial)
## Call:
## FrF2(8, 6)
##
## Experimental design of type FrF2
## 8 runs
##
## Factor settings (scale ends):
## A B C D E F
## 1 -1 -1 -1 -1 -1 -1
## 2 1 1 1 1 1 1
##
## Responses:
## [1] Check_Results
##
## Design generating information:
## $legend
## [1] A=A B=B C=C D=D E=E F=F
##
## $generators
## [1] D=AB E=AC F=BC
##
##
## Alias structure:
## $main
## [1] A=BD=CE B=AD=CF C=AE=BF D=AB=EF E=AC=DF F=BC=DE
##
## $fi2
## [1] AF=BE=CD
##
##
## The design itself:
## SoilA SoilB FabricA FabricB Temp Surfactant Check_Results
## 1 -1 1 1 -1 -1 1 11.96
## 2 -1 1 -1 -1 1 -1 15.88
## 3 1 -1 -1 -1 -1 1 10.15
## 4 1 1 -1 1 -1 -1 12.34
## 5 1 -1 1 -1 1 -1 6.16
## 6 -1 -1 1 1 -1 -1 12.05
## 7 1 1 1 1 1 1 9.87
## 8 -1 -1 -1 1 1 1 8.76
## class=design, type= FrF2
M1<- lm(Comp_Partial$Check_Results~ as.factor(Comp_Partial$SoilA) + as.factor(Comp_Partial$SoilB)
+ as.factor(Comp_Partial$FabricA) + as.factor(Comp_Partial$FabricB)
+ as.factor(Comp_Partial$Temp) + as.factor(Comp_Partial$Surfactant))
summary(M1)
##
## Call:
## lm.default(formula = Comp_Partial$Check_Results ~ as.factor(Comp_Partial$SoilA) +
## as.factor(Comp_Partial$SoilB) + as.factor(Comp_Partial$FabricA) +
## as.factor(Comp_Partial$FabricB) + as.factor(Comp_Partial$Temp) +
## as.factor(Comp_Partial$Surfactant))
##
## Residuals:
## 1 2 3 4 5 6 7 8
## -1.091 1.091 1.091 -1.091 -1.091 1.091 1.091 -1.091
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.8963 1.0912 9.985 0.0635 .
## as.factor(Comp_Partial$SoilA)1 -1.2663 1.0912 -1.160 0.4528
## as.factor(Comp_Partial$SoilB)1 1.6163 1.0912 1.481 0.3781
## as.factor(Comp_Partial$FabricA)1 -0.8862 1.0912 -0.812 0.5658
## as.factor(Comp_Partial$FabricB)1 -0.1412 1.0912 -0.129 0.9181
## as.factor(Comp_Partial$Temp)1 -0.7288 1.0912 -0.668 0.6252
## as.factor(Comp_Partial$Surfactant)1 -0.7112 1.0912 -0.652 0.6323
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.087 on 1 degrees of freedom
## Multiple R-squared: 0.8357, Adjusted R-squared: -0.15
## F-statistic: 0.8479 on 6 and 1 DF, p-value: 0.6808
As we can see, the experiment does not provide a good fit for the data.
par(mfrow=c(2,2))
plot(M1)
par(mfrow=c(1,1))
We can further see this with the diagnostics plots. The residuals vs fitted may suggest there is a pattern that is not being considered by the model. The residuals are not normal, scale loaction is not evenly spread, but there does not seem to be influential outliers. An issue with this design is the small amount of experiments, as such it is difficult to gauge the fit.
M1T<- lm(Comp_TDesign_2$Results~ Comp_TDesign_2$SoilA + Comp_TDesign_2$SoilB + as.factor(Comp_TDesign_2$FabricA)
+ Comp_TDesign_2$FabricB + Comp_TDesign_2$Temp + Comp_TDesign_2$Surfactant)
summary(M1T)
##
## Call:
## lm.default(formula = Comp_TDesign_2$Results ~ Comp_TDesign_2$SoilA +
## Comp_TDesign_2$SoilB + as.factor(Comp_TDesign_2$FabricA) +
## Comp_TDesign_2$FabricB + Comp_TDesign_2$Temp + Comp_TDesign_2$Surfactant)
##
## Residuals:
## 1 2 3 4 5 6 7 8
## 1.654 -1.654 -1.654 1.654 -1.654 1.654 -1.654 1.654
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.906 4.375 1.807 0.322
## Comp_TDesign_2$SoilA 3.652 3.307 1.104 0.468
## Comp_TDesign_2$SoilB 4.867 3.307 1.472 0.380
## as.factor(Comp_TDesign_2$FabricA)1 -3.163 3.307 -0.956 0.514
## Comp_TDesign_2$FabricB -4.902 3.307 -1.482 0.378
## Comp_TDesign_2$Temp 3.408 3.307 1.030 0.491
## Comp_TDesign_2$Surfactant 4.003 3.307 1.210 0.440
##
## Residual standard error: 4.678 on 1 degrees of freedom
## Multiple R-squared: 0.9002, Adjusted R-squared: 0.3016
## F-statistic: 1.504 on 6 and 1 DF, p-value: 0.554
par(mfrow=c(2,2))
plot(M1T)
par(mfrow=c(1,1))
We can look at the diagnostics plots. The residuals look like there is a a pattern that is not being considered by the model. The residuals are not normal, scale loaction is not evenly spread, but there does not seem to be influential outliers. Again an issue with this design is the small amount of experiments, as such it is difficult to gauge the fit.
M2T<- lm(Comp_TDesign$Results~ as.factor(Comp_TDesign$Soil) + as.factor(Comp_TDesign$Fabric)
+ as.factor(Comp_TDesign$Temp) + as.factor(Comp_TDesign$Surfactant))
summary(M2T)
##
## Call:
## lm.default(formula = Comp_TDesign$Results ~ as.factor(Comp_TDesign$Soil) +
## as.factor(Comp_TDesign$Fabric) + as.factor(Comp_TDesign$Temp) +
## as.factor(Comp_TDesign$Surfactant))
##
## Residuals:
## 1 2 3 4 5 6
## 6.075e-01 -3.053e-16 -6.075e-01 -6.075e-01 1.943e-16 -1.388e-16
## 7 8
## 6.075e-01 1.388e-16
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.5600 1.2150 7.868 0.0805 .
## as.factor(Comp_TDesign$Soil)2 6.0000 1.3584 4.417 0.1417
## as.factor(Comp_TDesign$Soil)3 8.5200 1.2150 7.012 0.0902 .
## as.factor(Comp_TDesign$Fabric)2 -8.2100 1.2150 -6.757 0.0935 .
## as.factor(Comp_TDesign$Fabric)3 -9.8050 1.7183 -5.706 0.1104
## as.factor(Comp_TDesign$Temp)2 3.4075 0.8591 3.966 0.1572
## as.factor(Comp_TDesign$Surfactant)2 4.0025 0.8591 4.659 0.1346
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.215 on 1 degrees of freedom
## Multiple R-squared: 0.9933, Adjusted R-squared: 0.9529
## F-statistic: 24.59 on 6 and 1 DF, p-value: 0.1532
We can see that in this case the fit is significantly better.
par(mfrow=c(2,2))
plot(M2T)
par(mfrow=c(1,1))
From the diagnostics plots we see that the residuals vs fitted may suggest there is a pattern that is not being considered by the model. The residuals are not normal, scale loaction is not evenly spread, but there does not seem to be influential outliers. An issue with this design is the small amount of experiments, as such it is difficult to gauge the fit. It would be advisable to run more experiments.
Finally we compare the models to the full design.
M3Full<- lm(Data$Result~ Data$Soil + Data$Fabric + Data$Temp + Data$Surfactant)
summary(M3Full)
##
## Call:
## lm.default(formula = Data$Result ~ Data$Soil + Data$Fabric +
## Data$Temp + Data$Surfactant)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.9569 -1.4582 0.0454 1.5831 5.2839
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.89833 1.36884 7.962 8.83e-09 ***
## Data$Soil2 3.14083 1.26730 2.478 0.019263 *
## Data$Soil3 10.35833 1.26730 8.174 5.18e-09 ***
## Data$Fabric2 -5.32917 1.26730 -4.205 0.000229 ***
## Data$Fabric3 -4.82417 1.26730 -3.807 0.000675 ***
## Data$Temp2 -0.06056 1.03475 -0.059 0.953734
## Data$Surfactant2 0.13611 1.03475 0.132 0.896256
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.104 on 29 degrees of freedom
## Multiple R-squared: 0.76, Adjusted R-squared: 0.7103
## F-statistic: 15.31 on 6 and 29 DF, p-value: 7.929e-08
Our coeffecients are similar to some of the fits, and we can see which actually have significance.
par(mfrow=c(2,2))
plot(M3Full)
par(mfrow=c(1,1))
The plots are much better with the increased points. The residuals vs fitted may suggest there is a pattern that is not being considered by the model; squaring a term may resolve this. The residuals are normal, scale loaction is more evenly spread out than the previous ones, and there does not seem to be influential outliers.
Design and Analysis of Experiments, 8th Edition Douglas C. Montgomery
http://www.itl.nist.gov/div898/handbook/pri/section3/pri3343.htm#generating
The data: http://www.stat.ufl.edu/~winner/data/color_change.dat
Data Desc: http://www.stat.ufl.edu/~winner/data/color_change.txt
Data <- read.table("C:/Users/T420ortizf2/Documents/CollegeWork/Fall 2016/DesignOfExperiments/Project3/Data.txt", quote="\"")
names(Data) <- c("Soil", "Fabric", "Temp", "Surfactant", "Result")
str(Data)
Data[,1] <- as.factor(Data[,1])
Data[,2] <- as.factor(Data[,2])
Data[,3] <- as.factor(Data[,3])
Data[,4] <- as.factor(Data[,4])
str(Data)
levels(Data$Soil)
levels(Data$Fabric)
levels(Data$Temp)
levels(Data$Surfactant)
summary(Data$Result)
Data
#Fractional Factorial Design
library(FrF2)
Partial <- FrF2(8,6)
names(Partial)[1] <- "SoilA"
names(Partial)[2] <- "SoilB"
names(Partial)[3] <- "FabricA"
names(Partial)[4] <- "FabricB"
names(Partial)[5] <- "Temp"
names(Partial)[6] <- "Surfactant"
summary(Partial)
#Taguchi Design
library(qualityTools)
taguchiChoose(factors1 = 2, factors2 = 2, level1 = 3, level2 = 2, ia = 0)
taguchiDesign("L36_2_3_a")
taguchiChoose(factors1 = 6, level1 = 2, ia = 0)
taguchiDesign("L8_2")
TDesign <- as.data.frame(taguchiDesign("L8_2"))
TDesign <- TDesign[,-c(1,2,3,10,11)]
# change column names to match factors in experiment
colnames(TDesign) <- c("SoilA", "SoilB", "FabricA", "FabricB", "Temp", "Surfactant")
TDesign2 <- TDesign-1
TDesign2 <- TDesign-1
TDesign2
T_Soil <- TDesign2[,1] + TDesign2[,2]
T_Soil <- T_Soil + 1
T_Soil
T_Fabric <- TDesign2[,3] + TDesign2[,4]
T_Fabric <- T_Fabric + 1
T_Fabric
Check_Soil <- T_Soil
Check_Fabric <- T_Fabric
Check_Temp <-TDesign2$Temp + 1
Check_Suractant <- TDesign2$Surfactant + 1
Check_Results <- rep(NA,8)
#Cycle through and find matching experiments
for(i in 1:8){
for(j in 1:36){
if((Check_Soil[i] == Data[j,1]) && (Check_Fabric[i] == Data[j,2])
&& (Check_Temp[i] == Data[j,3]) && (Check_Suractant[i] == Data[j,4])){
Check_Results[i] <- Data[j,5]
}
}
}
Check_Results
#Rename and format experiment matrices for fractional
Comp_TDesign <- data.frame(Check_Soil, Check_Fabric, Check_Temp, Check_Suractant, Check_Results)
colnames(Comp_TDesign) <- c("Soil", "Fabric", "Temp", "Surfactant", "Results")
Comp_TDesign
Comp_TDesign_2 <- data.frame(TDesign2[,1],TDesign2[,2],TDesign2[,3],TDesign2[,4],TDesign2[,5],TDesign2[,6], Check_Results)
colnames(Comp_TDesign_2) <- c("SoilA", "SoilB", "FabricA", "FabricB", "Temp", "Surfactant", "Results")
Comp_TDesign_2
Check_Soil <- c(2, 3, 2, 2, 1, 2, 3, 1)
Check_Fabric <- c(2, 3, 2, 1, 3, 1, 2, 2)
Check_Temp <-c(1, 2, 2, 2, 1, 1, 1, 2)
Check_Suractant <- c(2, 2, 1, 1, 1, 2, 1, 2)
Check_Results <- rep(NA,8)
for(i in 1:8){
for(j in 1:36){
if((Check_Soil[i] == Data[j,1]) && (Check_Fabric[i] == Data[j,2])
&& (Check_Temp[i] == Data[j,3]) && (Check_Suractant[i] == Data[j,4])){
Check_Results[i] <- Data[j,5]
}
}
}
Check_Results
Comp_Partial <- add.response(Partial, Check_Results)
summary(Comp_Partial)
#Fractional Factorial Model
M1<- lm(Comp_Partial$Check_Results~ as.factor(Comp_Partial$SoilA) + as.factor(Comp_Partial$SoilB)
+ as.factor(Comp_Partial$FabricA) + as.factor(Comp_Partial$FabricB)
+ as.factor(Comp_Partial$Temp) + as.factor(Comp_Partial$Surfactant))
summary(M1)
#Diagnostic Plots
par(mfrow=c(2,2))
plot(M1)
par(mfrow=c(1,1))
#Taguchi 6 2 level factors
M1T<- lm(Comp_TDesign_2$Results~ Comp_TDesign_2$SoilA + Comp_TDesign_2$SoilB + as.factor(Comp_TDesign_2$FabricA)
+ Comp_TDesign_2$FabricB + Comp_TDesign_2$Temp + Comp_TDesign_2$Surfactant)
summary(M1T)
#Diagnostic Plots
par(mfrow=c(2,2))
plot(M1T)
par(mfrow=c(1,1))
#Taguchi with 3 level factors
M2T<- lm(Comp_TDesign$Results~ as.factor(Comp_TDesign$Soil) + as.factor(Comp_TDesign$Fabric)
+ as.factor(Comp_TDesign$Temp) + as.factor(Comp_TDesign$Surfactant))
summary(M2T)
#Diagnostic Plots
par(mfrow=c(2,2))
plot(M2T)
par(mfrow=c(1,1))
#Full Design
M3Full<- lm(Data$Result~ Data$Soil + Data$Fabric + Data$Temp + Data$Surfactant)
summary(M3Full)
#Diagnostic Plots
par(mfrow=c(2,2))
plot(M3Full)
par(mfrow=c(1,1))