Processing math: 73%
+ - 0:00:00
Notes for current slide
Notes for next slide

When The Effect of One Predictor Depends on Another

1 / 58

The world isn't additive

  • Until now, we have assumed predictors combine additively
    • the effect of one is not dependent on the effect of the other
2 / 58

The world isn't additive

  • Until now, we have assumed predictors combine additively
    • the effect of one is not dependent on the effect of the other
  • BUT - what if the effect of one variable depends on the level of another?
2 / 58

The world isn't additive

  • Until now, we have assumed predictors combine additively
    • the effect of one is not dependent on the effect of the other
  • BUT - what if the effect of one variable depends on the level of another?

  • This is an INTERACTION and is quite common

    • Heck, a squared term is the interaction of a variable with itself!
2 / 58

The world isn't additive

  • Until now, we have assumed predictors combine additively
    • the effect of one is not dependent on the effect of the other
  • BUT - what if the effect of one variable depends on the level of another?

  • This is an INTERACTION and is quite common

    • Heck, a squared term is the interaction of a variable with itself!
  • Biology: The science of "It depends..."
2 / 58

The world isn't additive

  • Until now, we have assumed predictors combine additively
    • the effect of one is not dependent on the effect of the other
  • BUT - what if the effect of one variable depends on the level of another?

  • This is an INTERACTION and is quite common

    • Heck, a squared term is the interaction of a variable with itself!
  • Biology: The science of "It depends..."

  • This is challenging to think about and visualize, but if you can master it, you will go far!

2 / 58

We Have Explored Nonliearities Via Transforming our Response

3 / 58

But We Have Also Always Tested for Non-Additivity of Predictors

4 / 58

The Linear Model Can Accomodate Many Flavors of Nonlinearity

^yi=β0+β1x1i+β2x2i yiN(^yi,σ)

5 / 58

The Linear Model Can Accomodate Many Flavors of Nonlinearity

^yi=β0+β1x1i+β2x2i yiN(^yi,σ)Could become...

^yi=β0+β1x1i+β2x21i

5 / 58

The Linear Model Can Accomodate Many Flavors of Nonlinearity

^yi=β0+β1x1i+β2x2i yiN(^yi,σ)Could become...

^yi=β0+β1x1i+β2x21iCould be...

^yi=β0+β1x1i+β2x2i+β3x1ix2i

5 / 58

The Linear Model Can Accomodate Many Flavors of Nonlinearity

^yi=β0+β1x1i+β2x2i yiN(^yi,σ)Could become...

^yi=β0+β1x1i+β2x21iCould be...

^yi=β0+β1x1i+β2x2i+β3x1ix2iIt is ALL additive terms

5 / 58

6 / 58

A Non-Additive World

  1. Replicating Categorical Variable Combinations: Factorial Models

  2. Evaluating Interaction Effects

  3. How to Look at Means and Differences with an Interaction Effect

  4. Continuous Variables and Interaction Effects

7 / 58

Intertidal Grazing!

image

Do grazers reduce algal cover in the intertidal?

8 / 58

Experiment Replicated on Two Ends of a gradient

image

9 / 58

Factorial Experiment

image

10 / 58

Factorial Design

image

Note: You can have as many treatment types or observed category combinations as you want (and then 3-way, 4-way, etc. interactions)

11 / 58

The Data: See the dependency of one treatment on another?

12 / 58

If we had fit y ~ a + b, residuals look weird

13 / 58

A Factorial Model

yijk=β0+βixi+βjxj+βijxij+ϵijk

ϵijkN(0,σ2) xi=0,1,xj=0,1,xij=0,1

14 / 58

A Factorial Model

yijk=β0+βixi+βjxj+βijxij+ϵijk

ϵijkN(0,σ2) xi=0,1,xj=0,1,xij=0,1

  • Note the new last term
14 / 58

A Factorial Model

yijk=β0+βixi+βjxj+βijxij+ϵijk

ϵijkN(0,σ2) xi=0,1,xj=0,1,xij=0,1

  • Note the new last term

  • Deviation due to combination of categories i and j

14 / 58

A Factorial Model

yijk=β0+βixi+βjxj+βijxij+ϵijk

ϵijkN(0,σ2) xi=0,1,xj=0,1,xij=0,1

  • Note the new last term

  • Deviation due to combination of categories i and j


This is still something that is in

\Large \boldsymbol{Y} = \boldsymbol{\beta X} + \boldsymbol{\epsilon}

14 / 58

The Data (Four Rows)

height herbivores sqrtarea
low minus 9.4055728
low plus 11.9767608
mid minus 0.7071068
mid plus 0.7071068
15 / 58

The Dummy-Coded Treatment Contrasts

(Intercept) heightmid herbivoresplus heightmid:herbivoresplus
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 1
16 / 58

