8  Moderated Regression

8.1 Interactions in Linear Models

Does the relation between one predictor and the outcome depend on the value of another predictor?

8.1.1 Runner’s Data

  • Time - 5-kilometer race time in minutes
  • Age - runners age in years
  • Miles - typical miles run per week training for 5-kilometer race
runners <- read.csv("data/runners.csv", 
                    header = TRUE)
headTail(runners) # from psych package
     Time Age Miles
1   24.91  29    10
2   21.82  25    20
3   21.54  27    40
4   23.03  25    50
...   ... ...   ...
77  21.51  42    40
78  34.53  58    10
79  23.68  56    30
80   23.5  53    50

8.1.2 Explore Univariae Distributions of the Variables

hist(runners$Time)

hist(runners$Age)

hist(runners$Miles)

describe(runners, fast = TRUE)
      vars  n  mean    sd   min   max range   se
Time     1 80 23.55  5.29 14.87 37.75 22.88 0.59
Age      2 80 39.66 11.56 20.00 59.00 39.00 1.29
Miles    3 80 29.88 13.82 10.00 50.00 40.00 1.55

8.1.3 Visualize the Bivariate Relations Between Variables

plot(Time ~ Age, runners)
abline(reg = lm(Time ~ Age, runners), 
       col = "red")

plot(Time ~ Miles, runners)
abline(reg = lm(Time ~ Miles, runners), 
       col = "red")

8.1.4 Quantifying Bivariate Relations

plot(Age ~ Miles, runners)
abline(reg = lm(Age ~ Miles, runners), col = "red")

print(cor(runners), digits = 2)
       Time   Age Miles
Time   1.00  0.47 -0.73
Age    0.47  1.00 -0.16
Miles -0.73 -0.16  1.00

8.1.5 Multiple Regression: Additive Model

additivemod <- lm(Time ~ Age + Miles, data = runners)
summary(additivemod)

Call:
lm(formula = Time ~ Age + Miles, data = runners)

Residuals:
    Min      1Q  Median      3Q     Max 
-6.7507 -2.3133  0.0271  2.2358  7.1882 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 24.60519    1.57309  15.641  < 2e-16 ***
Age          0.16724    0.03059   5.468 5.43e-07 ***
Miles       -0.25728    0.02558 -10.057 1.13e-15 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.103 on 77 degrees of freedom
Multiple R-squared:  0.6648,    Adjusted R-squared:  0.6561 
F-statistic: 76.35 on 2 and 77 DF,  p-value: < 2.2e-16

8.1.6 Centering Predictors

runners$Age40 <- runners$Age - 40
runners$Miles30 <- runners$Miles - 30

8.1.6.1 Multiple Regression: Additive Model (Centered)

centaddmod <- lm(Time ~ Age40 + Miles30, data = runners)
summary(centaddmod)

Call:
lm(formula = Time ~ Age40 + Miles30, data = runners)

Residuals:
    Min      1Q  Median      3Q     Max 
-6.7507 -2.3133  0.0271  2.2358  7.1882 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 23.57653    0.34706  67.932  < 2e-16 ***
Age40        0.16724    0.03059   5.468 5.43e-07 ***
Miles30     -0.25728    0.02558 -10.057 1.13e-15 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.103 on 77 degrees of freedom
Multiple R-squared:  0.6648,    Adjusted R-squared:  0.6561 
F-statistic: 76.35 on 2 and 77 DF,  p-value: < 2.2e-16

8.1.6.2 Does the Effect of Training Miles Depend on Runner’s Age?

interactionmod <- lm(Time ~ Age + Miles + Age:Miles, data = runners)
summary(interactionmod)

Call:
lm(formula = Time ~ Age + Miles + Age:Miles, data = runners)

Residuals:
    Min      1Q  Median      3Q     Max 
-6.6046 -1.8405 -0.0875  1.9707  6.2404 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 18.899198   3.036308   6.224 2.44e-08 ***
Age          0.308398   0.071342   4.323 4.61e-05 ***
Miles       -0.068653   0.090112  -0.762   0.4485    
Age:Miles   -0.004767   0.002188  -2.179   0.0325 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.03 on 76 degrees of freedom
Multiple R-squared:  0.6845,    Adjusted R-squared:  0.672 
F-statistic: 54.96 on 3 and 76 DF,  p-value: < 2.2e-16

8.1.7 Model Comparison

anova(centaddmod, interactionmod)
Analysis of Variance Table

Model 1: Time ~ Age40 + Miles30
Model 2: Time ~ Age + Miles + Age:Miles
  Res.Df    RSS Df Sum of Sq      F  Pr(>F)  
1     77 741.20                              
2     76 697.63  1     43.57 4.7465 0.03246 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

8.1.8 Plotting the Interaction Model Predicted Values

plot(
  predictorEffects(mod = interactionmod,
                   predictors = ~ Age, 
                   xlevels = list(Miles = c(10, 30, 50))),
  ylim = c(10, 40),
  lines = list(multiline = TRUE)
)

8.1.9 Interpreting Coefficients in Models with Interactions

8.1.9.1 Additive Model

  • The coefficient is the expected change in the outcome (Y) for a one unit change in this predictor (X1) holding the other predictor (X2) constant
  • This effect of X1 is the same no matter what the value of X2

8.1.9.2 Moderation Model (with Interaction)

  • For variables included in the interaction term, the coefficient is interpreted as the effect of a one unit change in that predictor (X1) on the outcome (Y) when the other predictor in the interaction (X2) is zero.

  • The size of the effect of X1 on Y changes depending on the value of X2.

8.1.9.3 Let’s use the centered variables

cintmod <- lm(Time ~ Age40 + Miles30 + Age40:Miles30, 
              data = runners)
summary(cintmod)

Call:
lm(formula = Time ~ Age40 + Miles30 + Age40:Miles30, data = runners)

Residuals:
    Min      1Q  Median      3Q     Max 
-6.6046 -1.8405 -0.0875  1.9707  6.2404 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)   23.454674   0.343498  68.282  < 2e-16 ***
Age40          0.165377   0.029880   5.535 4.26e-07 ***
Miles30       -0.259348   0.025001 -10.374 3.27e-16 ***
Age40:Miles30 -0.004767   0.002188  -2.179   0.0325 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.03 on 76 degrees of freedom
Multiple R-squared:  0.6845,    Adjusted R-squared:  0.672 
F-statistic: 54.96 on 3 and 76 DF,  p-value: < 2.2e-16
Statistical models
  additive centered additive. moderation center moderation
(Intercept) 24.605*** 23.577*** 18.899*** 23.455***
  (1.573) (0.347) (3.036) (0.343)
Age 0.167***   0.308***  
  (0.031)   (0.071)  
Miles -0.257***   -0.069  
  (0.026)   (0.090)  
Age40   0.167***   0.165***
    (0.031)   (0.030)
Miles30   -0.257***   -0.259***
    (0.026)   (0.025)
Age:Miles     -0.005*  
      (0.002)  
Age40:Miles30       -0.005*
        (0.002)
R2 0.665 0.665 0.684 0.684
Adj. R2 0.656 0.656 0.672 0.672
Num. obs. 80 80 80 80
***p < 0.001; **p < 0.01; *p < 0.05