Objectives
- Practice model-building with simple linear regression, ANOVA, and
ANCOVA analyses.
- Predict expected values from fitted linear model objects.
Models
Create a new RMarkdown document in which to do your work.
In a code chunk, build the following linear models:
- Model 1: Build a simple linear regression model of
penguin bill length as predicted by body mass.
- Model 2: Build a one-way ANOVA model of penguin
bill length as predicted by penguin species.
- Model 3: Build a two-way additive ANOVA model of
penguin bill length predicted by sex and species.
- Model 4: Build a two way interactive ANOVA model of
penguin bill length predicted by sex and species.
- Model 5: Build an ANCOVA model of peuguin bill length as
predicted by: 1: sex 2: species 3: body mass
Your ANCOVA model should not contain any interaction
terms.
Data For Model Predictions
Refer to the lecture slides (deck 12a) for some examples of how to
create new data.frame
objects
For example, using my first model (called fit1
) I can
use the following code to predict the bill length of a penguin that
weighs 1 million grams:
newdata1 = data.frame(
body_mass_g = c(1000000))
predict(
fit1,
newdata = newdata1)
## 1
## 4078.315
Obviously, this is a silly prediction, but you may use this code as a
hint to get started with your own predictions.
Questions
Create a first-level heading in your RMarkdown document called
‘Questions’. Make this section a tabset.
You should answer each individual question under its own second-level
heading, so that each question is in its own tab. Review the RMarkdown 2
assignment if you need a refresher on how to do this.
For all calculations, make sure you show your code.
- Q1 (2 pts.): Interpret, in plain English, the slope
coefficient for model 1. Make sure your answer is in terms of units of
change in the predictor and the response.
- Q2 (1 pt.): Using your model 1, predict the bill
length of a penguin that weighs 3500 grams. Make sure you show your
code.
- Q3 (1 pt.): What is the base case for your
model 2?
- Q4 (3 pts.): Using model 2, what are the expected
bill lengths for each of the three penguin species?
- Q5 (1 pt.): What is the base case for model 3?
- Q6 (1 pt.): Using model 3, calculate the predicted
bill lengths for: 1: male Adelie penguins 2: female Gentoo penguins
- Q7 (1 pt.): What is the base case for model 4?
- Q8 (1 pt.): Using model 4, calculate the predicted
bill lengths for:
- male Adelie penguins
- female Gentoo penguins
- Q9 (1 pt.): Speculate on why your predictions were
different for model 3 and model 4. For a hint, check out this
slide deck. Specifically look at slides 24 through 33.
- Q10 (1 pt.): What is the base case for model 5, and
how is it different from the base case for model 4?
- Q11 (2 pts.): Conveniently, we could get the
expected bill length of a female Adelie penguin directly from the
intercept term in model 4. Why can’t we do the same thing using the
intercept term from model 5?
- Q12 (1 pt.): Using model 5, what is the expected
bill length of:
- male Adelie penguins that weigh 4000 grams
- female Gentoo penguins that weigh 4800 grams
Answer Key
- Q1: The slope coefficient, 0.0041 indicates that for each gram
increase in body mass, the expected bill length increases by 0.0041
mm.
- Q2: The expected bill length is 41.08 mm.
- Q3: Base case is species Adelie
- Q4: Predicted values are: 38.8, 48.8, 47.5
- Q5: Base case is female Adelie penguins
- Q6: Predicted values are 40.7, 45.7
- Q7: Base case is female Adelie penguins
- Q8: Predicted values are 40.4, 45.6
- Q9: Any answer (we didn’t talk about this in class).
- Q10: Base case is female Adelie penguins that weigh 0 grams, it’s
different from the others because it includes body mass.
- Q11: Because of the body mass term, we have to specify a body mass
as well.
- Q12: Predicted values are: 40.6, 45.8