Free Course on Response Surface Methodology with R
R Code for Lesson 5: Designs with Central Points – Interpreting a Lousy Fitting
Copy and paste the code below in your R Studio to follow the example in Lesson 5: Designs with Central Points – Interpreting a Lousy Fitting
(Video-Lesson Available on April 10, 2023)
# Designs with Central Points – Interpreting a Lousy Fitting
# 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: DoEOpt05
# Time (x1): Time (min)
# Temp (x2): Temperature (ºC)
# Y: Yield (%)
# building the data set
# (run this code to build the DoEOpt05 data set before following the analysis)
<- data.frame(x1 = c(-1,-1,1,1,0,0,0,0,0),
DoEOpt05 x2 = c(-1,1,-1,1,0,0,0,0,0),
Time = c(80,80,90,90,85,85,85,85,85),
Temp = c(170,180,170,180,175,175,175,175,175),
Y = c(76.5,77,78,79.5,79.9,80.3,80,79.7,79.8)
)
# loading Response Surface Methodology package
library(rsm)
# file view
str(DoEOpt05)
<- as.coded.data(DoEOpt05,
DoEOpt05 ~ (Time-85)/5,
x1 ~ (Temp-175)/5)
x2
# regression model with coded variables
<- rsm(Y ~ FO(x1,x2) + TWI(x1,x2), data = DoEOpt05)
model summary(model)
# plots
plot(DoEOpt05$Time, DoEOpt05$Y, xlab = "Time", ylab = "Yield (%)")
plot(DoEOpt05$Temp, DoEOpt05$Y, xlab = "Temperature", ylab = "Yield (%)")
contour(model, ~ x1+x2,
image = TRUE,
xlabs=c("Time (min)", "Temperature (ºC)"))
points(DoEOpt05$Time,DoEOpt05$Temp)