Tutorials › Nonlinear Mixed-Effects Models (NLME) › Gaussian Random-Effects Forecasts as a Conjugate Benchmark

Uncertainty in Individual Predictions · Tutorial 751 of 797

Gaussian Random-Effects Forecasts as a Conjugate Benchmark

Learn to derive and calculate posterior random-effect and future-response distributions under a Gaussian linear mixed model, and use them as benchmarks for individual forecasts.

Advanced 11 min read

What You'll Learn

  • State the assumptions that make a linear mixed-effects forecast Gaussian and conjugate.
  • Derive the posterior mean and covariance of individual random effects from observed responses.
  • Calculate a future-response distribution and distinguish it from a forecast of the latent mean.
  • Work through scalar, random-slope, and random-intercept-and-slope examples.
  • Use the closed-form result to check numerical forecasts and recognize when its assumptions fail.

Why Use a Gaussian Benchmark?

Individual forecasts can require substantial computation when the response model is nonlinear or its uncertainty must be propagated numerically. A useful reference case is a model that is linear in Gaussian random effects and has Gaussian residual errors. With its population parameters treated as known, both the posterior distribution of an individual’s random effects and the predictive distribution of a future response have closed forms. These results make it possible to check numerical forecasts in simple cases and to see precisely how observed data update individual-level predictions.

This benchmark is deliberately narrower than a general nonlinear mixed-effects analysis. The response must be linear in the random effects, and the random-effect and residual covariance matrices are treated as known. The formulas do not automatically account for uncertainty in estimated population parameters.

Definition: Consider the linear mixed model \(y=X\beta+Zb+\varepsilon\), where \(y\) is a vector of observed responses, \(X\) and \(Z\) are known design matrices, \(\beta\) is a fixed-effect vector, and \(b\) is an individual random-effect vector. Assume \(b\sim N(0,G)\), \(\varepsilon\sim N(0,R)\), and \(b\) and \(\varepsilon\) are independent. Here \(G\) and \(R\) are known covariance matrices, with \(G\) positive definite and \(R\) positive definite. Conditional on the observed \(y\), the distribution of \(b\) is its posterior distribution under this model.

In this tutorial, \(\beta\), \(G\), and \(R\) are treated as fixed and known. The observations are generated under the stated model, and the future residual errors are assumed independent of the observed residual errors and of the random effects. These conditions are what permit the simple conjugate calculations below. If residual errors are correlated across observation times, their joint covariance must instead be represented and conditioned on.

Posterior Distribution of the Random Effects

Write \(r=y-X\beta\) for the observed responses after subtracting their fixed-effect contribution. The likelihood for \(b\) is Gaussian, with mean \(Zb\) for \(r\) and covariance \(R\). Multiplying this likelihood by the Gaussian prior for \(b\) gives a Gaussian posterior.

Theorem: Under the stated model, the posterior distribution of \(b\) given \(y\) is \(N(m,C)\), where
$$ C=(G^{-1}+Z^\mathsf{T}R^{-1}Z)^{-1}, \qquad m=CZ^\mathsf{T}R^{-1}(y-X\beta). $$

The matrix \(C\) is the posterior covariance, and \(m\) is the posterior mean. The observed residuals \(y-X\beta\) inform the random effects through \(Z^\mathsf{T}R^{-1}(y-X\beta)\); observations with lower residual variance receive more weight through \(R^{-1}\). The prior contributes the precision matrix \(G^{-1}\), so the posterior reflects both the population distribution and the individual’s data.

Why the Posterior Is Gaussian

The result follows by completing the square in the exponent of the joint prior and likelihood. Ignoring factors that do not depend on \(b\), their product is proportional to

$$ \exp\left\{-\frac{1}{2} \left[b^\mathsf{T}G^{-1}b+ (r-Zb)^\mathsf{T}R^{-1}(r-Zb)\right]\right\}. $$

Expanding the quadratic expression gives

$$ b^\mathsf{T}(G^{-1}+Z^\mathsf{T}R^{-1}Z)b -2b^\mathsf{T}Z^\mathsf{T}R^{-1}r +r^\mathsf{T}R^{-1}r. $$

Set \(C=(G^{-1}+Z^\mathsf{T}R^{-1}Z)^{-1}\) and \(m=CZ^\mathsf{T}R^{-1}r\). Then the terms depending on \(b\) can be written as

$$ (b-m)^\mathsf{T}C^{-1}(b-m). $$

Indeed, its quadratic term is \(b^\mathsf{T}C^{-1}b\), and its linear term is \(-2b^\mathsf{T}C^{-1}m=-2b^\mathsf{T}Z^\mathsf{T}R^{-1}r\). The remaining term does not depend on \(b\) and is absorbed into the normalizing constant. This is the kernel of a multivariate normal distribution with mean \(m\) and covariance \(C\), proving the result.

