Tutorials › Generalized Linear Mixed Models (GLMM) › Predicting Random Slopes at Specific Covariate Values

Prediction of Random Effects · Tutorial 470 of 698

Predicting Random Slopes at Specific Covariate Values

Use the predicted random-effect vector and its covariance to estimate a group’s deviation at a chosen covariate value and quantify its uncertainty on the link scale.

Advanced 10 min read

What You'll Learn

  • Express a group-specific deviation at a chosen covariate value as a linear combination of its random effects.
  • Calculate that deviation from a predicted random-intercept and random-slope vector.
  • Use the full covariance matrix to calculate the deviation’s variance and standard error.
  • Construct and interpret a pointwise interval on the model’s link scale.
  • Diagnose errors from omitting covariance, confusing a slope with a value-specific deviation, or misinterpreting the interval.

Why Evaluate a Random Slope at a Particular Value?

In a GLMM with a random intercept and random slope, a group’s deviation from the population-level linear predictor depends on the covariate value. The random intercept describes the deviation when the covariate is zero; the random slope describes how that deviation changes for a one-unit increase in the covariate. Often the useful quantity is neither coefficient alone, but the group’s deviation at a specified covariate value.

For example, a group may have a modest predicted intercept deviation but a positive predicted slope deviation. At one covariate value these contributions might partly cancel, while at another they might reinforce each other. The uncertainty in the resulting deviation also depends on the covariance between the predicted intercept and slope. This tutorial calculates that value-specific deviation and its uncertainty on the model’s linear-predictor, or link, scale.

Definition and Assumptions

Consider group \(j\), with a random intercept \(b_{0j}\) and a random slope \(b_{1j}\) for covariate \(x\). At a specified value \(x_0\), the group-specific random contribution to the linear predictor is \(b_{0j}+x_0b_{1j}\). The fixed-effects part of the linear predictor is separate; the quantity calculated here is the group’s deviation from that fixed-effects part.

Definition: Let \(\mathbf{b}_j=(b_{0j},b_{1j})^\mathsf{T}\) be the random-effect vector for group \(j\), and let \(\hat{\mathbf{b}}_j\) be its predicted value. At covariate value \(x_0\), define \(\mathbf{z}(x_0)=(1,x_0)^\mathsf{T}\). The predicted group-specific deviation on the linear-predictor scale is \(\hat d_j(x_0)=\mathbf{z}(x_0)^\mathsf{T}\hat{\mathbf{b}}_j=\hat b_{0j}+x_0\hat b_{1j}\). If \(\mathbf{V}_j\) is the conditional covariance matrix for \(\mathbf{b}_j\), the variance of this deviation is \(\mathbf{z}(x_0)^\mathsf{T}\mathbf{V}_j\mathbf{z}(x_0)\).

For the usual two-effect case, write the covariance matrix as

$$ \mathbf{V}_j= \begin{pmatrix} v_{00} & v_{01}\\ v_{01} & v_{11} \end{pmatrix}. $$

Here \(v_{00}\) is the conditional variance of the random intercept, \(v_{11}\) is the conditional variance of the random slope, and \(v_{01}\) is their conditional covariance. These are conditional uncertainties for this group’s random effects, given the observed data and fitted model parameters. They are not the population random-effects covariance matrix.

The calculation assumes the predicted vector and its covariance are available from a fitted model, with the covariance referring to the same group and effect ordering as the vector. A normal-based interval additionally assumes that the conditional distribution of the random-effect vector is adequately represented by a bivariate normal distribution, or that a normal approximation is appropriate. In non-Gaussian GLMMs, conditional distributions can be skewed; in that case, the linear-combination calculation still gives a mean and variance when those moments are appropriate, but a normal interval may not be reliable. The examples below state when a normal approximation is used.

Deriving the Value-Specific Variance

The variance formula follows from the variance of a linear combination. Expanding the matrix product gives

$$ \begin{aligned} \operatorname{Var}\{b_{0j}+x_0b_{1j}\mid\text{data}\} &= \operatorname{Var}(b_{0j}\mid\text{data}) +x_0^2\operatorname{Var}(b_{1j}\mid\text{data})\\ &\quad+2x_0\operatorname{Cov}(b_{0j},b_{1j}\mid\text{data})\\ &=v_{00}+2x_0v_{01}+x_0^2v_{11}. \end{aligned} $$

