Tutorials › Generalized Linear Mixed Models (GLMM) › Fixed Cross-Level Interactions and Random Slopes

Random Intercepts and Slopes · Tutorial 57 of 698

Fixed Cross-Level Interactions and Random Slopes

Learn how fixed cross-level interactions and random slopes enter one GLMM, how they change the conditional slope, and how to interpret and distinguish their effects.

Intermediate 11 min read

What You'll Learn

  • Identify the fixed cross-level interaction coefficient and the random-slope term in a GLMM.
  • Derive the individual-level slope on the link scale for a specified cluster.
  • Interpret how the cluster-level predictor changes the average slope.
  • Separate systematic slope differences from residual variation among clusters.
  • Recognize model assumptions, diagnostics, and common interpretation errors.

Two Sources of Slope Differences

In clustered data, an individual-level association may differ from one cluster to another. For example, the association between a patient-level measure and an outcome might vary across clinics. There are two distinct ways to represent such differences. A fixed cross-level interaction describes systematic variation in the slope associated with a measured cluster-level predictor. A random slope describes residual variation in that slope among clusters, beyond what the model explains through measured predictors.

These terms can appear in the same generalized linear mixed model (GLMM). They answer different questions: does a cluster characteristic predict how the individual-level association changes, and do clusters still vary in that association after accounting for the characteristic?

Definition: Let \(i\) index individuals and \(j\) index clusters. Let \(x_{ij}\) be an individual-level covariate and \(z_j\) a cluster-level covariate. A fixed cross-level interaction is the product \(x_{ij}z_j\) with coefficient \(\beta_3\). A random slope for \(x_{ij}\) is a cluster-specific random coefficient \(b_{1j}\) multiplying \(x_{ij}\). The fixed interaction describes systematic slope change with \(z_j\); the random slope describes remaining cluster-to-cluster slope variation.

Model and Link-Scale Slope

A model containing both terms is

$$ g(\mu_{ij})=\eta_{ij} =\beta_0+\beta_1x_{ij}+\beta_2z_j+\beta_3x_{ij}z_j+b_{0j}+b_{1j}x_{ij}, \qquad \mu_{ij}=E(Y_{ij}\mid b_j). $$

Here \(g\) is the link function, \(\eta_{ij}\) is the conditional linear predictor, and \(b_j=(b_{0j},b_{1j})^\mathsf{T}\) contains a random intercept and random slope. A standard specification assumes \(b_j\sim N_2(0,\Sigma)\), where

$$ \Sigma= \begin{pmatrix} \tau_{00} & \tau_{01}\\ \tau_{01} & \tau_{11} \end{pmatrix}. $$

The response distribution is specified conditional on the random effects, with mean \(\mu_{ij}\). Responses are assumed conditionally independent given the random effects and covariates, and clusters are assumed independent. The random-effects distribution has mean zero and a valid covariance matrix. In the usual interpretation, the modeled random effects are not systematically associated with omitted covariate information after conditioning on the model’s included predictors. The individual-level covariate must vary within clusters to inform its within-cluster slope; the cluster-level covariate is constant within each cluster.

To see the distinction, hold \(z_j\) and the random effects fixed and differentiate the linear predictor with respect to \(x_{ij}\):

$$ \frac{\partial\eta_{ij}}{\partial x_{ij}} =\beta_1+\beta_3z_j+b_{1j}. $$

The population-average random-effects value, \(b_{1j}=0\), gives a link-scale slope of \(\beta_1+\beta_3z_j\). Thus \(\beta_3\) describes how that slope changes systematically for a one-unit increase in \(z_j\). For a particular cluster, \(b_{1j}\) adds a cluster-specific deviation. The random slope is not another name for the interaction: it is not the product \(x_{ij}z_j\), and it is not necessarily explained by \(z_j\).

The slope just derived is on the link scale. For a nonlinear inverse link \(h=g^{-1}\), the conditional mean is \(\mu_{ij}=h(\eta_{ij})\), so its response-scale derivative is

$$ \frac{\partial\mu_{ij}}{\partial x_{ij}} =h'(\eta_{ij})(\beta_1+\beta_3z_j+b_{1j}). $$

Consequently, the link-scale slope and the response-scale change need not be numerically equal. With a log link, exponentiating the link-scale slope gives a conditional rate ratio per one-unit increase in \(x\); with a logit link, it gives a conditional odds ratio.