From the Posterior to a Future Forecast

Let \(y_*\) be a vector of future responses for the same individual. Suppose its model is \(y_*=X_*\beta+Z_*b+\varepsilon_*\), where the future design matrices are known and \(\varepsilon_*\sim N(0,R_*)\). Assume \(\varepsilon_*\) is independent of \(b\) and of the residual errors in the observed data. Conditional on \(y\), the uncertain random effects have distribution \(N(m,C)\), while the future residuals remain independent Gaussian errors.

Theorem: Under these assumptions, the future responses conditional on the observed data have predictive distribution
$$ y_*\mid y\sim N\left(X_*\beta+Z_*m,\;Z_*CZ_*^\mathsf{T}+R_*\right). $$

The predictive mean substitutes the posterior mean of the random effects into the future model. The predictive covariance has two parts: \(Z_*CZ_*^\mathsf{T}\), uncertainty about the individual random effects after seeing the data, and \(R_*\), future residual variation. If the target is instead the latent future mean \(X_*\beta+Z_*b\), rather than a future observed response, omit \(R_*\). Confusing these two targets produces forecasts with the wrong variance.

The result follows because a linear transformation of a Gaussian vector is Gaussian. Given \(y\), \(Z_*b\) has mean \(Z_*m\) and covariance \(Z_*CZ_*^\mathsf{T}\). Adding the independent Gaussian error \(\varepsilon_*\) adds its covariance \(R_*\), giving the stated mean and covariance.

Worked Example: Updating a Random Intercept and Forecasting a Measurement

Suppose hypothetical concentrations follow \(y_i=10+b+\varepsilon_i\), measured in mg/L, with \(b\sim N(0,4)\) and independent \(\varepsilon_i\sim N(0,1)\). The population mean, prior variance, and residual variance are treated as known. An individual has two observed concentrations, 12 and 11 mg/L. Find the posterior distribution of \(b\), then forecast one future observed concentration under the same conditions.

Here \(G=4\), \(R=I\), and both rows of \(Z\) equal 1. The observed residuals relative to the fixed mean are \(12-10=2\) and \(11-10=1\). Thus

$$ C=\left(\frac{1}{4}+1+1\right)^{-1} =\frac{4}{9}=0.4444\;(\mathrm{mg/L})^2, \qquad m=C(2+1)=\frac{4}{3}=1.333\;\mathrm{mg/L}. $$

Therefore \(b\mid y\sim N(1.333,0.4444)\), with the mean in mg/L and variance in \((\mathrm{mg/L})^2\). The future response has fixed mean 10 mg/L, random-effect loading 1, and residual variance 1 \((\mathrm{mg/L})^2\). Its predictive distribution is

$$ y_*\mid y\sim N\left(10+\frac{4}{3},\frac{4}{9}+1\right) =N(11.333,1.444)\;, $$

where the first argument is in mg/L and the second is in \((\mathrm{mg/L})^2\). The predictive standard deviation is \(\sqrt{1.444}=1.202\) mg/L. For example, a central 90% predictive interval, using the standard-normal quantile 1.645, is \(11.333\pm1.645(1.202)\), or approximately 9.356 to 13.311 mg/L. This interval concerns a future observed concentration under the model, not a 90% probability statement about a fixed unknown parameter.

Worked Example: Forecasting With a Random Slope

In a hypothetical linear model, an observed response at covariate value \(x=1\) is \(y=8+b+\varepsilon\), where \(b\sim N(0,9)\) and \(\varepsilon\sim N(0,4)\). The observed response is 14 units. Forecast the future observed response at \(x=2\), where the model is \(y_*=20+2b+\varepsilon_*\) and \(\varepsilon_*\sim N(0,1)\), independently of the observed error.

The observed residual relative to the fixed part is \(14-8=6\). The posterior variance and mean of the random slope are

$$ C=\left(\frac{1}{9}+\frac{1^2}{4}\right)^{-1} =\frac{36}{13}=2.769, \qquad m=C\frac{1(6)}{4} =\frac{54}{13}=4.154. $$

The future random-effect contribution is \(2b\), so its conditional mean is \(2m=108/13=8.308\), and its conditional variance is \(2^2C=144/13=11.077\). Adding the future residual variance gives

$$ y_*\mid y\sim N\left(20+\frac{108}{13},\frac{144}{13}+1\right) =N(28.308,157/13). $$

The predictive variance is \(12.077\) response-units squared, and the predictive standard deviation is \(\sqrt{157/13}=3.475\) units. The factor \(2^2\) is essential: uncertainty in a random slope is amplified when forecasting at \(x=2\).

