Tutorials › Generalized Linear Models › Factor-by-Continuous Interactions and Conditional Slopes

Factors Contrasts and Interactions · Tutorial 149 of 981

Factor-by-Continuous Interactions and Conditional Slopes

Derive and interpret conditional slopes in factor-by-continuous GLMs, then distinguish linear-predictor slopes from changes in the mean response.

Intermediate 10 min read

What You'll Learn

  • Write a reference-coded GLM linear predictor with factor-by-continuous product terms
  • Derive the continuous-predictor slope at each factor level
  • Interpret each interaction coefficient as a difference in linear-predictor slopes
  • Distinguish linear-predictor slopes from response-mean derivatives
  • Work through identity, log, and logit link examples
  • Recognize common misinterpretations of interaction coefficients

Why Conditional Slopes Matter

A continuous predictor need not have the same relationship with the outcome in every group. For example, an additional year of age might be associated with one change in a health outcome among one treatment group and a different change among another. A factor-by-continuous interaction represents this possibility by allowing the continuous predictor’s slope on the GLM linear-predictor scale to vary across factor levels.

The key interpretation is precise: under reference coding, the coefficient of a factor-by-continuous product term is the difference between that factor level’s linear-predictor slope and the reference level’s slope. It is not generally a difference in response means, probabilities, or rates. Those response-scale quantities also depend on the link function and the current predictor value.

Model and Conditional Slopes

Let a factor have \(L\) levels, labelled \(0,1,\ldots,L-1\), and let \(x\) be a continuous predictor. Use level \(0\) as the reference level. For an observation at level \(j\), let \(z_j=1\) if the observation is at level \(j\), and \(z_j=0\) otherwise, for \(j=1,\ldots,L-1\). With a factor-by-continuous interaction, the linear predictor is

$$ \eta = g(\mu) = \beta_0+\beta_x x +\sum_{j=1}^{L-1}\alpha_j z_j +\sum_{j=1}^{L-1}\gamma_j z_j x. $$

Here \(g\) is the link function, \(\mu=E[Y\mid x,\text{factor level}]\) is the conditional mean, \(\beta_0\) is the reference-level intercept on the linear-predictor scale, and \(\beta_x\) is the reference-level slope on that scale. The coefficient \(\alpha_j\) shifts the linear predictor for level \(j\), while \(\gamma_j\) allows its slope to differ from the reference level’s slope.

Definition: The conditional slope for a factor level is the derivative of the linear predictor \(\eta=g(\mu)\) with respect to the continuous predictor \(x\), holding the factor level fixed. With reference coding, the reference-level slope is \(\beta_x\), and the slope at level \(j\) is \(\beta_x+\gamma_j\).

The conditional intercept at level \(j\) is \(\beta_0+\alpha_j\), and its linear predictor can therefore be written as \((\beta_0+\alpha_j)+(\beta_x+\gamma_j)x\). At the reference level, all the indicators are zero, so the linear predictor is \(\beta_0+\beta_x x\). This makes clear that \(\alpha_j\) changes the level-specific intercept, whereas \(\gamma_j\) changes the slope.

Theorem: In the reference-coded model above, the difference between the linear-predictor slope at factor level \(j\) and the slope at the reference level is \(\gamma_j\). The difference between the slopes at levels \(j\) and \(k\), for two nonreference levels, is \(\gamma_j-\gamma_k\).

Proof. Fix a factor level. At the reference level, every \(z_j=0\), so \(\eta=\beta_0+\beta_x x\). Differentiating with respect to \(x\) gives slope \(\beta_x\). At nonreference level \(j\), \(z_j=1\) and all other indicators are zero. Thus \(\eta=(\beta_0+\alpha_j)+(\beta_x+\gamma_j)x\), whose derivative with respect to \(x\) is \(\beta_x+\gamma_j\). Subtracting the reference slope gives \((\beta_x+\gamma_j)-\beta_x=\gamma_j\). Subtracting the slope at level \(k\) from the slope at level \(j\) gives \((\beta_x+\gamma_j)-(\beta_x+\gamma_k)=\gamma_j-\gamma_k\). \(\square\)

Worked Examples Across GLM Links

Worked Example: Identity Link and Two Group Slopes

Suppose a Gaussian model with identity link has a binary factor \(z\), with \(z=0\) as the reference level and \(z=1\) as the other level. Let

$$ \eta=\mu=10+2x+3z-0.75zx. $$

At the reference level \(z=0\), the product term and factor shift vanish. Therefore \(\mu=10+2x\), so the mean response increases by 2 units for each one-unit increase in \(x\). At \(z=1\), substitute \(z=1\): \(\mu=10+2x+3-0.75x=13+1.25x\). The slope is 1.25 units per unit of \(x\).

The interaction coefficient is \(-0.75\), and the slope difference is \(1.25-2=-0.75\), as the theorem states. For a direct check at \(x=2\), the fitted means are \(10+2(2)=14\) at the reference level and \(13+1.25(2)=15.5\) at the other level. The group difference at this particular \(x\) is 1.5; it is not the interaction coefficient. The interaction coefficient describes how the group difference changes as \(x\) increases.

Worked Example: Log Link and Conditional Rate Slopes

Suppose a Poisson GLM uses a log link and has a binary factor \(z\), with \(z=0\) as the reference level:

$$ \log(\mu)=\log(4)+0.12x+\log(1.5)z-0.05zx. $$

At \(z=0\), the linear-predictor slope is \(0.12\). At \(z=1\), it is \(0.12-0.05=0.07\). Thus the interaction coefficient, \(-0.05\), is the difference between these log-mean slopes. Equivalently, the fitted means are \(\mu_0(x)=4e^{0.12x}\) and \(\mu_1(x)=6e^{0.07x}\).

