library(tidyverse)
library(tidymodels)

Bulletin

Today

Today we review and practice linear modeling concepts with the Palmer penguins data.

data(penguins)

Use ?penguins or click here for more info about the dataset.

Main vs interaction effects

y: body mass (g)

x1: bill length

x2: island Dream

x3: island Torgersen

ˆy=^β0+^β1x1+^β2x2+^β3x3

Bill length only impacts body mass via the term β1x1. x2 and x3 can be thought of as turning on or off a constant.

Main

ABCDEFGHIJ0123456789
term
<chr>
estimate
<dbl>
std.error
<dbl>
statistic
<dbl>
p.value
<dbl>
(Intercept)1225.79107243.1805925.0406627.576684e-07
bill_length_mm77.119335.30697814.5316831.656434e-37
islandDream-919.0744858.622251-15.6779125.151598e-42
islandTorgersen-523.2920185.549545-6.1168302.638570e-09

Interaction

ˆy=^β0+^β1x1+^β2x2+^β3x3+^β4x1x2+^β5x1x3

What’s different? The interaction terms (β4x1x2 and β5x1x3).

ABCDEFGHIJ0123456789
term
<chr>
estimate
<dbl>
std.error
<dbl>
statistic
<dbl>
p.value
<dbl>
(Intercept)-1726.02014292.078750-5.9094348.425393e-09
bill_length_mm142.341946.41833322.1774019.138892e-68
islandDream4478.69269395.30733411.3296472.030517e-25
islandTorgersen2870.56340777.6850753.6911642.603717e-04
bill_length_mm:islandDream-120.601398.770689-13.7505051.930223e-34
bill_length_mm:islandTorgersen-76.5713419.534154-3.9198701.073890e-04

Interpreting interactions can be difficult, especially without writing things down. To make it easier, we will compare the implied linear models:

Plug in 0 for islandDream (x2) and 0 for islandTorgersen (x3) to get the linear model for islandBiscoe penguins

Plug in 1 for islandDream (x2) and 0 for islandTorgersen (x3) to get the linear model for islandDream penguins

Plug in 0 for islandDream (x2) and 1 for islandTorgersen (x3) to get the linear model for islandTorgersen penguins

  • Biscoe fitted model:

ˆy=1726.0+142.3x1

  • Dream fitted model:

ˆy=1726.0+142.3x1+4478.7120.6x1

Combine terms:

ˆy=2752.7+21.7x1

Exercise 1

Write out the fitted model for Torgersen island below.

  • Torgersen model: ˆy=[write here]

Interpreting

Now we can interpret the interaction model by comparing bill length slopes between islands.

Exercise 2

  • You measured the bill length of a penguin from island Biscoe and a penguin from island Torgersen a year ago. You re-measure them today and find the bill length of each one grew by exactly 2 mm. How much mass do you expect each penguin to have gained?

Exercise 3

Are the intercepts meaningful?

Practice

Exercise 4

Is the relationship between Body mass (g) and Bill depth (mm) positive or negative? Create a convincing argument from the data.

Exercise 5

Let’s build a linear model of body mass using bill depth and one other predictor of your choosing (hint: see previous exercise!)

  • Write out a linear model with both predictors and fit the model.

  • Fit the linear model

  • Are any of the predictors insignificant at the α=0.05 level? If so, state the null and alternative hypothesis, p-value and conclusion in context.

  • Do you prefer this model to the interaction effects model from above? Why?