Worked Example: A Random-Intercept-and-Slope Benchmark

Suppose two hypothetical responses have their fixed effects subtracted, leaving residuals \(r=(2,1)^\mathsf{T}\). The random intercept and slope are \(b=(b_0,b_1)^\mathsf{T}\sim N(0,G)\), with \(G=\operatorname{diag}(4,1)\). The design matrix is \(Z=\begin{pmatrix}1&0\\1&1\end{pmatrix}\), and \(R=I\). Forecast a future observed response whose fixed-effect contribution is 10 and random-effect row is \(Z_*=(1,2)\), with future residual variance 1.

The posterior precision matrix is

$$ C^{-1}=G^{-1}+Z^\mathsf{T}Z =\begin{pmatrix}1/4&0\\0&1\end{pmatrix} +\begin{pmatrix}2&1\\1&1\end{pmatrix} =\begin{pmatrix}9/4&1\\1&2\end{pmatrix}. $$

Its determinant is \((9/4)(2)-1=7/2\), so

$$ C=\frac{1}{7/2} \begin{pmatrix}2&-1\\-1&9/4\end{pmatrix} =\begin{pmatrix}4/7&-2/7\\-2/7&9/14\end{pmatrix}. $$

Also, \(Z^\mathsf{T}r=(3,1)^\mathsf{T}\), and hence

$$ m=CZ^\mathsf{T}r =\begin{pmatrix}10/7\\-3/14\end{pmatrix}. $$

The future predictive mean is \(10+Z_*m=10+10/7-3/7=11\). Its variance is \(Z_*CZ_*^\mathsf{T}+1=2+1=3\): specifically, \(Z_*CZ_*^\mathsf{T}=4/7-8/7+18/7=2\). Thus \(y_*\mid y\sim N(11,3)\). A numerical forecasting routine applied to this same model and inputs should return these mean and variance values, up to rounding.

Using the Benchmark and Recognizing Its Limits

A closed-form forecast is useful as a validation case: enter the same design matrices, prior covariance, residual covariance, and conditioning observations into a numerical procedure, then compare its posterior mean and covariance with the formulas above. Agreement checks the implementation for this Gaussian linear case. It does not establish that the numerical procedure is correct for every nonlinear model or every uncertainty source.

A frequent mistake is to forecast only at the posterior mean random effect and report the future residual variance as the total predictive variance. In the random-intercept example, that would give variance 1 rather than \(1+4/9=1.444\;(\mathrm{mg/L})^2\). The omitted \(4/9\) is uncertainty about the individual effect. Conversely, if the target is the latent mean and not a future measured response, adding residual variance would include variation that is not part of the target.

Other checks follow directly from the assumptions and formulas:

  • Check the target and units. The forecast mean must be on the response scale, and its variance must be in squared response units.
  • Check covariance contributions. The posterior covariance \(C\) and future error covariance \(R_*\) must be positive semidefinite; a materially negative predictive variance signals an implementation or input problem.
  • Check the design. Random-effect loadings in \(Z_*\) determine how posterior uncertainty carries into the forecast. A missing or incorrectly scaled loading can substantially change the variance.
  • Check the model fit and assumptions. Strong residual patterns, outliers, nonconstant residual variance, or responses incompatible with a Gaussian model can make the benchmark inappropriate.

The conditional mean \(m\) is a posterior point estimate of the random effects. Using only this estimate gives a plug-in forecast, while the full predictive distribution also propagates posterior random-effect uncertainty and future residual variation. Simulation or numerical integration may be needed when the response is nonlinear in random effects, the relevant distributions are not Gaussian, or the desired forecast includes uncertainty not represented by the known \(\beta\), \(G\), and \(R\). In particular, these formulas do not include uncertainty from estimating those population parameters.

Key takeaway: With known population parameters, Gaussian random effects, Gaussian independent residual errors, and a response linear in the random effects, the individual posterior and future predictive distribution are Gaussian. The predictive covariance includes both the propagated posterior random-effect covariance and future residual covariance.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. If the forecast target is a latent future mean rather than a future observed response, which covariance term is omitted?
  2. In a scalar random-intercept model with prior variance 4 and two independent observations each with residual variance 1, what is the posterior variance?
  3. For a future response with random-effect loading 3, how does the posterior variance \(C\) contribute to predictive variance?
  4. Name two assumptions that would prevent direct use of the stated closed-form predictive formula.

Solutions. (1) Omit \(R_*\), because latent means do not include future residual error. (2) The posterior variance is \((1/4+1+1)^{-1}=4/9\). (3) The contribution is \(3^2C=9C\). (4) Examples include a nonlinear response in the random effects, non-Gaussian random effects, or residual errors correlated between observed and future responses when that correlation is not represented in the model.