Tutorials › Generalized Linear Mixed Models (GLMM) › Deriving Conditional Contrasts With Random Intercepts

Random Intercepts and Slopes · Tutorial 37 of 698

Deriving Conditional Contrasts With Random Intercepts

Learn to derive and interpret within-cluster contrasts, distinguish link-scale from response-scale differences, and identify when random-intercept cancellation does not apply.

Intermediate 10 min read

What You'll Learn

  • Write a conditional mean model with a random intercept and identify the assumptions needed for cancellation.
  • Derive the link-scale contrast between two covariate values in the same cluster.
  • Distinguish a contrast in linear predictors from a contrast in conditional means.
  • Work through Gaussian and logistic examples with numerical substitutions.
  • Explain why a comparison across different clusters generally retains a random-effect difference.
  • Recognize random slopes, changing covariates, and incorrect link-scale interpretations as common failure modes.

Why Compare Two Covariate Values Within One Cluster?

In clustered data, observations from the same clinic, school, or person can share a baseline tendency. A random intercept represents that cluster-specific baseline. When the question compares two covariate values within the same cluster, the shared baseline appears in both linear predictors. Subtracting one predictor from the other therefore removes it. This is a simple algebraic fact, but its interpretation depends on the link function and on whether the model really uses a common random intercept for both observations.

The result concerns a conditional comparison: it holds at a fixed value of the cluster's random intercept. It does not say that observations from different clusters have the same baseline, nor that a contrast between observed outcomes has no residual variation.

Definition: Let \(Y_{ij}\) be the response for observation \(i\) in cluster \(j\), and let \(x_{ij}\) be a covariate. A random-intercept GLMM has conditional mean \(\mu_{ij}=E(Y_{ij}\mid b_{0j},x_{ij},z_{ij})\) and linear predictor $$ g(\mu_{ij})=\eta_{ij}=\beta_0+\beta_1x_{ij}+\boldsymbol{\gamma}^{T}\mathbf{z}_{ij}+b_{0j}. $$ Here \(g\) is the link function, \(b_{0j}\) is the random intercept for cluster \(j\), and \(\mathbf{z}_{ij}\) denotes any other covariates with fixed effects. The model assumes that the same \(b_{0j}\) enters each observation in cluster \(j\) with coefficient 1. A within-cluster contrast changes \(x\) while holding the cluster and the other covariates fixed.

For the usual random-effects formulation, the random intercepts are modeled as draws from a distribution with mean zero and a common variance, often independently across clusters. Those distributional assumptions are relevant to fitting and interpreting the full model. However, the algebraic cancellation below does not require a particular distribution for \(b_{0j}\): it requires only that the two predictors contain the same cluster's same random intercept. The conditional mean model and the stated covariate comparisons must also be appropriate.

Deriving the Within-Cluster Contrast

Consider two covariate values \(x_a\) and \(x_b\) in cluster \(j\). Suppose all components of \(\mathbf{z}\) are the same for the two predictions. Subtract the linear predictor at \(x_a\) from the one at \(x_b\):

$$ \begin{aligned} \eta_j(x_b)-\eta_j(x_a) &=\left(\beta_0+\beta_1x_b+\boldsymbol{\gamma}^{T}\mathbf{z}+b_{0j}\right) -\left(\beta_0+\beta_1x_a+\boldsymbol{\gamma}^{T}\mathbf{z}+b_{0j}\right)\\ &=\beta_1(x_b-x_a). \end{aligned} $$

Both the fixed intercept and the shared covariate terms cancel, as does the random intercept. Thus, the conditional linear-predictor contrast is the fixed slope multiplied by the covariate difference. This conclusion is exact for the stated model; it is not an approximation based on a large sample or a small random effect.

The contrast in conditional means is a different quantity. It is \(g^{-1}\{\eta_j(x_b)\}-g^{-1}\{\eta_j(x_a)\}\). With an identity link, this equals \(\beta_1(x_b-x_a)\). With a nonlinear link, the inverse link is applied to each predictor before subtraction, so the response-scale difference may depend on the cluster's random intercept. Cancellation on the link scale does not generally mean cancellation on the response scale.

