Interactions

Supervised Learning in R: Regression

Nina Zumel and John Mount

Win-Vector, LLC

Additive relationships

Example of an additive relationship:

plant_height ~ bacteria + sun
  • Change in height is the sum of the effects of bacteria and sunlight
    • Change in sunlight causes same change in height, independent of bacteria
    • Change in bacteria causes same change in height, independent of sunlight
Supervised Learning in R: Regression

What is an Interaction?

The simultaneous influence of two variables on the outcome is not additive.

plant_height ~ bacteria + sun + bacteria:sun
  • Change in height is more (or less) than the sum of the effects due to sun/bacteria
  • At higher levels of sunlight, 1 unit change in bacteria causes more change in height
Supervised Learning in R: Regression

What is an Interaction?

The simultaneous influence of two variables on the outcome is not additive.

plant_height ~ bacteria + sun + bacteria:sun
  • sun: categorical {"sun", "shade"}
  • In sun, 1 unit change in bacteria causes m units change in height
  • In shade, 1 unit change in bacteria causes n units change in height

Like two separate models: one for sun, one for shade.

Supervised Learning in R: Regression

Example of no Interaction: Soybean Yield

yield ~ Stress + SO2 + O3

Supervised Learning in R: Regression

Example of an Interaction: Alcohol Metabolism

Metabol ~ Gastric + Sex

Supervised Learning in R: Regression

Expressing Interactions in Formulae

  • Interaction - Colon (:)

    y ~ a:b
    
  • Main effects and interaction - Asterisk (*)

    y ~ a*b
    # Both mean the same
    y ~ a + b + a:b
    
  • Expressing the product of two variables - I

    y ~ I(a*b)
    

    same as $y \propto a b$

Supervised Learning in R: Regression

Finding the Correct Interaction Pattern

Formula RMSE (cross validation)
Metabol ~ Gastric + Sex 1.46
Metabol ~ Gastric * Sex 1.48
Metabol ~ Gastric + Gastric:Sex 1.39
Supervised Learning in R: Regression

Let's practice!

Supervised Learning in R: Regression

Preparing Video For Download...