Tutorials › Generalized Linear Mixed Models (GLMM) › Random Slopes in Zero-Inflated Count Models

Overdispersion and Zero Inflation · Tutorial 548 of 698

Random Slopes in Zero-Inflated Count Models

Learn how a random slope changes group-specific count-rate trajectories in a zero-inflated GLMM and how to distinguish conditional from population-average interpretations.

Advanced 10 min read

What You'll Learn

  • Specify a zero-inflated Poisson GLMM with a group-specific random slope in the count-rate predictor.
  • Interpret fixed and random slopes as changes in the conditional count rate.
  • Derive the marginal mean by integrating over the random intercept and slope.
  • Calculate how random-slope variation changes population-average trajectories.
  • Diagnose when random-slope assumptions or estimation may be unreliable.
  • Compare random-slope models with random-intercept-only and fixed group-specific slope approaches.

Why Allow Group-Specific Slopes?

A random intercept lets groups differ in their baseline count rates while assuming that the count-rate predictor has the same effect in every group. That assumption can be too restrictive when groups follow different trajectories over time or another ordered covariate. In a zero-inflated model, this question concerns the count-rate component: groups may differ in how quickly their rate changes even when the zero-inflation component is modeled separately.

For example, hypothetical clinics might record monthly event counts. Some clinics could have higher underlying rates at the reference month, while others could show faster increases or decreases over months. A group-specific random slope represents that variation. It does not, by itself, give groups different probabilities of structural zeros; that requires a separate model for the zero-inflation component.

Model Definition and Assumptions

Definition: Let \(Y_{ij}\) be the count for observation \(i\) in group \(j\), and let \(x_{ij}\) be a predictor in the count-rate model. A zero-inflated Poisson GLMM with a group-specific random intercept and slope can be written as
$$ \begin{aligned} S_{ij}\mid \mathbf{b}_j &\sim \operatorname{Bernoulli}(\pi_{ij}),\\ Y_{ij}\mid S_{ij}=1,\mathbf{b}_j &=0,\\ Y_{ij}\mid S_{ij}=0,\mathbf{b}_j &\sim \operatorname{Poisson}(\lambda_{ij}),\\ \operatorname{logit}(\pi_{ij})&=\boldsymbol{\gamma}^{\mathsf T}\mathbf{w}_{ij},\\ \log(\lambda_{ij})&=\beta_0+\beta_1x_{ij}+b_{0j}+b_{1j}x_{ij}+\log(e_{ij}),\\ \mathbf{b}_j&= \begin{pmatrix}b_{0j}\\b_{1j}\end{pmatrix} \sim N_2\left( \begin{pmatrix}0\\0\end{pmatrix}, \begin{pmatrix}\sigma_{00}&\sigma_{01}\\ \sigma_{01}&\sigma_{11}\end{pmatrix}\right). \end{aligned} $$
Here \(S_{ij}=1\) indicates a structural zero, \(\pi_{ij}\) is its probability, \(\lambda_{ij}\) is the Poisson rate for observations in the count-generating state, and \(e_{ij}\) is exposure. If exposure is not part of the application, set \(e_{ij}=1\). The vector \(\mathbf{w}_{ij}\) contains predictors for zero inflation; it need not contain the same predictors as the count-rate model.

Conditional on the random effects, observations are assumed independent, and the count-generating state follows a Poisson distribution. Groups are independent draws from the stated bivariate normal distribution. The structural-zero indicator and count-generating process are modeled as specified conditional on the predictors and random effects. In this formulation, the random effects enter the count-rate predictor only; the zero-inflation predictor has no group-specific random effect.

The covariance matrix must be positive semidefinite: its variances are nonnegative and its covariance must satisfy \(\sigma_{01}^2\leq \sigma_{00}\sigma_{11}\). The predictor \(x_{ij}\) should have a meaningful unit, and centering it at a scientifically interpretable reference value often makes the intercept and random-intercept variance easier to understand. The intercept \(b_{0j}\) is the group’s departure at \(x=0\); the slope \(b_{1j}\) is its departure from the population-average slope per one-unit increase in \(x\).

What the Random Slope Means

For a particular group \(j\), the count-rate log slope with respect to \(x\) is \(\beta_1+b_{1j}\), holding other predictors and exposure fixed. Thus, a one-unit increase in \(x\) multiplies that group’s rate in the count-generating state by \(\exp(\beta_1+b_{1j})\). The fixed slope \(\beta_1\) describes the mean of the group-specific slopes on the log scale because \(E(b_{1j})=0\). It does not imply that every group has that slope.

The probability of observing a zero, conditional on the random effects, includes both structural and sampling zeros:

$$ P(Y_{ij}=0\mid \mathbf{b}_j) =\pi_{ij}+(1-\pi_{ij})\exp(-\lambda_{ij}). $$

