2024-02-01

Back to ANCOVA

When the lines aren’t parallel…

Interactions between continuous and categorical (factor) EVs are much easier to understand (to my mind, anyway)

Earlier ANCOVAs

Recall: LMs that combine a continuous EV and a factor amount to fitting two or more regression lines (one for each factor level)

In the previous models, we had assumed that the regression lines are parallel:

  • they differed in intercept (one per factor level), but
  • they had a common slope — there was only one slope parameter in the model.

Relaxing this assumption (allowing for different slopes) = interaction

Example: back to the bugs

Does effect of day depend on lactose (and vice versa)?
Do they grow faster (steeper slope) with lactose?

Fit model with interaction

# m <- lm(bacteria ~ lactose + day + lactose:day, data = Bugs)

m <- lm(bacteria ~ lactose * day, data = Bugs)  # shorthand for above
a <- anova(m)
Df Sum Sq Mean Sq F value Pr(>F)
lactose 1 397.0 397.000 572.0 0.00e+00
day 1 298.0 298.000 430.0 0.00e+00
lactose:day 1 27.7 27.700 39.9 1.02e-05
Residuals 16 11.1 0.694

Clearly yes: \(P = 1.02\times 10^{-5}\) that growth rates (slopes) differ!

Without interaction lactose:day

m <- lm(bacteria ~ lactose + day,
        data = Bugs)
cf <- coef(m)
cf
## (Intercept)    lactose1         day 
##     3.09390    -4.45575     2.72935

Common slope cf["day"] \(=2.73\)
Fits neither with lactose nor without:

  • w/o lactose: slope too steep;
  • w/ lactose: slope too shallow.

With interaction lactose:day

m <- lm(bacteria ~ lactose * day,
        data = Bugs)

cf <- coef(m)
cf[1:3]  # first three coefs
## (Intercept)    lactose1         day 
##     3.09390    -1.95930     2.72935
cf[4]    # coef for interaction!
## lactose1:day 
##     -0.83215

Understanding ‘interaction coefficients’

What is the lactose1:day coefficient?

  • deviation of the slope in 1st (w/o-lactose) group from dotted line
  • dotted line = mean of the two slopes
  • deviation of 2nd (w/ lactose) group is
    -lactose1:day

Thus:

  • slope w/o lactose: \(1.9\)
    cf["day"] + cf["lactose1:day"]
  • slope w/ lactose: \(3.56\)
    cf["day"] - cf["lactose1:day"]