Fitting with Least Squares

graze_int <- lm(sqrtarea ~ height + herbivores +
height:herbivores,
data=algae)
## OR
graze_int <- lm(sqrtarea ~ height*herbivores,
data=algae)
17 / 58

Now We Are Linear/Additive

18 / 58

Residuals A-OK

19 / 58

HOV Good!

20 / 58

No Outliers

21 / 58

Collinearity is Tricky - unimportant for interaction

22 / 58

A Non-Additive World

  1. Replicating Categorical Variable Combinations: Factorial Models

  2. Evaluating Interaction Effects

  3. How to Look at Means and Differences with an Interaction Effect

  4. Continuous Variables and Interaction Effects

23 / 58

What do the Coefficients Mean?

term estimate std.error
(Intercept) 32.91450 3.855532
heightmid -10.43090 5.452546
herbivoresplus -22.51075 5.452546
heightmid:herbivoresplus 25.57809 7.711064
24 / 58

What do the Coefficients Mean?

term estimate std.error
(Intercept) 32.91450 3.855532
heightmid -10.43090 5.452546
herbivoresplus -22.51075 5.452546
heightmid:herbivoresplus 25.57809 7.711064
  • Intercept chosen as basal condition (low, herbivores -)
24 / 58

What do the Coefficients Mean?

term estimate std.error
(Intercept) 32.91450 3.855532
heightmid -10.43090 5.452546
herbivoresplus -22.51075 5.452546
heightmid:herbivoresplus 25.57809 7.711064
  • Intercept chosen as basal condition (low, herbivores -)

  • Changing height to mid is associated with a loss of 10 units of algae relative to low/-

24 / 58

What do the Coefficients Mean?

term estimate std.error
(Intercept) 32.91450 3.855532
heightmid -10.43090 5.452546
herbivoresplus -22.51075 5.452546
heightmid:herbivoresplus 25.57809 7.711064
  • Intercept chosen as basal condition (low, herbivores -)

  • Changing height to mid is associated with a loss of 10 units of algae relative to low/-

  • Adding herbivores is associated with a loss of 22 units of algae relative to low/-
24 / 58

What do the Coefficients Mean?

term estimate std.error
(Intercept) 32.91450 3.855532
heightmid -10.43090 5.452546
herbivoresplus -22.51075 5.452546
heightmid:herbivoresplus 25.57809 7.711064
  • Intercept chosen as basal condition (low, herbivores -)

  • Changing height to mid is associated with a loss of 10 units of algae relative to low/-

  • Adding herbivores is associated with a loss of 22 units of algae relative to low/-

  • BUT - if you add herbivores and mid, that's also associated with an additional increase of 25 units of algae relative to mid and + alone

    • 25.5 - 22.5 - 10.4 = only a loss of 7.4 relative to low/-
24 / 58

What do the Coefficients Mean?

term estimate std.error
(Intercept) 32.91450 3.855532
heightmid -10.43090 5.452546
herbivoresplus -22.51075 5.452546
heightmid:herbivoresplus 25.57809 7.711064



NEVER TRY AND INTERPRET ADDITIVE EFFECTS ALONE WHEN AN INTERACTION IS PRESENT
that way lies madness

25 / 58

This view is intuitive

26 / 58

This view is also intuitive

27 / 58

We Can Still Look at R^2

# R2 for Linear Regression
R2: 0.228
adj. R2: 0.190

Eh, not great, not bad...

28 / 58

We Can Still Look at R^2

# R2 for Linear Regression
R2: 0.228
adj. R2: 0.190

Eh, not great, not bad...

  • Note: adding more interaction effects will always increase the R2 so only add if warranted - NO FISHING!
28 / 58

A Non-Additive World

  1. Replicating Categorical Variable Combinations: Factorial Models

  2. Evaluating Interaction Effects

  3. How to Look at Means and Differences with an Interaction Effect

  4. Continuous Variables and Interaction Effects

29 / 58

Posthoc Estimated Means and Interactions with Categorical Variables

  • Must look at simple effects first in the presence of an interaction
    • The effects of individual treatment combinations
    • If you have an interaction, this is what you do!
30 / 58

Posthoc Estimated Means and Interactions with Categorical Variables

  • Must look at simple effects first in the presence of an interaction
    • The effects of individual treatment combinations
    • If you have an interaction, this is what you do!
  • Main effects describe effects of one variable in the absence of an interaction
    • Useful only if there is no interaction
    • Or useful if one categorical variable can be absent
30 / 58

Estimated Means with No Interaction - Misleading!