Why the Slope Formula Holds

For fixed cluster \(j\), \(z_j\), \(b_{0j}\), and \(b_{1j}\) are constant as \(x_{ij}\) changes. Collecting the terms that contain \(x_{ij}\) gives

$$ \eta_{ij} =(\beta_0+\beta_2z_j+b_{0j}) +x_{ij}(\beta_1+\beta_3z_j+b_{1j}). $$

The coefficient multiplying \(x_{ij}\) is therefore the derivative with respect to that covariate. Its components have separate roles: \(\beta_1\) is the slope at \(z_j=0\) and \(b_{1j}=0\); \(\beta_3z_j\) is the systematic change associated with the cluster-level predictor; \(b_{1j}\) is the cluster-specific deviation. This also shows why centering matters for interpretation: changing the zero point of \(z_j\) changes the reference value for \(\beta_1\), and changing the zero point of \(x_{ij}\) changes the reference point for the intercept. Centering does not turn a random slope into a fixed interaction or vice versa.

Worked Example: A Clinic Characteristic Moderates a Patient-Level Association

Suppose a hypothetical Gaussian mixed model predicts a recovery score, with \(x_{ij}\) equal to baseline symptom severity (in points) and \(z_j\) equal to a clinic staffing measure centered so that zero is its sample mean. For illustration, suppose the fitted link-scale coefficients are \(\beta_1=-1.2\) recovery-score points per symptom point and \(\beta_3=0.40\) recovery-score points per symptom point for each one-unit increase in the staffing measure. Ignore the random slope initially.

At \(z_j=0\), the fitted slope is

$$ \beta_1+\beta_3z_j=-1.2+(0.40)(0)=-1.2. $$

At a clinic with \(z_j=2\), it is

$$ -1.2+(0.40)(2)=-0.40 $$

recovery-score points per symptom point. The positive interaction coefficient means the negative slope becomes 0.40 points less negative for each one-unit increase in the staffing measure. This is a conditional model association, not evidence that changing staffing causes the outcome to change.

Now suppose that clinic has random slope \(b_{1j}=-0.30\). Its conditional slope becomes \(-0.40-0.30=-0.70\) recovery-score points per symptom point. The interaction describes the systematic difference associated with \(z_j=2\); the random effect describes an additional deviation for that clinic.

Worked Example: Distinguishing a Logit Interaction From Slope Variation

Consider a hypothetical logistic mixed model for a binary outcome. Let \(x_{ij}\) be patient age in years, centered at 50 years, and let \(z_j\) be a clinic training measure in units of ten training hours. Suppose the estimates are \(\beta_1=-0.40\) and \(\beta_3=0.25\), measured in log-odds per age-year and the corresponding interaction units. At a clinic with \(z_j=2\), the fixed-effects log-odds slope is

$$ -0.40+(0.25)(2)=0.10. $$

For the average random slope, the conditional odds ratio for a one-year increase in age is \(\exp(0.10)=1.105\). In this fitted model, at that training level and at the random-effects value zero, the odds are multiplied by about 1.105 for each additional year of age. This is a conditional odds comparison, not a probability increase of 10.5 percentage points.

Suppose a particular clinic has \(b_{1j}=-0.15\). Its log-odds slope is \(0.10-0.15=-0.05\), and its corresponding conditional odds ratio is \(\exp(-0.05)=0.9512\). The fixed interaction is unchanged; the clinic’s random slope shifts its own conditional slope. The actual probability change also depends on the model’s linear predictor, including the intercept and covariate values.

What Each Term Does—and Does Not—Explain

Model componentQuestion it addressesWhat it represents
\(\beta_3x_{ij}z_j\)Does the measured cluster characteristic systematically modify the individual-level association?A fixed, modeled change in the link-scale slope as \(z_j\) changes.
\(b_{1j}x_{ij}\)Do clusters still differ in their individual-level slopes after accounting for \(z_j\)?A cluster-specific random deviation in the link-scale slope.
\(b_{0j}\)Do clusters differ in their baseline linear predictor?A cluster-specific intercept deviation.

The corresponding null claims are different. Setting \(\beta_3=0\) removes the modeled linear change in slope with \(z_j\). Setting \(\tau_{11}=0\) removes residual random-slope variation, because \(\tau_{11}=\operatorname{Var}(b_{1j})\). Evidence for one term does not imply evidence for the other. A model may have systematic moderation but little residual slope variation, residual variation without a detected interaction, both, or neither.

