Tutorials › Generalized Linear Mixed Models (GLMM) › Worked Prior Design for a Random-Slope GLMM

Bayesian GLMM and Prior Specification for Variance Components · Tutorial 264 of 698

Worked Prior Design for a Random-Slope GLMM

You will learn to choose interpretable random-effect scale and correlation priors, and to diagnose them by simulating group effects and outcomes over the predictor values your study can encounter.

Advanced 10 min read

What You'll Learn

  • Specify a random-intercept and random-slope logistic GLMM with a scale-correlation covariance decomposition.
  • Relate predictor centering and units to the meaning of random-effect scales and correlations.
  • Distinguish conditional normal calculations from marginal calculations under random scale priors.
  • Simulate prior-predictive group effects, probabilities, and binary outcomes.
  • Diagnose implausible prior implications and compare correlated and independent random-effect specifications.

Designing a Prior for a Random-Slope GLMM

A random-slope prior can look mild when described by a scale parameter yet imply large group-to-group differences at predictor values far from the center. The relevant question is not only whether a prior scale seems small. It is whether the induced linear predictors and response probabilities are plausible over the predictor range the study may encounter. This tutorial develops a design-and-check workflow for a logistic random-slope GLMM.

Model: For group \(j=1,\ldots,J\) and observation \(i\) in group \(j\), let \(Y_{ij}\mid b_j,\beta_0,\beta_1\sim\operatorname{Bernoulli}(p_{ij})\), with $$ \operatorname{logit}(p_{ij})=\beta_0+\beta_1x_{ij}+b_{0j}+b_{1j}x_{ij}, \qquad b_j= \begin{pmatrix} b_{0j}\\ b_{1j} \end{pmatrix} \mid \Sigma \sim N_2(0,\Sigma). $$ Here \(b_{0j}\) is a group-specific intercept deviation and \(b_{1j}\) is a group-specific slope deviation. Conditional on the parameters and group effects, responses are independent Bernoulli variables. The groups’ random-effect vectors are independently drawn from the same bivariate normal distribution.

A useful parameterization separates the random-effect scales from their correlation:

$$ \Sigma = \begin{pmatrix} \tau_0 & 0\\ 0 & \tau_1 \end{pmatrix} \begin{pmatrix} 1 & \rho\\ \rho & 1 \end{pmatrix} \begin{pmatrix} \tau_0 & 0\\ 0 & \tau_1 \end{pmatrix} = \begin{pmatrix} \tau_0^2 & \rho\tau_0\tau_1\\ \rho\tau_0\tau_1 & \tau_1^2 \end{pmatrix}. $$

The scales \(\tau_0,\tau_1\) are nonnegative and measured in log-odds and log-odds per unit of \(x\), respectively. The correlation \(\rho\) lies between \(-1\) and \(1\). A typical starting specification might use independent half-normal priors on the scales, \(\tau_0\sim\operatorname{HalfNormal}(0,s_0)\) and \(\tau_1\sim\operatorname{HalfNormal}(0,s_1)\), together with an LKJ prior on the correlation matrix. These are design choices, not universal defaults: the scales \(s_0,s_1\), the prior on \(\rho\), and the units and centering of \(x\) should be considered together.

Start with the Predictor Scale

The value \(x=0\) determines what the random intercept represents: it is the group deviation at that predictor value. If zero is outside the observed or scientifically plausible range, center \(x\) at a meaningful value, such as the study’s reference exposure or midpoint. Rescaling \(x\) also changes the interpretation of \(\tau_1\). If \(x\) is changed from years to decades, for example, the random-slope scale per unit changes by a factor of ten.

Before selecting a prior, write down a plausible predictor range, including values that may occur in future predictions. Then consider the group-specific contribution \(b_{0j}+b_{1j}x\) across that range, not just the scale of \(b_{1j}\) at one unit of \(x\).

Worked Example: A Random-Slope Scale Is Not a Marginal Normal Quantile

Suppose \(x\) is centered and scaled so that plausible values run from \(-2\) to \(2\). Consider \(\tau_1\sim\operatorname{HalfNormal}(0,0.25)\), with \(b_{1j}\mid\tau_1\sim N(0,\tau_1^2)\). What does this say about slope variation at \(x=2\)?

The half-normal scale parameter is \(0.25\). Its 90th percentile is \(1.645(0.25)=0.411\), since \(P(\tau_1\leq t)=2\Phi(t/0.25)-1\) for \(t\geq0\). This is a statement about the prior distribution of \(\tau_1\), not a 90th percentile for \(b_{1j}\).

If we condition on the particular value \(\tau_1=0.25\), then \(2b_{1j}\mid\tau_1=0.25\sim N(0,0.50^2)\). Its conditional 90th percentile in absolute value is \(1.645(0.50)=0.823\) log-odds. This calculation is correct only conditional on fixing \(\tau_1=0.25\).

