Difference between revisions of "Worksheets/Week3"

From Statistics for Engineering
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 7: Line 7:


# A = additive at 20mL and 30mL for low and high levels
# A = additive at 20mL and 30mL for low and high levels
A <- c(-1, +1, -1, +1)
A = c(-1, +1, -1, +1)


# B = without (-) or with (+) baffles
# B = without (-) or with (+) baffles
B <- c(-1, -1, +1, +1)
B = c(-1, -1, +1, +1)


# Response y is the amount of side product formed, y [grams]
# Response y is the amount of side product formed, y [grams]
y <- c(89, 268, 179, 448)
y = c(89, 268, 179, 448)


# Fit a linear model
# Fit a linear model
model.siderxn <- lm(y ~ A + B + A*B)
model_siderxn = lm(y ~ A + B + A*B)
summary(model.siderxn)
summary(model_siderxn)




Line 27: Line 27:


# See how the two factors affect the response:
# See how the two factors affect the response:
contourPlot(model.siderxn)
contourPlot(model_siderxn)
interaction.plot(A, B, y)
interaction.plot(A, B, y)
interaction.plot(B, A, y)
interaction.plot(B, A, y)
Line 34: Line 34:
xA = -1
xA = -1
xB = -1
xB = -1
y.hat <- predict(model.siderxn, data.frame(A = xA, B = xB))
y.hat = predict(model_siderxn, data.frame(A = xA, B = xB))
paste0('Predicted value is: ', y.hat, ' grams of side product.')
paste0('Predicted value is: ', y.hat, ' grams of side product.')
     </code>
     </code>
Line 46: Line 46:


# A = additive at 20mL and 30mL for low and high levels
# A = additive at 20mL and 30mL for low and high levels
A <- c(-1, +1, -1, +1, 0, 0)
A = c(-1, +1, -1, +1, 0, 0)


# B = without (-) or with (+) baffles
# B = without (-) or with (+) baffles
B <- c(-1, -1, +1, +1, -1, +1)
B = c(-1, -1, +1, +1, -1, +1)


# Response y is the amount of side product formed, y [grams]
# Response y is the amount of side product formed, y [grams]
y <- c(89, 268, 179, 448, 186, 290)
y = c(89, 268, 179, 448, 186, 300)
model.siderxn.cp <- lm(y ~ A + B + A*B)
model_siderxn_cp <- lm(y ~ A + B + A*B)
summary(model.siderxn.cp)
summary(model_siderxn_cp)


# Uncomment this line if you run the code in RStudio
# Uncomment this line if you run the code in RStudio
Line 61: Line 61:
# Comment this line if you run this code in RStudio
# Comment this line if you run this code in RStudio
source('https://yint.org/contourPlot.R')
source('https://yint.org/contourPlot.R')
contourPlot(model.siderxn.cp)
contourPlot(model_siderxn_cp)
    </code>
</div></html>
 
=== Part 3 ===
 
Your family runs a small business selling products online. The first factor of interest is whether to provide free shipping over €30 or over €50. The second factor is whether or not the purchaser must first create a profile before completing the transaction. The purchaser can still complete their transaction without creating a profile. Below are the data collected, showing the 8 experiments.
 
 
<html><div data-datacamp-exercise data-lang="r" data-height="500px">
    <code data-type="sample-code">
 
# S = Free shipping if order amount is €30 or more [-1],
# or if order amount is over €50 [+1]
S <- c(-1, +1, -1, +1, -1, +1, -1, +1)
 
# Does the purchaser need to create a profile first [+1] or not [-1]?
P <- c(-1, -1, +1, +1, -1, -1, +1, +1)
 
# Response: daily sales amount
y <- c(348, 359, 327, 243, 356, 363, 296, 257)
 
# Linear model using S, P and S*P to predict the response
model.sales <- lm(y ~ S*P)
summary(model.sales)
 
# 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.sales)
interaction.plot(S, P, y)
interaction.plot(P, S, y)
    </code>
</div></html>
 
=== Part 4 ===
 
Continuing with the case above:
 
<html><div data-datacamp-exercise data-lang="r" data-height="500px">
    <code data-type="sample-code">
 
# S = Free shipping if order amount is €30 or more [-1], or if
# order amount is over €50 [+1]. Notice that a mistake was made
# with the last experiment: order minimum for free shipping was €60 [+1].
S <- c(-1, +1, -1, +1, -1, +1, -1, +2)
 
# Does the purchaser need to create a profile first [+1] or not [-1]?
P <- c(-1, -1, +1, +1, -1, -1, +1, +1)
 
# Response: daily sales amount
y <- c(348, 359, 327, 243, 356, 363, 296, 220)
 
# Linear model using S, P and S*P to predict the response
model.sales.mistake <- lm(y ~ S*P)
summary(model.sales.mistake)
 
# 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.sales.mistake)
    </code>
</div></html>
 
=== Part 5 ===
 
Your group is developing a new product, but have been struggling to get the product’s stability, measured in days, to the level required. You are aiming for a stability value of 50 days or more.
 
<html><div data-datacamp-exercise data-lang="r" data-height="auto">
    <code data-type="sample-code">
 
# Define the 3 factors. This code is a template that you
# can easily extend and reuse for full factorial designs:
base <- c(-1, +1)
design <- expand.grid(A=base, B=base, C=base)
A <- design$A
B <- design$B
C <- design$C
 
# Type "A", and "B" and "C" at the command prompt
# to verify what these letters contain. Are they in
# standard order? Look at the "design" variable also.
 
# The response: stability [units=days]
y <- c(40, 27, 35, 21, 41, 27, 31, 20)
 
# Linear model to predict stability from
# A: enzyme strength:  -1 == 20%; +1 == 30%
# B: feed concentration: -1 == 5%; +1 == 15%
# C: mixer type:  -1 = R mixer; +1 = W mixer
model.stability <- lm(y ~ A*B*C)
summary(model.stability)
 
# Uncomment this line if you run the code in RStudio
#library(pid)
# Comment these 2 lines if you run this code in RStudio
source('https://yint.org/paretoPlot.R')
source('https://yint.org/contourPlot.R')
paretoPlot(model.stability)
contourPlot(model.stability, 'A', 'B')
contourPlot(model.stability, 'A', 'C')
     </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)