Tutorials › Generalized Linear Mixed Models (GLMM) › Comparing Clusters at the Same Covariate Value

Random Intercepts and Slopes · Tutorial 56 of 698

Comparing Clusters at the Same Covariate Value

Calculate a same-covariate, cluster-to-cluster difference by combining the random-intercept contrast with the random-slope contrast.

Intermediate 10 min read

What You'll Learn

  • Write the cluster-specific linear predictor for a random-intercept and random-slope model.
  • Calculate a difference between two clusters at a specified shared covariate value.
  • Explain why the fixed terms cancel when the clusters have the same covariates.
  • Interpret the difference on the link scale and distinguish it from a response-scale difference.
  • Check centering, covariate support, and random-effect estimates when making cluster comparisons.

Why Compare Clusters at a Shared Covariate Value?

In a random-slope model, clusters can differ both in their linear-predictor levels and in how their linear predictors change with a covariate. Comparing two clusters at the same value of that covariate separates the comparison from differences that would arise merely because the clusters were evaluated at different covariate values. The resulting contrast combines the clusters’ random-intercept difference with their random-slope difference, weighted by the shared covariate value.

The comparison is made on the linear-predictor scale. Its meaning on the response scale depends on the link function: for an identity link it is a response-mean difference, while for a log link or logit link it is not itself a response-mean or probability difference.

Model and Same-Value Contrast

Consider a GLMM with one covariate \(x_{ij}\), observation \(i\) in cluster \(j\), a random intercept, and a random slope for \(x\):

$$ g\{E(Y_{ij}\mid b_{0j},b_{1j})\} =\eta_{ij} =\beta_0+\beta_1 x_{ij}+b_{0j}+b_{1j}x_{ij}. $$

Here \(g\) is the link function, \(\eta_{ij}\) is the conditional linear predictor, \(\beta_0\) and \(\beta_1\) are the fixed intercept and fixed slope, and \(b_{0j}\) and \(b_{1j}\) are cluster \(j\)'s random-intercept and random-slope deviations. In particular, the cluster-specific linear-predictor slope is \(\beta_1+b_{1j}\); \(b_{1j}\) is only the cluster-specific random deviation from the common slope \(\beta_1\).

For this model, the usual random-effects assumptions are that the cluster-specific vectors \((b_{0j},b_{1j})\) are drawn from a common mean-zero distribution with covariance matrix \(G\), and that different clusters’ random-effect vectors are independent. The intercept and slope deviations may be correlated; assuming a zero covariance is not required. Conditional on the random effects and covariates, the responses follow the specified GLMM response distribution and are independent across observations. These assumptions define the model being interpreted; they do not guarantee that it fits the data well.

Definition: At a shared covariate value \(x=c\), the conditional linear-predictor difference between clusters \(j\) and \(k\), in the stated order, is $$ \Delta_{jk}(c)=\eta_j(c)-\eta_k(c) =(b_{0j}-b_{0k})+c(b_{1j}-b_{1k}). $$ The fixed intercept and slope cancel because both clusters are evaluated at the same \(c\). If fitted random effects are used, this is a plug-in estimate of the contrast, not a statement that the random effects are known exactly.

The formula requires that other fixed covariates and offsets, if present, are also held equal for the two clusters. More generally, any terms common to both clusters cancel; terms that differ do not. The covariate value \(c\) must also be expressed in the same units and coding used to fit the model.

Deriving and Using the Contrast

The result follows by writing each cluster’s predictor at \(c\) and subtracting in the specified order:

$$ \begin{aligned} \eta_j(c)&=\beta_0+\beta_1c+b_{0j}+b_{1j}c,\\ \eta_k(c)&=\beta_0+\beta_1c+b_{0k}+b_{1k}c,\\ \eta_j(c)-\eta_k(c) &=(\beta_0-\beta_0)+(\beta_1c-\beta_1c) +(b_{0j}-b_{0k})+c(b_{1j}-b_{1k})\\ &=(b_{0j}-b_{0k})+c(b_{1j}-b_{1k}). \end{aligned} $$

This derivation also explains why the contrast can change with \(c\). The random-intercept difference contributes a constant, while the random-slope difference contributes an amount proportional to the covariate value. If the two clusters have the same random slope deviation, their predictor difference is constant across \(x\). If their random slopes differ, the contrast may increase, decrease, or even change sign as \(x\) changes.