Worked Example: Same Cluster Predictor, Different Random Slopes

Suppose a hypothetical fitted model has \(\beta_1=0.50\), \(\beta_3=0.20\), and two clinics both have \(z_j=1\). Their fixed-effects slope is \(0.50+(0.20)(1)=0.70\) link units per unit of \(x\). Assume their estimated random slopes are \(b_{1A}=-0.20\) and \(b_{1B}=0.30\).

Clinic A’s conditional slope is \(0.70-0.20=0.50\); clinic B’s is \(0.70+0.30=1.00\). Since the clinics have the same \(z_j\), their difference here is represented by their different random slopes, not by the fixed interaction. The example illustrates the model’s decomposition; estimated random effects are uncertain and should not be treated as directly observed cluster properties.

Assumptions, Diagnostics, and Limitations

A useful interpretation depends on the design and the model being plausible. The cluster-level predictor must vary across clusters to estimate its contribution, while the individual-level predictor needs within-cluster variation to identify a within-cluster slope. Estimating an interaction also requires sufficient overlap: if high values of \(z_j\) occur only in a few clusters, or if \(x_{ij}\) has little variation in some ranges of \(z_j\), the interaction may be imprecise or rely heavily on extrapolation. The interaction is a linear change in slope on the chosen link scale; it does not automatically describe nonlinear moderation.

A random slope requires enough information across clusters to distinguish slope variation from sampling noise. Warning signs include convergence problems, a variance estimate near zero, an estimated covariance matrix that is nearly singular, or large changes in coefficients when a few clusters are removed. These findings do not by themselves prove the model is wrong, but they call for checking covariate scaling, centering, cluster counts, within-cluster spread in \(x\), and whether the response family and link are appropriate. Plots of cluster-level data and fitted patterns can help reveal nonlinearity or influential clusters.

The fixed interaction and random slope are not competing alternatives in the strict sense: one can include both, as above. A model with only the interaction assumes no residual slope variation; a model with only a random slope does not explain its average variation using \(z_j\); including both allows both explanations. A model without either assumes a common link-scale slope. Choosing among these structures should be guided by the scientific question, design, plausible complexity, and model diagnostics, not by the desire to include every possible term. Inference for variance components also requires care because zero variance is on the boundary of the allowable parameter space.

Common Mistake

Wrong reasoning: “The interaction coefficient is positive, so every clinic’s slope increases by that amount, and the random-slope variance is another measure of the interaction.” This conflates a systematic change with residual variation.

Correction: For a given cluster, the link-scale slope is \(\beta_1+\beta_3z_j+b_{1j}\). A one-unit increase in \(z_j\) changes the model’s systematic slope by \(\beta_3\), while \(b_{1j}\) is that cluster’s random deviation. A positive \(\beta_3\) does not guarantee every cluster has a larger slope: random deviations may be positive or negative. Neither term alone establishes a causal effect.

Key takeaway: In a model with both terms, \(\beta_3\) describes how the link-scale slope changes systematically with the cluster-level predictor, while \(b_{1j}\) describes remaining cluster-specific slope deviation. Keep those roles separate when specifying, interpreting, and checking the model.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. In the stated model, what is the link-scale slope for cluster \(j\) as a function of its covariates and random effect?
  2. If \(\beta_1=0.30\), \(\beta_3=-0.10\), \(z_j=2\), and \(b_{1j}=0.05\), calculate the cluster’s link-scale slope.
  3. Does \(\beta_3=0\) imply that random slopes have zero variance? Explain.
  4. What problem arises if \(z_j\) is identical in every cluster?

Solutions. (1) The slope is \(\beta_1+\beta_3z_j+b_{1j}\), obtained by differentiating the linear predictor with respect to \(x_{ij}\). (2) Substitution gives \(0.30+(-0.10)(2)+0.05=0.15\) link units per unit of \(x\). (3) No. \(\beta_3=0\) removes the modeled systematic slope change with \(z_j\); \(\tau_{11}=0\) is the separate claim that random slopes have zero variance. (4) There is no between-cluster variation in \(z_j\) from which to estimate its effect or the cross-level interaction, so their coefficients are not identified from that predictor variation.

Clinical Biostats