Key result: Under a random-intercept model with no random slope for \(x\), the same cluster's random intercept cancels from the difference in linear predictors when comparing two values of \(x\) and holding other covariates fixed. The resulting link-scale contrast is \(\beta_1(x_b-x_a)\). The response-scale contrast must be calculated using the inverse link.

Worked Examples

Worked Example: A Gaussian Model With an Identity Link

Suppose a hypothetical continuous-outcome model predicts a measurement in millimetres from a treatment dose \(x\), measured in units. Its conditional mean model is \(\mu_{ij}=10+2.4x_{ij}+b_{0j}\), with an identity link. For one cluster, take \(b_{0j}=-1.5\). Compare doses \(x_a=2\) and \(x_b=5\).

At dose 2, the conditional mean is $$ \mu_j(2)=10+2.4(2)-1.5=13.3\text{ mm}. $$ At dose 5, it is $$ \mu_j(5)=10+2.4(5)-1.5=20.5\text{ mm}. $$ The difference is \(20.5-13.3=7.2\) mm. Directly from the contrast formula, it is \(2.4(5-2)=7.2\) mm. The random intercept shifts both conditional means down by 1.5 mm but does not change their difference. Because the link is the identity, the link-scale and conditional mean differences have the same numerical value and units.

The cancellation is not a claim that two observed responses differ by exactly 7.2 mm. For example, if the observed responses were 12.9 mm at dose 2 and 21.6 mm at dose 5, their observed difference would be 8.7 mm. The remaining 1.5 mm is the difference between the two residual deviations from their conditional means.

Worked Example: A Logistic Model and a Response-Scale Difference

Consider hypothetical binary responses with a logit link and \(\eta_{ij}=-1.2+0.7x_{ij}+b_{0j}\). For one cluster let \(b_{0j}=0.8\), and compare \(x_a=0\) with \(x_b=1\). The link-scale contrast is \(0.7(1-0)=0.7\), regardless of the value of this cluster's intercept.

The predictors and conditional probabilities for this cluster are $$ \eta_j(0)=-1.2+0+0.8=-0.4,\qquad \eta_j(1)=-1.2+0.7+0.8=0.3, $$ $$ \mu_j(0)=\frac{1}{1+\exp(0.4)}\approx 0.4013,\qquad \mu_j(1)=\frac{1}{1+\exp(-0.3)}\approx 0.5744. $$ Thus the conditional probability difference is approximately \(0.5744-0.4013=0.1731\), or 17.31 percentage points.

Now consider the same covariate values for a cluster with \(b_{0j}=-0.8\). The predictors are \(-2.0\) and \(-1.3\), again differing by 0.7. The probabilities are approximately 0.1192 and 0.2142, a difference of 0.0950, or 9.50 percentage points. The link-scale contrast is unchanged, but the response-scale difference is not. The inverse logit is nonlinear, so the baseline predictor affects the probability difference.

Worked Example: Why a Cross-Cluster Contrast Is Different

Suppose a hypothetical model has \(\eta_{ij}=4+1.1x_{ij}+b_{0j}\). Compare a measurement with \(x=1\) in cluster A, whose random intercept is \(b_{0A}=0.5\), with a measurement having \(x=3\) in cluster B, whose random intercept is \(b_{0B}=-0.4\).

The first predictor is \(4+1.1(1)+0.5=5.6\). The second is \(4+1.1(3)-0.4=6.9\). The cross-cluster difference is therefore \(6.9-5.6=1.3\). Algebraically, $$ \eta_B(3)-\eta_A(1) =1.1(3-1)+(-0.4-0.5) =2.2-0.9 =1.3. $$ The fixed-effect contribution alone is 2.2, but the random-intercept difference contributes \(-0.9\). If the comparison instead used \(x=1\) and \(x=3\) within cluster A, the random intercept would be the same in both predictors and the contrast would be 2.2. It is the shared cluster, not merely the presence of a random-intercept model, that permits cancellation.

Conditions, Diagnostics, and Common Failure Modes