To see why the covariance appears twice, let \(A=b_{0j}\) and \(B=x_0b_{1j}\). Expanding \(\operatorname{Var}(A+B)\) gives \(\operatorname{Var}(A)+\operatorname{Var}(B)+\operatorname{Cov}(A,B)+\operatorname{Cov}(B,A)\). Since covariance is symmetric and \(x_0\) is fixed, the last two terms sum to \(2x_0\operatorname{Cov}(b_{0j},b_{1j})\). The standard error is the square root of the resulting variance.

This is a pointwise calculation: it concerns one specified covariate value. It does not provide a simultaneous interval covering the group’s deviation over an entire range of covariate values. The chosen \(x_0\) must also use the same units and coding as the fitted model’s slope.

Worked Example: Deviation at Two Covariate Units

Suppose a hypothetical fitted binary GLMM gives one group the predicted random-effect vector \(\hat{\mathbf{b}}_j=(0.12,-0.03)^\mathsf{T}\). Its conditional covariance matrix is

$$ \mathbf{V}_j= \begin{pmatrix} 0.09 & -0.01\\ -0.01 & 0.004 \end{pmatrix}. $$

Assume the conditional distribution is adequately approximated by a bivariate normal distribution. Calculate the group’s predicted deviation at \(x_0=2\), its standard error, and an approximate 95% pointwise interval. The covariate is measured in the units used to fit the model; the deviation is on the model’s link scale.

The design vector is \(\mathbf{z}(2)=(1,2)^\mathsf{T}\). The predicted deviation is

$$ \hat d_j(2)=0.12+2(-0.03)=0.06. $$

For the variance, include the covariance term:

$$ \begin{aligned} \widehat{\operatorname{Var}}\{d_j(2)\} &=0.09+2(2)(-0.01)+2^2(0.004)\\ &=0.09-0.04+0.016\\ &=0.066. \end{aligned} $$

Thus the standard error is \(\sqrt{0.066}\approx0.2569\). The approximate interval is

$$ 0.06\pm1.96(0.2569) =0.06\pm0.5035 \approx(-0.4435,\ 0.5635). $$

Under the stated normal approximation, this is a 95% pointwise interval for the group’s latent deviation at \(x=2\), conditional on the fitted model and observed data. It is not an interval for the response probability, nor does it account for all uncertainty in estimated model parameters.

Worked Applications

Worked Example: A Negative Covariate Value

For a different hypothetical group, suppose \(\hat{\mathbf{b}}_j=(-0.08,0.05)^\mathsf{T}\) and

$$ \mathbf{V}_j= \begin{pmatrix} 0.04 & 0.006\\ 0.006 & 0.01 \end{pmatrix}. $$

Find the predicted deviation and standard error at \(x_0=-1\). Assume the conditional distribution is adequately approximated by a bivariate normal distribution.

The predicted deviation is \(-0.08+(-1)(0.05)=-0.13\). Its variance is

$$ \begin{aligned} \widehat{\operatorname{Var}}\{d_j(-1)\} &=0.04+2(-1)(0.006)+(-1)^2(0.01)\\ &=0.04-0.012+0.01\\ &=0.038. \end{aligned} $$

Therefore \(SE=\sqrt{0.038}\approx0.1949\). An approximate 95% pointwise interval is \(-0.13\pm1.96(0.1949)\), or approximately \((-0.5120,0.2520)\). The negative covariate value changes the sign of the covariance contribution because \(2x_0v_{01}<0\). The interval describes uncertainty in the deviation at this particular value, not uncertainty in the slope by itself.

Worked Example: Uncertainty Changes Across Covariate Values

Use the first group’s covariance matrix from the previous example. Compare the variance and standard error of its deviation at \(x_0=0\), \(x_0=2\), and \(x_0=-2\). This comparison shows why a single uncertainty value cannot describe the whole random-slope trajectory.

At \(x_0=0\), only the intercept contributes: the predicted deviation is \(0.12\), the variance is \(0.09\), and \(SE=\sqrt{0.09}=0.3000\).

At \(x_0=2\), the predicted deviation is \(0.12+2(-0.03)=0.06\). As calculated above, its variance is \(0.066\) and \(SE\approx0.2569\).

At \(x_0=-2\), the predicted deviation is \(0.12+(-2)(-0.03)=0.18\), and the variance is