Worked Example: Identity-Link Difference at a Shared Value

Suppose a hypothetical identity-link model has \(\hat\beta_0=1.2\) and \(\hat\beta_1=0.4\). The fitted random effects are \((\hat b_{0A},\hat b_{1A})=(0.3,0.10)\) for cluster A and \((\hat b_{0B},\hat b_{1B})=(-0.2,-0.05)\) for cluster B. Compare the clusters at \(x=2\). Assume both clusters have the same values of any other covariates and offsets.

The estimated random-intercept difference is \(0.3-(-0.2)=0.5\), and the estimated random-slope difference is \(0.10-(-0.05)=0.15\) per unit of \(x\). Therefore,

$$ \widehat{\Delta}_{AB}(2) =\{0.3-(-0.2)\}+2\{0.10-(-0.05)\} =0.5+2(0.15)=0.80. $$

Checking by direct substitution, \(\hat\eta_A(2)=1.2+0.4(2)+0.3+0.10(2)=2.50\), whereas \(\hat\eta_B(2)=1.2+0.4(2)-0.2-0.05(2)=1.70\). Their difference is \(2.50-1.70=0.80\), as above. With an identity link, the conditional means differ by 0.80 outcome units at \(x=2\), with cluster A’s mean higher. This is a conditional, fitted comparison; it does not by itself quantify uncertainty.

Interpreting Differences Under Other Links

For a nonlinear link, \(\Delta_{jk}(c)\) is still a difference in linear predictors, but it is not generally a difference in conditional means. If \(g\) is increasing, the sign of the difference does show which cluster has the larger conditional mean at the shared covariate value: \(\eta_j(c)>\eta_k(c)\) implies \(E(Y\mid j,c)>E(Y\mid k,c)\). The size of the link-scale difference does not directly give the size of the response-scale difference.

Worked Example: Log-Link Contrast as a Rate Ratio

Suppose a hypothetical Poisson model for a conditional rate uses the log link. At \(x=3\), the fitted random effects are \((\hat b_{0A},\hat b_{1A})=(0.10,0.05)\) and \((\hat b_{0B},\hat b_{1B})=(-0.10,-0.02)\). Assume the clusters have equal offsets and all other covariates are the same.

The link-scale difference is

$$ \widehat{\Delta}_{AB}(3) =\{0.10-(-0.10)\}+3\{0.05-(-0.02)\} =0.20+3(0.07)=0.41. $$

Because the link is the natural logarithm, exponentiating the difference gives the fitted conditional rate ratio:

$$ \frac{\hat\lambda_A(3)}{\hat\lambda_B(3)} =\exp\{\widehat{\Delta}_{AB}(3)\} =\exp(0.41)\approx 1.507. $$

Thus, at \(x=3\), the fitted conditional rate for cluster A is about 1.51 times the rate for cluster B, under the stated equal-offset comparison. The value 0.41 is a log-rate difference, not a rate difference. The ratio is unitless; each rate retains its original rate units.

Worked Example: Logit-Link Contrast and Probability Difference

For a hypothetical logit-link model, let \(\hat\beta_0=-1\), \(\hat\beta_1=0.5\), and compare clusters A and B at \(x=2\). Let A’s fitted random effects be \((0.4,0.2)\), and B’s be \((-0.1,-0.1)\). All other covariates are held equal.

The contrast is

$$ \widehat{\Delta}_{AB}(2) =\{0.4-(-0.1)\}+2\{0.2-(-0.1)\} =0.5+0.6=1.10. $$

Direct substitution gives \(\hat\eta_A(2)=-1+0.5(2)+0.4+0.2(2)=0.80\) and \(\hat\eta_B(2)=-1+0.5(2)-0.1-0.1(2)=-0.30\). Their difference is \(0.80-(-0.30)=1.10\). The corresponding conditional probabilities are \(\operatorname{logit}^{-1}(0.80)\approx0.690\) and \(\operatorname{logit}^{-1}(-0.30)\approx0.426\), a probability difference of about \(0.264\), not 1.10. Exponentiating the contrast gives the conditional odds ratio \(\exp(1.10)\approx3.004\). Thus A’s conditional odds are about 3.00 times B’s at this shared value.

