0% found this document useful (0 votes)
194 views7 pages

Factorial Experiments R Codes

This document provides R code for analyzing data from several factorial experiments. It includes code for data entry, ANOVA, residual analysis, and other statistical tests. Questions cover topics like analyzing and interpreting factorial experiment data, testing for interactions and non-additivity, estimating means and confidence intervals, and building regression models. R functions used include aov(), anova(), TukeyHSD(), and lm(). Graphical displays like interaction plots, residual plots, and response surface plots are also demonstrated.

Uploaded by

48Raut Aparna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
194 views7 pages

Factorial Experiments R Codes

This document provides R code for analyzing data from several factorial experiments. It includes code for data entry, ANOVA, residual analysis, and other statistical tests. Questions cover topics like analyzing and interpreting factorial experiment data, testing for interactions and non-additivity, estimating means and confidence intervals, and building regression models. R functions used include aov(), anova(), TukeyHSD(), and lm(). Graphical displays like interaction plots, residual plots, and response surface plots are also demonstrated.

Uploaded by

48Raut Aparna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

University of Mumbai

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:

(a) Analyse the data and draw conclusions. Use (α = 0.05).

(b) Prepare appropriate residual plots and comment on the model’s adequacy.

(c) Under what conditions would you operate this process?

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 and Temperature must be converted to qualitative factors if ANOVA is to be conducted.


Use following syntax

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)

summary(chem_process) # produces summary of the model


1
anova(chem_process) # produces ANOVA of the model

interaction.plot(Pressure,Temperature,response = Observation,fun = mean,col =


c("red","blue","yellow"))

# 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.

plot(chem_process,1) # for residual vs fit

plot(chem_process,2) # for QQ plot

#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

qqnorm(residual) # for QQ plot of residuals

qqline(residual) # draw the straight line through the points.

plot(fits,residual,xlab = "fitted values",ylab = "residuals") # plots residual vs fitted

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.

(d) Find the P-values for the tests in part (a).

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

rate=rep(c(0.2,0.2,0.2,0.25,0.25,0.25,0.3,0.3,0.3),4);rate=factor(rate) # Feed rate

cut=rep(c(0.15,0.18,0.20,0.25),rep(9,4));cut=factor(cut) # depth cut

#Q.2 (a)

model=aov(surfin~rate*cut)

summary(model)

anova(model)

interaction.plot(rate,cut,surfin,col=c("red","blue","yellow","green")) # argument 'fun = mean' is


default, therefore need not be specified

#Q.2 (b)

plot(model,1) # residual vs fits

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.

R-codes Refer to section 3.5 of the reference book.

#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

y1.=rate_mean[1,2] # mean surface finish at feed rate 0.2

y2.=rate_mean[2,2] # mean surface finish at feed rate 0.25

t = qt(0.025, model$df.residual,lower.tail=FALSE) # terror df ,. Or directly refer ANOVA table and define


t=qt(0.975,df=24);MSE = 689.33

b=4 # number of levels of depth of cut

n=3 # number of replication

LL=(y1.-y2.)-t*sqrt(2*MSE/(b*n)) # lower limit

UL=(y1.-y2.)+t*sqrt(2*MSE/(b*n)) #upper limit

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

row=rep(1:3,4);row=factor(row) # row factor

colm=rep(1:4,rep(3,4));colm=factor(colm)# column factor

#ANOVA without interaction

experiment=aov(obs~row+colm)

anova(experiment)

#Tukey’s test for non-additivity

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?

(b) Prepare graphical displays to assist in interpreting this experiment.

(c) Analyse the residuals and comment on model adequacy.

(d) Is the model

y = β0 + β1x1 + β2x2 + β22x22 + β12x1x2 + ϵ


supported by this experiment (x1 = doping level, x2 = temperature)? Estimate the parameters in this
model and plot the response surface.

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

temp=rep(-1:1,c(4,4,4)) # anneal temperature

temp2=temp^2 # square of entries in temp

polytemp=polydope*temp

# Students are to solve the problems (a), (b) and (c). I am producing the commands for

(d) Q.6 (d)

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

} # the response function

response=outer(x1,x2,y) # applying function y at all possible combination of x1 and x2

persp(x1,x2,response, main = "Base current vs Polysilicon Doping and Anneal Temperature",

xlab = "Polysilicon Doping",ylab = "Anneal Temperature",zlab = "Base Current", col =

cm.colors(length(response)),shade = 0.2,theta = 60,phi = 30)

contour(x1,x2,response,col = rainbow(10),main="contour plot of base

current", xlab="polysilicon doping",ylab="Anneal temperature")

filled.contour(x1,x2,response,main="contour plot of base

current",col=topo.colors(20) ,xlab="polysilicon doping",ylab="Anneal temperature")

# 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.

# to understand more about colors visit https://www.datamentor.io/r-programming/color/


6

You might also like