Interactions between continuous and categorical (factor) EVs are much easier to understand (to my mind, anyway)
2024-02-01
Interactions between continuous and categorical (factor) EVs are much easier to understand (to my mind, anyway)
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:
Relaxing this assumption (allowing for different slopes) =
Does effect of day depend on lactose (and vice versa)?
# 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!
lactose:daym <- 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:
lactose:daym <- 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
What is the lactose1:day coefficient?
-lactose1:dayThus:
cf["day"] + cf["lactose1:day"]cf["day"] - cf["lactose1:day"]