Difference between revisions of "Worksheets/Week4"

From Statistics for Engineering
Jump to navigation Jump to search
(Created page with "=== Part 1 === 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 secon...")
 
 
(10 intermediate revisions by the same user not shown)
Line 9: Line 9:
# S = Free shipping if order amount is €30 or more [-1],
# S = Free shipping if order amount is €30 or more [-1],
# or if order amount is over €50 [+1]
# or if order amount is over €50 [+1]
S <- c(-1, +1, -1, +1, -1, +1, -1, +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 = Does the purchaser need to create a profile first [+1] or not [-1]?
P <- c(-1, -1, +1, +1, -1, -1, +1, +1)
P = c(-1, -1, +1, +1, -1, -1, +1, +1)


# Response: daily sales amount
# Response: daily sales amount
y <- c(348, 359, 327, 243, 356, 363, 296, 257)
y = c(348, 359, 327, 243, 356, 363, 296, 257)


# Linear model using S, P and S*P to predict the response
# Linear model using S, P and S*P to predict the response
model.sales <- lm(y ~ S*P)
model_sales = lm(y ~ S*P)
summary(model.sales)
summary(model_sales)


# Uncomment this line if you run the code in RStudio
# Uncomment this line if you run the code in RStudio
Line 26: Line 26:
source('https://yint.org/contourPlot.R')
source('https://yint.org/contourPlot.R')


contourPlot(model.sales)
contourPlot(model_sales)
interaction.plot(S, P, y)
 
interaction.plot(P, S, y)
# Uncomment and re-run these lines to understand
# the interactions
#interaction.plot(S, P, y)
#interaction.plot(P, S, y)
     </code>
     </code>
</div></html>
</div></html>
Line 41: Line 44:
# S = Free shipping if order amount is €30 or more [-1], or if
# 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  
# order amount is over €50 [+1]. Notice that a mistake was made  
# with the last experiment: order minimum for free shipping was €60 [+1].
# with the last experiment: order minimum for free shipping was €60 [+2].
S <- c(-1, +1, -1, +1, -1, +1, -1, +2)
S = c(-1, +1, -1, +1, -1, +1, -1, +2)


# Does the purchaser need to create a profile first [+1] or not [-1]?
# Does the purchaser need to create a profile first [+1] or not [-1]?
P <- c(-1, -1, +1, +1, -1, -1, +1, +1)
P = c(-1, -1, +1, +1, -1, -1, +1, +1)


# Response: daily sales amount
# Response: daily sales amount
y <- c(348, 359, 327, 243, 356, 363, 296, 220)
y = c(348, 359, 327, 243, 356, 363, 296, 220)


# Linear model using S, P and S*P to predict the response
# Linear model using S, P and S*P to predict the response
model.sales.mistake <- lm(y ~ S*P)
model_sales_mistake = lm(y ~ S*P)
summary(model.sales.mistake)
summary(model_sales_mistake)


# Uncomment this line if you run the code in RStudio
# Uncomment this line if you run the code in RStudio
Line 59: Line 62:
source('https://yint.org/contourPlot.R')
source('https://yint.org/contourPlot.R')


contourPlot(model.sales.mistake)
contourPlot(model_sales_mistake)
     </code>
     </code>
</div></html>
</div></html>
Line 72: Line 75:
# Define the 3 factors. This code is a template that you  
# Define the 3 factors. This code is a template that you  
# can easily extend and reuse for full factorial designs:
# can easily extend and reuse for full factorial designs:
base <- c(-1, +1)
base = c(-1, +1)
design <- expand.grid(A=base, B=base, C=base)
design = expand.grid(A=base, B=base, C=base)
A <- design$A
A = design$A
B <- design$B
B = design$B
C <- design$C
C = design$C


# Type "A", and "B" and "C" at the command prompt
# Type "A", and "B" and "C" at the command prompt
Line 83: Line 86:


# The response: stability [units=days]
# The response: stability [units=days]
y <- c(40, 27, 35, 21, 41, 27, 31, 20)
y = c(40, 27, 35, 21, 41, 27, 31, 20)


# Linear model to predict stability from
# Linear model to predict stability from
Line 89: Line 92:
# B: feed concentration: -1 == 5%; +1 == 15%  
# B: feed concentration: -1 == 5%; +1 == 15%  
# C: mixer type:  -1 = R mixer; +1 = W mixer
# C: mixer type:  -1 = R mixer; +1 = W mixer
model.stability <- lm(y ~ A*B*C)
model_stability = lm(y ~ A*B*C)
summary(model.stability)
summary(model_stability)


# Uncomment this line if you run the code in RStudio
# Uncomment this line if you run the code in RStudio
Line 97: Line 100:
source('https://yint.org/paretoPlot.R')
source('https://yint.org/paretoPlot.R')
source('https://yint.org/contourPlot.R')
source('https://yint.org/contourPlot.R')
paretoPlot(model.stability)
paretoPlot(model_stability)
contourPlot(model.stability, 'A', 'B')
 
contourPlot(model.stability, 'A', 'C')
# Uncomment these two lines later to inspect the
# contour plots
#contourPlot(model_stability, 'A', 'B')
#contourPlot(model_stability, 'A', 'C')
 
# Make a prediction with this model:
xA = 0
xB = 0
xC = 0
y.hat <- predict(model_stability, data.frame(A = xA, B = xB, C = xC))
paste0('Predicted stability is: ', y.hat, ' days.')
     </code>
     </code>
</div></html>
</div></html>

Latest revision as of 08:33, 3 October 2019

Part 1

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.


# 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) # P = 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) # Uncomment and re-run these lines to understand # the interactions #interaction.plot(S, P, y) #interaction.plot(P, S, y)

Part 2

Continuing with the case above:

# 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 [+2]. 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)

Part 3

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.

# 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) # Uncomment these two lines later to inspect the # contour plots #contourPlot(model_stability, 'A', 'B') #contourPlot(model_stability, 'A', 'C') # Make a prediction with this model: xA = 0 xB = 0 xC = 0 y.hat <- predict(model_stability, data.frame(A = xA, B = xB, C = xC)) paste0('Predicted stability is: ', y.hat, ' days.')