Factorial Experiments R Codes
Factorial Experiments R Codes
Department of Statistics
MSC, Sem II,2020-21
Title: factorial Experiments
Ref: PDT/III/1
R – Codes
Q.1 The yield of a chemical process is being studied. The two most important variables are thought to
be the pressure and the temperature. Three levels of each factor are selected, and a factorial
experiment with two replicates is performed. The yield data are as follows:
(b) Prepare appropriate residual plots and comment on the model’s adequacy.
R-codes
#data entry
Observation=c(90.4,90.2,90.1,90.3,90.5,90.7,90.7,90.6,90.5,90.6,90.8,90.9,90.2,90.4,89.9,90.1,90.4
, 90.1)
Pressure=rep(c(200,215,230),c(6,6,6));Pressure
Temperature=rep(c(150,150,160,160,170,170),3);Temperature
Pressure=factor(Pressure);Temperature=factor(Temperature)
#Q.1 (a)
#define the model using syntax ‘aov’ and store in the variable chem_process. One can also use the
syntax ‘lm’ instead of ‘aov’
chem_process=aov(Observation~Pressure+Temperature)
# In the interaction plot it is observed that there can be interaction present. Therefore, we fit another
model with interaction present as below.
chem_process2=aov(Observation~Pressure*Temperature)
summary(chem_process2)
anova(chem_process2)
# Q.1 (b)
# We need to assess the normality of the residuals and the constant variance of the same. We use
the model without interaction as interaction is insignificant.
#another way of doing this is extracting the residuals and fitted values and then plotting them
accordingly.
residual=chem_process$residuals
fits=chem_process$fitted.values
values #Q.1 (c) use the interaction plot to answer this question
Q.2 An engineer suspects that the surface finish of a metal part is influenced by the feed rate and the
depth of cut. He selects three feed rates and four depths of cut. He then conducts a factorial
experiment and obtains the following data:
2
(a) Analyze the data and draw conclusions. Use (α = 0.05).
(b) Prepare appropriate residual plots and comment on the model’s adequacy.
(c) Obtain point estimates of the mean surface finish at each feed rate.
R-codes
# Data entry
surfin=c(74,64,60,92,86,88,99,98,102,79,68,73,98,104,88,104,99,95,82,88,92,99,108,95,108,110,99
, 99,104,96,104,110,99,114,111,107) # Surface Finish
#Q.2 (a)
model=aov(surfin~rate*cut)
summary(model)
anova(model)
#Q.2 (b)
plot(model,2) # QQ plot
#Q.2 (c)
rate_mean=aggregate(surfin~rate,FUN = mean);rate_mean
#Q.2 (d)
Q.3 For the data in Q.2, compute a 95 percent confidence interval estimate of the mean difference in
response for feed rates of 0.20 and 0.25 in/min.
#The 95% confidence interval for the mean difference in response for feed rates of 0.20 and 0.25 is,
3
2������
#{ (��̅1∙- ��̅2∙) – terror df,0.025 √
2������
����, (��̅1∙- ��̅2∙) + terror df,0.025 √
����}
#define
LL;UL
Q.4. Use Tukey’s test to determine which levels of the pressure factor are significantly different for
the data in Q.1.
R-codes
TukeyHSD(chem_process,”Pressure”,conf.level=0.95)
Q.5 Consider the following data from a two-factor factorial experiment. Analyze the data and draw
conclusions. Perform a test for non-additivity. Use (α = 0.05).
R-codes
#data entry
obs=c(36,18,30,39,20,37,36,22,33,32,20,34) #observation
experiment=aov(obs~row+colm)
anova(experiment)
4
Install.packages(“additivityTests”)
library("additivityTests")
data_matrix=matrix(obs,3,4);data_matrix
tukey.test(data_matrix, alpha=0.05)
Q.6 An article in the IEEE Transactions on Electron Devices (Nov. 1986, pp. 1754) describes a study on
polysilicon doping. The experiment shown below is a variation of their study. The response variable is
base current.
(a) Is there evidence (with α = 0.05) indicating that either polysilicon doping level or anneal
temperature affects base current?
R-codes
#data entry
current=c(4.6,4.4,3.2,3.5,10.15,10.2,9.38,10.02,11.01,10.58,10.81,10.61) # base
current polydope=rep(c(-1,-1,1,1),3) # polysilicon doping
polytemp=polydope*temp
# Students are to solve the problems (a), (b) and (c). I am producing the commands for
study=lm(current~polydope+temp+temp2+polytemp)
summary(study)
study$coefficients
5
# now we see the commands for plotting the response function
x1=x2=seq(-1,1,0.1)
y=function(x1,x2){
y=9.9375-0.285*x1+3.41375*x2-2.5985*x2*x2+0.26625*x1*x2
# try varying the arguments of the syntax ‘persp’ like col, shade, theta and phi. ‘theta’ rotates the
graph horizontally while ‘phi’ rotates the graph vertically.