contact@statdoe.com

Response Surface Methodology

Free Course on Response Surface Methodology with R

R Code for Lesson 3: Analyzing a 22 Design with Central Points

Copy and paste the code below in your R Studio to follow the example in Lesson 3: Analyzing a 22 Design – R tutorial

# Analysis for a 2^2 Design with Central Points

# Author: Rosane Rech, January 2021.
# This code is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
# https://creativecommons.org/licenses/by-nc-sa/4.0/ 

# Data source:
# Design and analysis of experiments / Douglas C. Montgomery. — Eighth edition.
# ISBN 978-1-118-14692-7

# Data file: DoEOpt04.csv
# Time (x1): Time (min)
# Temp (x2): Temperature (ºC)
# Y: Yield (%)

# building the data set 
# (run this code to build the DoEOpt04 data set before following the analysis)

DoEOpt04 <- data.frame(x1 = c(-1,-1,1,1,0,0,0,0,0),
                          x2 = c(-1,1,-1,1,0,0,0,0,0),
                          Time = c(30,30,40,40,35,35,35,35,35),
                          Temp = c(150,160,150,160,155,155,155,155,155),
                          Y = c(39.3,40,40.9,41.5,40.3,40.5,40.7,40.2,40.6)
                            )

# loading Response Surface Methodology package

library(rsm)

# file view

str(DoEOpt04)

# setting the relationship between coded and natural variables

DoEOpt04 <- as.coded.data(DoEOpt04, 
              x1 ~ (Time-35)/5,
              x2 ~ (Temp-155)/5)

# regression model with coded variables

model <- rsm(Y ~ FO(x1,x2) + TWI(x1,x2), data = DoEOpt04)
summary(model)

# contour plot

contour(model, ~ x1+x2, 
        image = TRUE, 
        xlabs=c("Time (min)", "Temperature (ºC)"))
points(DoEOpt04$Time,DoEOpt04$Temp)