Under the stated prior, \(\tau_1\) is random, so the marginal distribution of \(2b_{1j}\) is a scale mixture of normals. Its absolute-value distribution satisfies $$ P(|2b_{1j}|\leq q) = E_{\tau_1}\left[2\Phi\left(\frac{q}{2\tau_1}\right)-1\right], \qquad q\geq0. $$ The marginal 90th percentile must be found by solving this equation for probability \(0.90\), or by prior simulation. It is not obtained as \(1.645\) times the marginal standard deviation. In fact, the marginal standard deviation is \(2(0.25)=0.50\), because \(E(\tau_1^2)=0.25^2\), but that variance alone does not determine the mixture’s quantiles.

Understand the Correlation Across the Range

Conditional on the scales and correlation, the variance of the group-specific random contribution at predictor value \(x\) is

$$ \operatorname{Var}(b_{0j}+xb_{1j}\mid\tau_0,\tau_1,\rho) =\tau_0^2+x^2\tau_1^2+2x\rho\tau_0\tau_1. $$

This follows by expanding the variance of a sum: \(\operatorname{Var}(b_0)+x^2\operatorname{Var}(b_1)+2x\operatorname{Cov}(b_0,b_1)\), with \(\operatorname{Cov}(b_0,b_1)=\rho\tau_0\tau_1\). The cross-term changes sign with \(x\). Thus, a negative correlation can reduce between-group spread on one side of zero and increase it on the other. Correlation is not merely a technical feature of \(\Sigma\); it shapes the pattern of group trajectories.

Worked Example: Checking a Correlation at Both Ends of the Range

Take conditional values \(\tau_0=0.50\), \(\tau_1=0.20\), and \(\rho=-0.60\). Compare the random-contribution standard deviation at \(x=-2\) and \(x=2\).

At \(x=2\), the conditional variance is $$ 0.50^2+2^2(0.20^2)+2(2)(-0.60)(0.50)(0.20) =0.25+0.16-0.24=0.17. $$ The standard deviation is \(\sqrt{0.17}=0.412\) log-odds.

At \(x=-2\), the cross-term changes sign: $$ 0.50^2+(-2)^2(0.20^2)+2(-2)(-0.60)(0.50)(0.20) =0.25+0.16+0.24=0.65. $$ The standard deviation is \(\sqrt{0.65}=0.806\) log-odds. The same conditional scales and correlation therefore imply substantially more variation at \(x=-2\) than at \(x=2\). These are conditional calculations at the stated parameter values; if the scales and correlation themselves have priors, marginal prior-predictive summaries also average over those priors.

For two random effects, an LKJ prior with shape parameter \(\eta\) gives a density for the correlation matrix proportional to \(|R|^{\eta-1}\); here \(|R|=1-\rho^2\). An LKJ(1) prior is uniform over correlation matrices, and larger \(\eta\) places relatively more density near zero correlation. This does not guarantee that the induced trajectories are plausible. Check the implied range-specific spread and simulated outcomes as well.

Simulate Prior-Predictive Outcomes

A prior-predictive check draws parameters from the proposed priors, draws group effects conditional on those parameters, and then draws responses from the GLMM. It asks whether the model and priors, before seeing the study outcomes, generate patterns that could reasonably have occurred in the intended setting. Include uncertainty in fixed effects as well as in variance components. For example, one might use \(\beta_0\sim N(\operatorname{logit}(0.20),0.5^2)\) and \(\beta_1\sim N(0,0.35^2)\), but the centers and scales must reflect substantive expectations about the baseline probability and average log-odds change.

1
Specify the input range.
List the observed and scientifically plausible future values of \(x\), in the units that will be used in the model. Check that zero has a meaningful interpretation.
2
Draw prior parameters.
For each simulation, draw \(\beta_0,\beta_1,\tau_0,\tau_1,\rho\) from their proposed priors and construct \(\Sigma\).
3
Draw group effects and probabilities.
Draw \(b_j\sim N_2(0,\Sigma)\), calculate \(\eta_{ij}=\beta_0+\beta_1x_{ij}+b_{0j}+b_{1j}x_{ij}\), and set \(p_{ij}=\operatorname{logit}^{-1}(\eta_{ij})\).
4
Draw outcomes and inspect summaries.
Draw \(Y_{ij}\sim\operatorname{Bernoulli}(p_{ij})\). Summarize probability ranges, event counts, all-zero or all-one groups, and group-specific trends over \(x\).

Worked Example: Evaluating Simulated Probabilities Across the Range