The conditional expected observed count is \((1-\pi_{ij})\lambda_{ij}\), not \(\lambda_{ij}\). If \(\pi_{ij}\) is fixed as \(x\) changes, the group-specific observed-mean rate ratio per one-unit increase in \(x\) is also \(\exp(\beta_1+b_{1j})\). If the zero-inflation probability changes with \(x\), the observed-mean trajectory reflects both components, and the count-rate slope alone does not describe it.

Worked Example: Specifying Clinic Trajectories

Suppose a hypothetical data set records monthly counts from patients nested within clinics. Let \(x_{ij}\) be months since a defined baseline, centered so that \(x=0\) is the baseline month. Let \(e_{ij}\) be the observation’s exposure in patient-months. A suitable count-rate predictor is

$$ \log(\lambda_{ij})=\beta_0+\beta_1x_{ij}+b_{0j}+b_{1j}x_{ij}+\log(e_{ij}). $$

The exposure offset makes \(\lambda_{ij}\) proportional to the time at risk. The clinic-specific rate ratio for one additional month is \(\exp(\beta_1+b_{1j})\). For example, if \(\beta_1=\log(1.08)\) and a clinic’s slope departure is \(b_{1j}=\log(1.05)\), its monthly rate ratio is

$$ \exp\{\log(1.08)+\log(1.05)\}=1.08(1.05)=1.134. $$

Thus, in this hypothetical model, the clinic’s count-generating rate is multiplied by about 1.134 per month, for the same exposure. The model also allows its baseline rate to differ through \(b_{0j}\). A separate zero-inflation predictor must be specified; this count-rate slope does not assert a clinic-specific trend in structural-zero probability.

Marginal Trajectories Across Groups

A group-specific trajectory conditions on a particular pair \((b_{0j},b_{1j})\). A population-average trajectory instead averages over the distribution of group effects. That average is not obtained simply by setting both random effects to zero: exponentiation makes the average of the rates differ from the rate at the average random effect.

For clarity, hold exposure at one and suppose \(\pi_{ij}=\pi(x)\) does not depend on the random effects. Since \(b_{0j}+b_{1j}x\) is normal with mean zero and variance \(\sigma_{00}+2x\sigma_{01}+x^2\sigma_{11}\), the normal moment-generating function gives the following result.

Result: The expected observed count averaged over the random-effects distribution is
$$ E(Y\mid x) =(1-\pi(x))\exp\left\{ \beta_0+\beta_1x+ \frac{1}{2}\left(\sigma_{00}+2x\sigma_{01}+x^2\sigma_{11}\right) \right\}. $$
For exposure \(e\), multiply the right-hand side by \(e\), provided the offset is \(\log(e)\).

To justify the result, conditional on \(b_{0j},b_{1j}\), the expected count is \((1-\pi(x))\lambda\). Averaging over the random effects therefore requires the expectation of \(\exp(b_{0j}+b_{1j}x)\). This linear combination is normal with variance \(v(x)=\sigma_{00}+2x\sigma_{01}+x^2\sigma_{11}\). If \(U\sim N(0,v)\), then \(E\{\exp(U)\}=\exp(v/2)\), giving the displayed formula. The slope variance contributes a quadratic term in \(x\), so even a linear conditional predictor can imply a curved marginal mean trajectory.

Worked Example: Computing a Population-Average Mean

Consider a hypothetical model with \(\beta_0=\log(2)\), \(\beta_1=\log(1.25)\), \(\pi(x)=0.20\), unit exposure, and random-effects covariance values \(\sigma_{00}=0.16\), \(\sigma_{01}=-0.03\), and \(\sigma_{11}=0.04\). Calculate the marginal expected observed count at \(x=2\).

First, the random-effects variance at \(x=2\) is

$$ v(2)=0.16+2(2)(-0.03)+(2^2)(0.04)=0.16-0.12+0.16=0.20. $$

The fixed part of the count-rate predictor gives \(\exp\{\beta_0+2\beta_1\}=2(1.25)^2=3.125\). Integrating over random effects multiplies this by \(\exp(0.20/2)=\exp(0.10)\). The population-average count-generating rate is therefore

$$ 3.125\exp(0.10)=3.454. $$

Finally, the expected observed count is

$$ E(Y\mid x=2)=0.80(3.454)=2.763. $$

This is an average expected count per observation at unit exposure under the stated model. It is not the rate for every group; individual groups have their own random intercepts and slopes.

Fitting, Checking, and Comparing Models

Estimation must account for the fact that the group effects are unobserved. In likelihood-based fitting, the group-specific likelihood contribution is averaged over the assumed distribution of \((b_{0j},b_{1j})\); this generally requires numerical integration or approximation. The fitted random slope is therefore a population-distribution parameter, not a directly observed slope for each group. Group-specific estimates are typically shrunken toward the population mean, with the amount of shrinkage depending on the information in that group.

