Difference between revisions of "Worksheets/Week3"
Jump to navigation
Jump to search
Kevin Dunn (talk | contribs) |
Kevin Dunn (talk | contribs) (→Part 1) |
||
(28 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=== Part 1 === | === Part 1 === | ||
A factorial experiment was run to investigate the settings that minimize the production of an unwanted side product. The two factors being investigated are called A and B for simplicity. | |||
<html><div data-datacamp-exercise data-lang="r" data-height="auto"> | <html><div data-datacamp-exercise data-lang="r" data-height="auto"> | ||
<code data-type="sample-code"> | <code data-type="sample-code"> | ||
# | # A = additive at 20mL and 30mL for low and high levels | ||
A | A = c(-1, +1, -1, +1) | ||
B | |||
y | # B = without (-) or with (+) baffles | ||
B = c(-1, -1, +1, +1) | |||
summary( | |||
library(pid) | # Response y is the amount of side product formed, y [grams] | ||
contourPlot( | y = c(89, 268, 179, 448) | ||
# Fit a linear model | |||
model_siderxn = lm(y ~ A + B + A*B) | |||
summary(model_siderxn) | |||
# Uncomment this line if you run the code in RStudio | |||
#library(pid) | |||
# Comment this line if you run this code in RStudio | |||
source('https://yint.org/contourPlot.R') | |||
# See how the two factors affect the response: | |||
contourPlot(model_siderxn) | |||
interaction.plot(A, B, y) | interaction.plot(A, B, y) | ||
interaction.plot(B, A, y) | interaction.plot(B, A, y) | ||
# Make a prediction with this model: | |||
xA = -1 | |||
xB = -1 | |||
y.hat = predict(model_siderxn, data.frame(A = xA, B = xB)) | |||
paste0('Predicted value is: ', y.hat, ' grams of side product.') | |||
</code> | |||
</div></html> | |||
=== Part 2 === | |||
Continuing from above, with 2 extra experimental points: | |||
<html><div data-datacamp-exercise data-lang="r" data-height="500px"> | |||
<code data-type="sample-code"> | |||
# A = additive at 20mL and 30mL for low and high levels | |||
A = c(-1, +1, -1, +1, 0, 0) | |||
# B = without (-) or with (+) baffles | |||
B = c(-1, -1, +1, +1, -1, +1) | |||
# Response y is the amount of side product formed, y [grams] | |||
y = c(89, 268, 179, 448, 186, 300) | |||
model_siderxn_cp <- lm(y ~ A + B + A*B) | |||
summary(model_siderxn_cp) | |||
# Uncomment this line if you run the code in RStudio | |||
#library(pid) | |||
# Comment this line if you run this code in RStudio | |||
source('https://yint.org/contourPlot.R') | |||
contourPlot(model_siderxn_cp) | |||
</code> | </code> | ||
</div></html> | </div></html> |
Latest revision as of 13:35, 26 September 2019
Part 1
A factorial experiment was run to investigate the settings that minimize the production of an unwanted side product. The two factors being investigated are called A and B for simplicity.
# A = additive at 20mL and 30mL for low and high levels
A = c(-1, +1, -1, +1)
# B = without (-) or with (+) baffles
B = c(-1, -1, +1, +1)
# Response y is the amount of side product formed, y [grams]
y = c(89, 268, 179, 448)
# Fit a linear model
model_siderxn = lm(y ~ A + B + A*B)
summary(model_siderxn)
# Uncomment this line if you run the code in RStudio
#library(pid)
# Comment this line if you run this code in RStudio
source('https://yint.org/contourPlot.R')
# See how the two factors affect the response:
contourPlot(model_siderxn)
interaction.plot(A, B, y)
interaction.plot(B, A, y)
# Make a prediction with this model:
xA = -1
xB = -1
y.hat = predict(model_siderxn, data.frame(A = xA, B = xB))
paste0('Predicted value is: ', y.hat, ' grams of side product.')
Part 2
Continuing from above, with 2 extra experimental points:
# A = additive at 20mL and 30mL for low and high levels
A = c(-1, +1, -1, +1, 0, 0)
# B = without (-) or with (+) baffles
B = c(-1, -1, +1, +1, -1, +1)
# Response y is the amount of side product formed, y [grams]
y = c(89, 268, 179, 448, 186, 300)
model_siderxn_cp <- lm(y ~ A + B + A*B)
summary(model_siderxn_cp)
# Uncomment this line if you run the code in RStudio
#library(pid)
# Comment this line if you run this code in RStudio
source('https://yint.org/contourPlot.R')
contourPlot(model_siderxn_cp)