At \(x=2\), the reference-level mean is \(\mu_0=4e^{0.24}\approx5.085\), and the other-level mean is \(\mu_1=6e^{0.14}\approx6.902\). These are response means, not slopes. The ratio of the two means at a general \(x\) is

$$ \frac{\mu_1(x)}{\mu_0(x)} =\frac{6e^{0.07x}}{4e^{0.12x}} =1.5e^{-0.05x}. $$

The ratio changes with \(x\), because its log has slope \(-0.05\). This is one way the interaction appears on the response scale, but the coefficient itself remains a difference in log-mean slopes.

Worked Example: Logit Link and Probability Slopes

Consider a logistic regression with \(z=0\) as the reference level:

$$ \operatorname{logit}(p) =-1+0.8x+0.5z-0.3zx, \qquad \operatorname{logit}(p)=\log\!\left(\frac{p}{1-p}\right). $$

The reference-level slope on the logit scale is \(0.8\); the slope at \(z=1\) is \(0.8-0.3=0.5\). Therefore \(-0.3\) is the difference in logit slopes. It is not a constant difference in probabilities.

At \(x=0\), the reference-level linear predictor is \(-1\), so its probability is \(p_0=1/(1+e^1)\approx0.26894\). Differentiating the inverse logit gives the probability slope \(p(1-p)\) times the logit slope. Thus, at this point, the reference-level probability slope is \(0.26894(1-0.26894)(0.8)\approx0.15729\).

For \(z=1\) at \(x=0\), the linear predictor is \(-1+0.5=-0.5\), so \(p_1=1/(1+e^{0.5})\approx0.37754\). Its probability slope is \(0.37754(1-0.37754)(0.5)\approx0.11750\). The difference between these probability slopes is approximately \(-0.03979\), not \(-0.3\). The latter is the difference on the logit scale.

Why the Link Function Changes Response-Scale Slopes

A GLM specifies a linear predictor \(\eta\) and relates it to the conditional mean through \(\mu=g^{-1}(\eta)\). Consequently, the derivative of the mean with respect to \(x\) includes both the linear-predictor slope and the rate at which the inverse link changes at the current \(\eta\).

Theorem: Suppose \(g^{-1}\) is differentiable at the linear predictor for the factor level under consideration. If that level’s linear-predictor slope is \(s\), then the response-mean derivative is
$$ \frac{d\mu}{dx}=(g^{-1})'(\eta)s. $$

Proof. At a fixed factor level, \(\eta\) is a differentiable function of \(x\), and \(\mu=g^{-1}(\eta)\). The chain rule gives \(d\mu/dx=(g^{-1})'(\eta)(d\eta/dx)\). By definition, \(d\eta/dx=s\), which yields the stated expression. The response-mean derivative may vary with \(x\), even when \(s\) is constant, because \(\eta\) and therefore \((g^{-1})'(\eta)\) may vary with \(x\). \(\square\)

For the identity link, \((g^{-1})'(\eta)=1\), so the mean slope equals the linear-predictor slope. For the log link, \(\mu=e^\eta\), so \((g^{-1})'(\eta)=e^\eta=\mu\) and \(d\mu/dx=\mu s\). For the logit link, \(\mu=p=1/(1+e^{-\eta})\), and differentiating gives \((g^{-1})'(\eta)=p(1-p)\). Hence \(dp/dx=p(1-p)s\). These link-specific factors explain why equal or different linear-predictor slopes do not translate directly into fixed response-scale changes.

Interpretation and a Common Pitfall

A factor-by-continuous interaction is useful when the scientific question concerns whether a continuous association differs across groups. For example, in a log-link model, the interaction describes a difference in log-mean slopes; in a logit-link model, it describes a difference in logit slopes. Stating the scale is essential. The coefficient also depends on which factor level is used as the reference under reference coding, so interpretations should identify that reference level.

  • Common mistake: “The interaction coefficient is \(-0.3\), so the probability falls by 0.3 for each one-unit increase in \(x\) in the second group.” This treats a logit-scale coefficient as a probability-scale slope.
  • Correction: Under reference coding, \(-0.3\) is the difference between the two groups’ logit slopes. The probability slope at a given \(x\) is \(p(1-p)\) times the group’s logit slope, so it depends on the group’s probability at that \(x\).
  • Another useful check: A nonzero interaction coefficient means the linear-predictor slopes differ. It does not by itself say that one group’s fitted mean is always higher; that comparison also depends on the intercept terms and the value of \(x\).
Key takeaway: First derive the linear predictor for each factor level, then read off its coefficient of \(x\). The interaction coefficient is a difference between those slopes on the linear-predictor scale; use the inverse link and its derivative when interpreting changes in the mean response.

Check Your Understanding

Use the stated coding and keep the linear-predictor scale distinct from the response scale.

  1. In a reference-coded model with linear predictor \(\eta=2+1.4x-0.6z+0.9zx\), find the slope at each level of the binary factor and interpret the interaction coefficient.
  2. For a log-link model, explain why a coefficient of \(0.2\) for the continuous predictor is not generally an increase of \(0.2\) in the mean response per unit of \(x\).
  3. In a logistic model, what does a factor-by-continuous coefficient of \(-0.4\) compare? What additional quantity is needed to find a probability slope at a particular predictor value?
  4. For a factor with three levels and reference level 0, write the slope at level 2 in terms of the reference slope and its interaction coefficient.
  5. Why can the difference between two groups’ fitted means vary with \(x\), even though each group’s linear-predictor slope is constant?
Clinical Biostats