herbivores emmean SE df lower.CL upper.CL
minus 27.7 2.73 60 22.2 33.2
plus 18.0 2.73 60 12.5 23.4
Results are averaged over the levels of: height
Confidence level used: 0.95
height emmean SE df lower.CL upper.CL
low 21.7 2.73 60 16.2 27.1
mid 24.0 2.73 60 18.6 29.5
Results are averaged over the levels of: herbivores
Confidence level used: 0.95
31 / 58

Posthoc Comparisons Averaging Over Blocks - Misleading!

contrast estimate SE df lower.CL upper.CL
minus - plus 9.72 3.86 60 2.01 17.4
Results are averaged over the levels of: height
Confidence level used: 0.95
32 / 58

Simple Effects Means

height herbivores emmean SE df lower.CL upper.CL
low minus 32.9 3.86 60 25.20 40.6
mid minus 22.5 3.86 60 14.77 30.2
low plus 10.4 3.86 60 2.69 18.1
mid plus 25.6 3.86 60 17.84 33.3
Confidence level used: 0.95
33 / 58

Posthoc with Simple Effects

contrast estimate SE df t.ratio p.value
low minus - mid minus 10.430905 5.452546 60 1.913034 0.0605194
low minus - low plus 22.510748 5.452546 60 4.128484 0.0001146
low minus - mid plus 7.363559 5.452546 60 1.350481 0.1819337
mid minus - low plus 12.079843 5.452546 60 2.215450 0.0305355
mid minus - mid plus -3.067346 5.452546 60 -0.562553 0.5758352
low plus - mid plus -15.147189 5.452546 60 -2.778003 0.0072896
34 / 58

Posthoc with Simple Effects

contrast estimate SE df t.ratio p.value
low minus - mid minus 10.430905 5.452546 60 1.913034 0.0605194
low minus - low plus 22.510748 5.452546 60 4.128484 0.0001146
low minus - mid plus 7.363559 5.452546 60 1.350481 0.1819337
mid minus - low plus 12.079843 5.452546 60 2.215450 0.0305355
mid minus - mid plus -3.067346 5.452546 60 -0.562553 0.5758352
low plus - mid plus -15.147189 5.452546 60 -2.778003 0.0072896
That's a Lot to Drink In!
34 / 58

Might be easier visually

35 / 58

We are often interested in looking at differences within levels...

height = low:
herbivores emmean SE df lower.CL upper.CL
minus 32.9 3.86 60 25.20 40.6
plus 10.4 3.86 60 2.69 18.1
height = mid:
herbivores emmean SE df lower.CL upper.CL
minus 22.5 3.86 60 14.77 30.2
plus 25.6 3.86 60 17.84 33.3
Confidence level used: 0.95
36 / 58

We Can Then Look at Something Simpler...

37 / 58

Why think about interactions?

  • It Depends is a rule in biology
38 / 58

Why think about interactions?

  • It Depends is a rule in biology

  • Context dependent interactions everywhere

38 / 58

Why think about interactions?

  • It Depends is a rule in biology

  • Context dependent interactions everywhere

  • Using categorical predictors in a factorial design is an elegant way to see interactions without worrying about shapes of relationships

38 / 58

Why think about interactions?

  • It Depends is a rule in biology

  • Context dependent interactions everywhere

  • Using categorical predictors in a factorial design is an elegant way to see interactions without worrying about shapes of relationships

  • BUT - it all comes down to a general linear model! And the same inferential frameworks we have been dealing with since linear regression!

38 / 58

To Blow Your Mind - You can have 2, 3, and more-way interactions!

image

39 / 58

A Non-Additive World

  1. Replicating Categorical Variable Combinations: Factorial Models

  2. Evaluating Interaction Effects

  3. How to Look at Means and Differences with an Interaction Effect.

  4. Continuous Variables and Interaction Effects

40 / 58

Problem: What if Continuous Predictors are Not Additive?

Problem: What if Continuous Predictors are Not Additive?

Problem: What if Continuous Predictors are Not Additive?

41 / 58

42 / 58

Model For Age Interacting with Elevation to Influence Fire Severity

y_i = \beta_0 + \beta_{1}x_{1i} + \beta_{2}x_{2i}+ \beta_{3}x_{1i}x_{2i} + \epsilon_{i}

\epsilon_{i} \sim \mathcal{N}(0,\sigma^2)

Or in code:

keeley_lm_int <- lm(firesev ~ age * elev, data=keeley)
43 / 58

Assumption Tests as Usual!

44 / 58

Examine Residuals With Respect to Each Predictor

45 / 58

Interactions, VIF, and Centering

# Check for Multicollinearity
Low Correlation
Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
age 3.20 [2.37, 4.52] 1.79 0.31 [0.22, 0.42]
Moderate Correlation
Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
elev 5.52 [3.95, 7.92] 2.35 0.18 [0.13, 0.25]
age:elev 8.29 [5.83, 11.98] 2.88 0.12 [0.08, 0.17]
  • Collinearities between additive predictors and interaction effects are not problematic.