$$ 0.09+2(-2)(-0.01)+(-2)^2(0.004) =0.09+0.04+0.016 =0.146. $$

Thus \(SE=\sqrt{0.146}\approx0.3821\). Uncertainty differs across the three values because both the slope variance contribution and the intercept-slope covariance contribution depend on \(x_0\). The resulting standard errors are pointwise; their pattern does not imply that one value is universally the most informative for every group or model.

Diagnostics, Alternatives, and Limitations

Several checks help catch mistakes before interpreting a result. First, confirm that the random-effect vector and covariance matrix use the same order, here intercept followed by slope. Second, verify the arithmetic by evaluating the matrix product or the expanded variance formula. Third, check that the variance is nonnegative. A covariance matrix should be positive semidefinite, so \(\mathbf{z}^\mathsf{T}\mathbf{V}_j\mathbf{z}\) cannot be negative apart from small numerical error. A materially negative result signals an inconsistent covariance matrix, mismatched entries, or an arithmetic error.

Also check that \(x_0\) is expressed in the model’s covariate units. If the model used a covariate measured in tens of units, entering a raw value measured in single units changes the prediction. Finally, distinguish the group-specific deviation from the full linear predictor: the latter also contains the fixed-effects contribution. The calculation here stays on the link scale. Transforming it to an odds or rate scale requires additional care and is not accomplished by treating the deviation as a response-scale quantity.

A common mistake is to omit the covariance and calculate the variance as \(v_{00}+x_0^2v_{11}\). That is correct only if the conditional covariance is zero (or \(x_0=0\)). In the first example at \(x_0=2\), omitting the covariance would give \(0.09+4(0.004)=0.106\), rather than \(0.066\). The correct calculation includes \(2x_0v_{01}\), which here equals \(-0.04\). The covariance may increase or decrease the variance depending on its sign and the chosen covariate value.

Another error is to report \(\hat b_{1j}\) as the group’s deviation at every covariate value. The slope is the group-specific change in deviation per one-unit increase in \(x\); the deviation at \(x_0\) is \(\hat b_{0j}+x_0\hat b_{1j}\). A third error is to interpret a normal-based interval as including uncertainty in all estimated parameters. The covariance used here quantifies conditional uncertainty in the group’s random-effect vector; uncertainty from estimating fixed effects or variance parameters is a distinct source of uncertainty.

Compared with reporting the predicted random intercept and slope separately, evaluating their linear combination answers a covariate-specific question and properly accounts for their covariance. A new-group prediction instead uses the population distribution of random effects, rather than the observed group’s conditional predicted vector and covariance. When the conditional distribution is noticeably non-normal, an alternative is to calculate the same linear combination for draws from the conditional distribution and summarize those draws; this avoids relying on a symmetric normal interval. These approaches answer different questions, so the target group and source of uncertainty should be stated.

Key takeaway: At a specified covariate value \(x_0\), calculate the predicted deviation as \(\hat b_{0j}+x_0\hat b_{1j}\) and its variance as \(v_{00}+2x_0v_{01}+x_0^2v_{11}\). The covariance term is essential unless it is zero.

Check Your Understanding

For each question, identify the value-specific deviation or uncertainty being requested. Solutions follow the questions.

  1. A group has predicted effects \((0.10,0.04)^\mathsf{T}\). What is its predicted deviation at \(x_0=3\)?
  2. For that group, suppose the conditional covariance matrix is \(\begin{pmatrix}0.04&-0.005\\-0.005&0.002\end{pmatrix}\). Calculate the variance and standard error at \(x_0=3\).
  3. Why is \(v_{00}+x_0^2v_{11}\) generally not the complete variance formula?
  4. What does a pointwise 95% interval for the deviation at \(x_0=1\) describe, and what does it not automatically include?

Solutions. (1) The deviation is \(0.10+3(0.04)=0.22\). (2) The variance is \(0.04+2(3)(-0.005)+3^2(0.002)=0.04-0.03+0.018=0.028\), so the standard error is \(\sqrt{0.028}\approx0.1673\). (3) It omits the covariance contribution \(2x_0v_{01}\), which is nonzero unless the covariance or \(x_0\) is zero. (4) It describes uncertainty in the group’s latent deviation at that specified covariate value under the stated conditional model and interval approximation. It is not automatically a simultaneous interval over covariate values and does not automatically include all parameter-estimation uncertainty.

Clinical Biostats