Consider one illustrative prior draw with \(\beta_0=-1.40\), \(\beta_1=0.30\), \(b_{0j}=0.20\), and \(b_{1j}=-0.10\). These are hypothetical values used to show the calculation, not estimates from data. For this group, calculate the probabilities at \(x=-1,0,1,2\).

At \(x=-1\), \(\eta=-1.40+0.30(-1)+0.20+(-0.10)(-1)=-1.40\), so \(p=\operatorname{logit}^{-1}(-1.40)=0.198\). At \(x=0\), \(\eta=-1.40+0.20=-1.20\), giving \(p=0.231\). At \(x=1\), \(\eta=-1.40+0.30+0.20-0.10=-1.00\), giving \(p=0.269\). At \(x=2\), \(\eta=-1.40+0.60+0.20-0.20=-0.80\), giving \(p=0.310\).

The group-specific slope is \(\beta_1+b_{1j}=0.20\) log-odds per unit of \(x\), so this draw has increasing probability across the listed range. A full prior-predictive simulation must also include draws with other parameter values, as well as Bernoulli outcome noise. Inspecting many such trajectories can reveal, for example, prior mass on nearly certain events or sharply changing probabilities that are not plausible for the application.

How to Revise a Prior and What to Compare

If prior simulations generate implausible probabilities, first identify where the extremity originates. Large group differences near the edges may reflect an overly broad \(\tau_1\) prior, an uncentered or poorly scaled predictor, a correlation prior that allows strong directional association, or wide fixed-effect priors. Changing the random-slope scale may not solve implausible baseline probabilities caused by \(\beta_0\). Make one targeted change at a time and rerun the same prior-predictive checks.

The main alternative to a correlated random intercept and slope is to set \(\rho=0\). This removes the cross-term and assumes the random intercept and slope are conditionally independent under the bivariate normal model. It can be a useful simpler specification, but it is not a neutral numerical convenience: it rules out a systematic relationship between a group’s baseline deviation and its slope deviation. A correlated specification is more flexible but may be weakly informed when the number of groups is small. The introductory material on prior-predictive checks for random-effect variability and the earlier material on joint scale and correlation priors provide useful context for interpreting these choices.

Several limitations remain. Prior-predictive plausibility depends on the scenarios and predictor values simulated; a sparse observed range does not justify ignoring plausible extrapolation. A prior that generates sensible marginal probabilities can still imply unrealistic within-group patterns, so inspect trajectories and group summaries as well as pooled distributions. Finally, simulation does not establish that a prior is correct. It makes the consequences visible so that the specification can be defended, revised, and later subjected to sensitivity analysis.

Common Pitfall

  • Wrong reasoning: “The random-slope scale has a half-normal prior with scale \(0.25\), so at \(x=2\) the 90th percentile of the absolute slope contribution is \(1.645(2)(0.25)=0.823\).” This treats the random scale as fixed at \(0.25\).
  • Correction: \(0.823\) is the conditional 90th percentile given \(\tau_1=0.25\). When \(\tau_1\) is random, the effect has a mixture distribution. Compute its quantile by integrating over the scale prior or by simulation, and label any fixed-scale calculation as conditional.
  • Another warning: A plausible prior on each scale separately does not ensure plausible probabilities jointly. Check the full model, including fixed effects, correlation, predictor range, and outcome sampling.
Key takeaway: Design random-slope priors on a meaningful predictor scale, examine conditional spread across that scale, and use prior-predictive simulation to assess the resulting probabilities and outcomes. Never substitute a fixed-scale normal quantile for a quantile from a random-scale mixture.

Check Your Understanding

Answer each question, then compare with the compact solutions.

  1. If \(x\) is recentered so that \(x=0\) represents a different reference value, which random-effect interpretation changes?
  2. For \(\tau_0=0.4\), \(\tau_1=0.1\), and \(\rho=0\), calculate the conditional variance of \(b_{0j}+xb_{1j}\) at \(x=3\).
  3. Why is \(1.645\) times the marginal standard deviation generally not the 90th percentile of \(|x b_{1j}|\) when \(\tau_1\) has a nondegenerate prior?
  4. Name two distinct prior-predictive summaries that could reveal implausible logistic GLMM behavior.

Solutions. (1) The random intercept becomes the group deviation at the new \(x=0\) reference value; the slope remains the change per unit of \(x\), provided units are unchanged. (2) With zero correlation, the variance is \(0.4^2+3^2(0.1^2)=0.16+0.09=0.25\) log-odds squared. (3) Mixing over random scales produces a scale mixture of normals, which is generally not normal; its quantile must be integrated or simulated. (4) Examples include the distribution of probabilities across the predictor range, the number of events per group, the frequency of all-zero groups, and simulated group-specific trajectories.

Clinical Biostats