46 / 58

Interactions, VIF, and Centering

# Check for Multicollinearity
Low Correlation
Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
age 3.20 [2.37, 4.52] 1.79 0.31 [0.22, 0.42]
Moderate Correlation
Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
elev 5.52 [3.95, 7.92] 2.35 0.18 [0.13, 0.25]
age:elev 8.29 [5.83, 11.98] 2.88 0.12 [0.08, 0.17]
  • Collinearities between additive predictors and interaction effects are not problematic.

  • However, you should make sure your ADDITIVE predictors do not have VIF problems in a model with no interactions.

46 / 58

Interactions, VIF, and Centering

# Check for Multicollinearity
Low Correlation
Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
age 3.20 [2.37, 4.52] 1.79 0.31 [0.22, 0.42]
Moderate Correlation
Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
elev 5.52 [3.95, 7.92] 2.35 0.18 [0.13, 0.25]
age:elev 8.29 [5.83, 11.98] 2.88 0.12 [0.08, 0.17]
  • Collinearities between additive predictors and interaction effects are not problematic.

  • However, you should make sure your ADDITIVE predictors do not have VIF problems in a model with no interactions.

  • If you are worried, center your predictors - i.e., X_i - mean(X)
    • This can fix issues with models not converging
46 / 58

Interpretation of Centered Coefficients

\huge X_i - \bar{X}

47 / 58

Interpretation of Centered Coefficients

\huge X_i - \bar{X}

  • Additive coefficients are the effect of a predictor at the mean value of the other predictors
47 / 58

Interpretation of Centered Coefficients

\huge X_i - \bar{X}

  • Additive coefficients are the effect of a predictor at the mean value of the other predictors

  • Intercepts are at the mean value of all predictors

47 / 58

Interpretation of Centered Coefficients

\huge X_i - \bar{X}

  • Additive coefficients are the effect of a predictor at the mean value of the other predictors

  • Intercepts are at the mean value of all predictors

  • Visualization will keep you from getting confused!

47 / 58

Interactions, VIF, and Centering

y = \beta_0 + \beta_{1}(x_{1}-\bar{x_{1}}) + \beta_{2}(x_{2}-\bar{x_{2}})+ \beta_{3}(x_{1}-\bar{x_{1}})(x_{2}-\bar{x_{2}})

Variance Inflation Factors for Centered Model:

# Check for Multicollinearity
Low Correlation
Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
age_c 1.02 [1.00, 2376.13] 1.01 0.98 [0.00, 1.00]
elev_c 1.04 [1.00, 7.04] 1.02 0.96 [0.14, 1.00]
age_c:elev_c 1.04 [1.00, 9.78] 1.02 0.96 [0.10, 1.00]
48 / 58

Coefficients!

term estimate std.error statistic p.value
(Intercept) 1.8132153 0.6156070 2.945411 0.0041484
age 0.1206292 0.0208618 5.782298 0.0000001
elev 0.0030852 0.0013329 2.314588 0.0230186
age:elev -0.0001472 0.0000431 -3.416029 0.0009722

R2 = 0.3235187.

Note that additive coefficients signify the effect of one predictor in the abscence of all others.

49 / 58

Centered Coefficients!

term estimate std.error statistic p.value
(Intercept) 4.6091266 0.1463029 31.503991 0.0000000
age_c 0.0581123 0.0117591 4.941901 0.0000038
elev_c -0.0006786 0.0005792 -1.171587 0.2445985
age_c:elev_c -0.0001472 0.0000431 -3.416029 0.0009722

R2 = 0.3235187

Note that additive coefficients signify the effect of one predictor at the average level of all others.

50 / 58

Interpretation

  • What the heck does a continuous interaction effect mean?
51 / 58

Interpretation

  • What the heck does a continuous interaction effect mean?

  • We can look at the effect of one variable at different levels of the other

51 / 58

Interpretation

  • What the heck does a continuous interaction effect mean?

  • We can look at the effect of one variable at different levels of the other

  • We can look at a surface

51 / 58

Interpretation

  • What the heck does a continuous interaction effect mean?

  • We can look at the effect of one variable at different levels of the other

  • We can look at a surface

  • We can construct counterfactual plots showing how changing both variables influences our outcome

51 / 58

Age at Different Levels of Elevation

52 / 58

Elevation at Different Levels of Age

53 / 58

Or all in one plot

54 / 58

Without Data and Including CIs

55 / 58

A Heatmap Approach

56 / 58

Surfaces and Other 3d Objects

57 / 58

58 / 58

The world isn't additive

  • Until now, we have assumed predictors combine additively
    • the effect of one is not dependent on the effect of the other
2 / 58
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow