Difference between revisions of "Worksheets/Week2"

From Statistics for Engineering
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Navigation|Book=Worksheets|previous=|current=Worksheets|next=Week3}}
A baked food product:
* T = time used to bake the product
* F = quantity of fat added


<html><div data-datacamp-exercise data-lang="r" data-height="auto">
<html><div data-datacamp-exercise data-lang="r" data-height="auto">
Line 9: Line 4:


# T = time used for baking: (-1) corresponds to 80 minutes and (+1) corresponds to 100 minutes
# T = time used for baking: (-1) corresponds to 80 minutes and (+1) corresponds to 100 minutes
T <- c(-1, +1, -1, +1)
T = c(-1, +1, -1, +1)


# F = quantity of fat used: (-1) corresponds to 20 g and (+1) corresponds to 30 grams
# F = quantity of fat used: (-1) corresponds to 20 g and (+1) corresponds to 30 grams
F <- c(-1, -1, +1, +1)
F = c(-1, -1, +1, +1)


# Response y is the crispiness
# Response y is the crispiness
y <- c(37, 57, 49, 53)
y = c(37, 57, 49, 53)


# Fit a linear model
# Fit a linear model
model_crispy <- lm(y ~ T + F + T*F)
model_crispy = lm(y ~ T + F + T*F)
summary(model_crispy)
summary(model_crispy)


Line 33: Line 28:


# Make a prediction with this model:
# Make a prediction with this model:
xT = -1   # corresponds to 110 minutes
xT = +2   # corresponds to 110 minutes
xF = -1  # corresponds to 20 grams of fat
xF = -1  # corresponds to 20 grams of fat
y.hat <- predict(model_crispy, data.frame(T = xT, F = xF))
y.hat = predict(model_crispy, data.frame(T = xT, F = xF))
paste0('Predicted value is: ', y.hat, ' crispiness.')
paste0('Predicted value is: ', y.hat, ' crispiness.')
     </code>
     </code>
</div></html>
</div></html>

Latest revision as of 13:33, 26 September 2019

# T = time used for baking: (-1) corresponds to 80 minutes and (+1) corresponds to 100 minutes T = c(-1, +1, -1, +1) # F = quantity of fat used: (-1) corresponds to 20 g and (+1) corresponds to 30 grams F = c(-1, -1, +1, +1) # Response y is the crispiness y = c(37, 57, 49, 53) # Fit a linear model model_crispy = lm(y ~ T + F + T*F) summary(model_crispy) # 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_crispy ) interaction.plot(T, F, y) interaction.plot(F, T, y) # Make a prediction with this model: xT = +2 # corresponds to 110 minutes xF = -1 # corresponds to 20 grams of fat y.hat = predict(model_crispy, data.frame(T = xT, F = xF)) paste0('Predicted value is: ', y.hat, ' crispiness.')