Why Condition on Random Effects?
A generalized linear mixed model (GLMM) describes responses using a generalized linear model conditional on random effects. This conditioning matters: observations in the same cluster can have different response distributions because they share a latent cluster-level quantity. The model first specifies what the response distribution and mean are given that quantity. A mean averaged over the random effects is a different target, obtained by averaging the conditional mean over their distribution.
The distinction is not merely wording. With a nonlinear link, averaging a conditional mean does not usually give the mean obtained by setting the random effect to its average. Thus, a link-scale prediction for a particular random-effect value and a population-average response mean should not be treated as interchangeable.
The choice of response family determines the conditional distribution and its relationship to the conditional mean. For example, a Bernoulli response has a conditional success probability as its mean; a Poisson response has a conditional count mean. The link then relates that mean to the linear predictor. The family and link must be compatible with the response: for example, a Bernoulli mean must lie between zero and one, while a Poisson mean must be positive.
The fixed effects and random effects enter the same conditional linear predictor, but play different roles. The fixed part \(x_{ij}^{\mathsf T}\beta\) is shared according to the specified covariates; \(z_{ij}^{\mathsf T}b_i\) allows the conditional predictor to vary with the cluster's random effects. This tutorial uses that general structure without requiring a particular random-effect design.
Conditional and Averaged Means
For a fixed value of \(b_i\), the conditional mean is obtained by applying the inverse link \(h=g^{-1}\) to the conditional linear predictor:
This is a mean conditional on the random effect, not a mean that has averaged over the random-effect distribution. If the target is the mean across that distribution, the corresponding expression is
The averaging is on the response-mean scale, after applying the inverse link. In general, this is not \(h\{x_{ij}^{\mathsf T}\beta+z_{ij}^{\mathsf T}E(b_i)+o_{ij}\}\). Nonlinearity is the key reason these quantities differ. If \(h\) is linear and \(E(b_i)=0\), they coincide; with nonlinear links, zero-mean random effects alone do not make them equal.
Worked Conditional Models
Worked Example: A Conditional Bernoulli Probability
Suppose a hypothetical binary response \(Y_{ij}\) records whether a patient meets a defined outcome (\(1\) for yes, \(0\) for no). Consider a Bernoulli conditional response model with a logit link and predictor
For an illustrative covariate value \(x_{ij}=2\) and random-effect value \(b_i=0.3\), the conditional linear predictor is
The inverse logit gives the conditional success probability:
Thus, under the stated model, the conditional probability of the outcome is about 0.574 for a unit with these covariate and random-effect values. If the response is observed to be \(Y_{ij}=1\), its conditional Bernoulli likelihood contribution is \(0.5744\); if it is \(0\), that contribution is \(1-0.5744=0.4256\). The Bernoulli family is appropriate here because the response is binary, and the logit link maps any finite predictor to a probability strictly between zero and one. This calculation is conditional on \(b_i=0.3\); it has not averaged across a distribution of random effects.
Worked Example: A Conditional Poisson Mean With an Offset
Suppose a hypothetical model describes the number of events during an observation period of \(t_{ij}\) weeks. Let \(x_{ij}\) be a covariate and use a Poisson response with a log link and an exposure offset:
For \(t_{ij}=3\) weeks, \(x_{ij}=1\), and \(b_i=-0.2\), substitute the values into the predictor:
Exponentiating gives the conditional mean count:
The model therefore assigns an expected count of about 4.050 events over the three-week period, conditional on the stated covariate and random-effect values. The response is a nonnegative count, the Poisson mean is positive, and the log link ensures a positive mean. Under the stated Poisson conditional distribution, the conditional variance also equals \(4.050\). The offset \(\log(3)\) accounts for the observation duration; it is not an estimated coefficient. The result is still a conditional mean, not an average over \(b_i\).
Why Averaging Changes the Answer
The distinction can be made explicit using a simple, fully specified random-effect distribution. The distribution in this example is discrete to make the averaging arithmetic transparent; the definition of a conditional GLMM does not require this particular distribution.
Worked Example: Averaging a Conditional Logistic Mean
Suppose a hypothetical binary outcome has a logit conditional mean with predictor \(0.4+b_i\). Suppose the random effect takes values \(-0.8\) and \(0.8\), each with probability \(0.5\). The conditional probabilities at those two values are
The mean averaged over the two random-effect values is
The random effect has mean \(E(b_i)=0.5(-0.8)+0.5(0.8)=0\). Substituting that mean into the predictor instead would give
The two answers, \(0.5849\) and \(0.5987\), differ. The averaged response mean is found by averaging the two conditional probabilities, not by applying the inverse logit to the mean predictor. Their difference is not evidence of an arithmetic error; it follows from applying a nonlinear inverse link before, rather than after, averaging.
Justification and Likelihood
The averaging rule follows directly from conditional expectation. Given covariates, the random effect determines the conditional mean; averaging that mean over the random-effect distribution gives the unconditional mean with respect to those effects:
Under conditional independence of responses given the random effects and covariates, the likelihood contribution for a cluster is obtained by multiplying the conditional response probabilities or densities and then averaging that product over the cluster's random-effect distribution:
The product is inside the integral because the same cluster-level random effect is shared by the responses in that cluster. In general, the integral does not reduce to a GLM likelihood evaluated at the mean random effect. This is why the GLMM has both a conditional model and an explicit random-effect distribution.
Assumptions, Diagnostics, and Alternatives
Interpreting the conditional component requires stating the assumptions that give it meaning. At a minimum, the response family and link must be suitable for the response and conditional mean; the fixed and random parts of the predictor must be specified; and the random effects must have a stated distribution. A common GLMM assumption is that responses are conditionally independent given the random effects and covariates. This does not assert marginal independence: integrating over shared random effects can induce dependence among responses in a cluster.
The random-effect distribution is part of the model, not a decorative add-on. Its shape and scale affect the averaging over random effects and can affect fitted marginal means. Covariates are also usually treated as given for the conditional model; if the random effects are associated with the covariates in a way the model does not account for, conditional and population-level interpretations may be misleading.
Model checking should therefore consider both the response model and the clustering structure. Useful warning signs include persistent conditional residual patterns, more variation than the chosen response family allows, or residual dependence within clusters after accounting for the fitted model. Check whether fitted conditional means respect the response's range and whether the assumed random-effect distribution is a plausible description of cluster variation. Convergence problems or estimates on problematic boundaries can also indicate that the specified model is too complex for the available information. Diagnostics do not prove an assumption; they can reveal mismatches that call for reconsidering the model or its interpretation.
The main alternatives target different means. A GLM specifies a mean model without this random-effect conditioning structure. A marginal model, such as one fitted by generalized estimating equations, directly targets a mean averaged over the population or clusters under its working assumptions. A GLMM instead gives a model conditional on random effects and can use that structure to describe cluster-level variation. These approaches answer related but not identical questions; which is appropriate depends on whether the scientific target is conditional or population-average.
| Approach | Mean being modelled | Important distinction |
|---|---|---|
| GLMM | Conditional on the random effects and covariates | Requires a random-effect distribution; averaging over it is a further calculation |
| GLM | Mean under the specified GLM, without the random-effect conditioning structure | Does not represent cluster variation through random effects |
| Marginal model | Mean averaged over the target population or clusters | Targets an averaged response mean directly rather than a cluster-conditional mean |
A common pitfall is to say, “The random effects have mean zero, so the conditional mean equals the mean over clusters.” That reasoning is wrong for a nonlinear inverse link. In general, \(E\{h(\eta+z^{\mathsf T}b)\}\) is not \(h\{\eta+z^{\mathsf T}E(b)\}\), even when \(E(b)=0\). The correction is to state which mean is being reported and, for an averaged mean, integrate or otherwise average the conditional mean over the specified random-effect distribution.
Check Your Understanding
Answer each question, then compare with the solutions below.
- In a GLMM, what does the conditional mean \(E(Y_{ij}\mid b_i,x_{ij},z_{ij})\) condition on?
- If \(E(b_i)=0\), must the inverse-link mean at \(b_i=0\) equal the mean averaged over random effects? Explain.
- A conditional model has \(\log(\mu)=\log(2)+0.2+b\). Find \(\mu\) when \(b=0.1\), and state what the answer represents.
- Why does conditional independence given shared random effects not imply marginal independence within a cluster?
Solutions. (1) It conditions on the cluster's random-effect value and the stated covariates. (2) No. With a nonlinear inverse link, averaging \(h(\eta+z^{\mathsf T}b_i)\) generally differs from evaluating it at \(E(b_i)=0\). (3) \(\mu=e^{\log(2)+0.2+0.1}=2e^{0.3}\approx 2.700\), the conditional expected response for that random-effect value. (4) Responses share the same random effect; averaging over that shared quantity can induce dependence even when they are independent conditional on it.