Before interpreting a contrast as \(\beta_1(x_b-x_a)\), check what is being compared and what model was fitted. The key conditions are narrow and explicit:

  • Same cluster: both predictors must contain the same \(b_{0j}\). If the observations come from different clusters, their random-intercept difference remains.
  • Same other covariates: terms involving \(\mathbf{z}\) cancel only when those covariates are held fixed. If a covariate changes, its fixed-effect contribution belongs in the contrast.
  • No random slope for the changing covariate: if the predictor also contains \(b_{1j}x_{ij}\), the within-cluster contrast includes \(b_{1j}(x_b-x_a)\). It is then not just the fixed slope times the covariate difference.
  • Correct link-scale interpretation: \(\beta_1(x_b-x_a)\) is a contrast in linear predictors. For a nonlinear link, it is not generally a difference in conditional means.

These conditions suggest practical diagnostics. Check the model specification for random slopes and interactions; verify that the two predictions use the same cluster identifier and the same values of the other covariates; and state the scale of the contrast before reporting it. If model adequacy is in doubt, inspect residual patterns and compare observed outcomes with fitted conditional means using diagnostics appropriate to the response family. A contrast can be calculated exactly from a fitted model and still be misleading if the conditional mean structure is unsuitable.

A common mistake is to say, “The random intercept cancels, so the two predicted probabilities differ by \(\beta_1(x_b-x_a)\).” This confuses the link scale with the response scale. The subtraction cancels \(b_{0j}\) in \(\eta\), but a nonlinear inverse link must still be applied separately to each predictor. Another mistake is to claim cancellation for two observations from different clusters: in that case the difference \(b_{0k}-b_{0j}\) remains unless the two random intercepts happen to be equal.

How This Contrast Differs From Other Comparisons

A within-cluster contrast holds the cluster baseline fixed and changes the covariate of interest. A between-cluster comparison changes the cluster as well, so its predictor contrast generally combines the fixed-effect contribution with a difference in random intercepts. These are different estimands and should not be described interchangeably.

A model with fixed cluster indicators can also represent cluster-specific baselines, but it treats those baselines as separate fixed parameters rather than as draws from a random-effects distribution. In either formulation, comparing two covariate values while holding the same cluster baseline fixed removes that baseline from a linear-predictor difference. The modeling assumptions and the interpretation of fitted cluster effects are nevertheless different.

A conditional contrast is also distinct from a population-average comparison, which averages predictions over the random-effects distribution. For nonlinear links, averaging inverse-link predictions is not generally the same as applying the inverse link to an average predictor. The cancellation derived here is a conditional, same-cluster result; it does not itself calculate a population-average contrast.

Limitation: Cancellation is a property of the specified predictor, not a guarantee that the estimated contrast is known without uncertainty or that the model is correct. Estimated fixed effects have sampling uncertainty, and a missing random slope or an incorrectly held covariate can change the contrast being represented.

Check Your Understanding

For each question, identify the relevant scale and show the calculation. Solutions follow the questions.

  1. A Gaussian identity-link model has \(\beta_1=1.6\) outcome units per unit of \(x\). What is the same-cluster conditional mean contrast for \(x_a=1\) and \(x_b=4\), with other covariates held fixed?
  2. In a nonlinear-link model, what part of the linear predictor cancels when two \(x\) values are compared within a cluster? Does that alone determine the response-scale difference?
  3. A model includes \(b_{0j}+b_{1j}x_{ij}\) as its random-effects contribution. Write the within-cluster linear-predictor contrast for \(x_b\) versus \(x_a\).
  4. Two observations come from different clusters. Their covariate difference is 2, the fixed slope is 0.9, and the second cluster's random intercept is 0.3 lower than the first's. Find the linear-predictor contrast.

Solutions.

1. With an identity link, the conditional mean contrast equals the linear-predictor contrast: \(1.6(4-1)=4.8\) outcome units.

2. The common fixed intercept, the common values of other fixed covariate terms, and the same cluster's random intercept cancel. The linear-predictor contrast is \(\beta_1(x_b-x_a)\). For a nonlinear link, the response-scale difference requires applying the inverse link to both predictors; it cannot be determined from the slope contrast alone.

3. Subtracting the two predictors gives \((\beta_1+b_{1j})(x_b-x_a)\). The random intercept cancels, but the random slope contribution does not.

4. The fixed-effect contribution is \(0.9(2)=1.8\). The random-intercept difference is \(-0.3\), so the linear-predictor contrast is \(1.8-0.3=1.5\).

Clinical Biostats