Reference Points, Diagnostics, and Alternatives

The covariate’s reference point matters for the individual random intercepts, but not for a correctly calculated contrast at a fixed physical covariate value. For example, recentering \(x\) changes the intercept component of each cluster’s representation: some of the cluster-specific level at the new origin is represented by its slope deviation. The prediction at a given original \(x\), and hence the difference between predictions at that \(x\), remains unchanged when the model is re-expressed consistently. A practical check is to verify that the \(c\) used in the contrast is on the exact centered or uncentered scale used in fitting.

Before interpreting a calculated contrast, check the following:

  • Confirm the order of subtraction. \(\Delta_{jk}(c)\) is cluster \(j\) minus cluster \(k\); reversing the order reverses its sign.
  • Use the shared covariate value, not a different value for each cluster. A comparison at different values combines cluster differences with covariate changes.
  • Check that the value is within, or reasonably supported by, the observed covariate range for both clusters. A numerical contrast can be calculated outside that range, but may rely on extrapolation.
  • Verify that the random slope belongs to the stated covariate and that the random effects and \(c\) use the same units and centering.
  • Remember that fitted random effects are estimated, often with shrinkage toward the population mean. A point contrast alone does not show its uncertainty or establish that clusters differ statistically.

One alternative is to compare only random intercepts. That is sufficient for the contrast at \(x=0\), but at a nonzero \(c\) it omits \(c(b_{1j}-b_{1k})\) and can give the wrong magnitude or even the wrong sign. Another alternative is to compare predicted response means directly. That can be useful when the scientific question is about response-scale differences, particularly with nonlinear links, but it answers a different scale-specific question and requires applying the inverse link to each cluster’s predictor before subtracting. A population-average comparison is also distinct from this cluster-conditional comparison: the present calculation uses the specified clusters’ random effects.

The method has limits. It concerns a particular covariate value and a fitted model with a common fixed slope and random deviations. If the model’s structure or covariate values are inappropriate, the arithmetic does not repair that problem. Further, an estimated contrast does not alone provide a confidence interval or test; those require accounting for uncertainty in the estimated fixed effects and random effects, as appropriate to the inferential target.

Common Mistake

Common mistake: Treating \(b_{1j}\) as the full cluster-specific slope and comparing clusters using only \(b_{0j}-b_{0k}\), or saying the random-slope term alone is the change in the predictor per unit of \(x\). The correction is that the cluster-specific linear-predictor slope is \(\beta_1+b_{1j}\), while \(b_{1j}\) is the deviation from the fixed slope. At a shared value \(c\), the cluster contrast is \((b_{0j}-b_{0k})+c(b_{1j}-b_{1k})\); the fixed slope cancels between clusters, but the random-slope contrast generally does not.

Check Your Understanding

For each question, identify the scale of the contrast and show the calculation where needed.

  1. At \(x=4\), cluster A has \((b_{0A},b_{1A})=(0.2,0.05)\) and cluster B has \((b_{0B},b_{1B})=(-0.1,0.10)\). What is \(\Delta_{AB}(4)\)?
  2. If two clusters have equal random-intercept deviations but different random-slope deviations, must their predictor difference be zero at every \(x\)?
  3. In a log-link model, what does a contrast of \(-0.20\) imply for the conditional rate ratio of cluster A to cluster B?
  4. In a logit-link model, is a contrast of \(0.8\) the difference in conditional probabilities?

Solutions. (1) \(\Delta_{AB}(4)=\{0.2-(-0.1)\}+4(0.05-0.10)=0.30-0.20=0.10\), so A’s linear predictor is 0.10 higher. (2) No. With equal intercept deviations, the contrast is \(x(b_{1A}-b_{1B})\), which is generally nonzero except at \(x=0\) or when the slope deviations are equal. (3) The rate ratio is \(\exp(-0.20)\approx0.819\); A’s fitted conditional rate is about 0.819 times B’s at that shared covariate value, assuming other terms and offsets are equal. (4) No. It is a log-odds difference; the corresponding odds ratio is \(\exp(0.8)\approx2.226\). The probability difference depends on both clusters’ linear predictors.

Clinical Biostats