Check whether the model’s structure is plausible as well as whether the optimizer reports convergence. Useful checks include:

  • Inspect convergence messages and sensitivity to reasonable changes in optimizer settings. A convergence warning means the reported estimates and uncertainty may not be trustworthy.
  • Examine the estimated random-slope variance and the intercept-slope correlation. A variance near zero or a correlation near \(-1\) or \(1\) can indicate a boundary or weakly supported covariance structure.
  • Compare observed and model-predicted counts across the range of \(x\), across groups, and across exposure levels. Systematic trajectory patterns suggest that the mean structure may be inadequate.
  • Check whether the model reproduces the frequency of zeros and the distribution of positive counts in relevant predictor ranges. A poor match can indicate misspecification, though a discrepancy does not identify a unique cause.
  • Consider whether group trajectories are reasonably represented by a bivariate normal distribution and whether observations are conditionally independent after accounting for the modeled predictors and group effects.

These checks diagnose potential problems; none proves that the random-effects distribution or zero-inflation structure is correct. A small number of groups, little within-group variation in \(x\), or a narrow range of \(x\) can make slope variation difficult to estimate. A technically successful fit does not compensate for inadequate information in the design.

The main alternative is a random-intercept-only zero-inflated GLMM, which is more parsimonious but assumes a common count-rate slope across groups. A model with a separate fixed slope for every group allows unrestricted group-specific slopes, but uses many parameters and does not describe those slopes as draws from a shared population distribution. A random-slope model is useful when groups are viewed as drawn from a population and partial pooling is appropriate. These are different assumptions, not interchangeable ways to obtain the same interpretation.

A random slope also has limits. It does not correct an incorrectly specified zero-inflation predictor, establish that zeros are truly structural, or guarantee that a Poisson count distribution is adequate. It represents a particular kind of between-group heterogeneity: variation in the count-rate relationship with \(x\). The random-effects assumptions and the conditional Poisson assumption should be justified in the application rather than treated as consequences of adding a slope.

Common Mistake

Common mistake: “The fixed slope is the rate ratio for every group, and the population-average trajectory is found by setting the random effects to zero.”

Correction: The group-specific log slope is \(\beta_1+b_{1j}\), so groups can have different rate ratios. Setting random effects to zero gives the conditional trajectory for a group at the center of the random-effects distribution. The population-average mean requires integrating over that distribution, which adds the variance adjustment shown above.

Worked Example: Comparing Two Marginal Means

Use the hypothetical parameters from the preceding example to compare the population-average expected observed counts at \(x=0\) and \(x=2\). At \(x=0\), \(v(0)=0.16\), so

$$ E(Y\mid x=0)=0.80\exp\{\log(2)+0.16/2\} =0.80(2)\exp(0.08)=1.733. $$

At \(x=2\), the marginal mean was \(2.763\). The ratio is \(2.763/1.733=1.594\). This differs from the fixed-effects rate ratio across the two-unit change, \(1.25^2=1.563\), because the random-effects variance changes with \(x\): it is \(0.16\) at \(x=0\) and \(0.20\) at \(x=2\). In fact, the marginal ratio is

$$ \exp\left\{2\beta_1+\frac{1}{2}[v(2)-v(0)]\right\} =(1.25)^2\exp(0.02)=1.594. $$

The zero-inflation probability is constant here, so its factor \(0.80\) cancels in the ratio. This comparison shows why a conditional slope and a population-average change answer related but distinct questions.

Check Your Understanding

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

  1. In the model, what is the group-specific count-rate ratio for a one-unit increase in \(x\)?
  2. If \(\sigma_{00}=0.09\), \(\sigma_{01}=0.01\), and \(\sigma_{11}=0.04\), calculate the random-effects variance at \(x=1\).
  3. Why does setting the random effects to zero not generally give the population-average count?
  4. If the random-slope variance is estimated near zero, what feature of the model is receiving little support from the data?

Solutions. (1) The group-specific ratio is \(\exp(\beta_1+b_{1j})\), conditional on the group effect and holding other predictors and exposure fixed. (2) \(v(1)=0.09+2(1)(0.01)+(1)^2(0.04)=0.15\). (3) The expected rate involves averaging an exponential over normally distributed random effects; \(E\{\exp(U)\}=\exp\{\operatorname{Var}(U)/2\}\) when \(U\) has mean zero, so the average is not generally the rate evaluated at \(U=0\). (4) The data provide little support for between-group variation in the count-rate slope. This does not by itself establish that all groups truly share an identical slope, especially if the design has few groups or limited within-group variation in \(x\).

Clinical Biostats