Tutorials › Generalized Linear Mixed Models (GLMM) › The Conditional GLM Component of a GLMM

From GLM to GLMM · Tutorial 32 of 698

The Conditional GLM Component of a GLMM

Learn how a GLMM specifies responses conditional on random effects and why the conditional mean is generally different from the mean averaged over those effects.

Beginner 9 min read

What You'll Learn

  • Write a GLMM response distribution conditional on its random effects.
  • Distinguish a conditional mean from a mean averaged over random effects.
  • Calculate conditional Bernoulli probabilities and Poisson means from link-scale predictors.
  • Average conditional means over a specified random-effect distribution.
  • Recognize assumptions and diagnostics relevant to the conditional model.
  • Compare conditional GLMM means with GLM and marginal-model means.

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.

Definition: For response \(Y_{ij}\) from unit \(j\) in cluster \(i\), let \(b_i\) be that cluster's random-effect vector, \(x_{ij}\) a fixed-effect design vector, \(z_{ij}\) a random-effect design vector, and \(\beta\) a fixed-effect coefficient vector. A conditional GLM component specifies a response distribution for \(Y_{ij}\) given \(b_i\) and the covariates, together with a conditional mean \(\mu_{ij}(b_i)=E(Y_{ij}\mid b_i,x_{ij},z_{ij})\) satisfying $$ g\{\mu_{ij}(b_i)\}=\eta_{ij}(b_i)=x_{ij}^{\mathsf T}\beta+z_{ij}^{\mathsf T}b_i+o_{ij}, $$ where \(g\) is the link function and \(o_{ij}\) is an optional known offset. The random effects also have a specified probability distribution, often written \(b_i\sim F_b(\theta)\), with distributional parameters \(\theta\).

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:

$$ \mu_{ij}(b_i)=h\left(x_{ij}^{\mathsf T}\beta+z_{ij}^{\mathsf T}b_i+o_{ij}\right). $$

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

$$ E(Y_{ij}\mid x_{ij},z_{ij}) =E_{b_i}\{\mu_{ij}(b_i)\mid x_{ij},z_{ij}\} =\int h\left(x_{ij}^{\mathsf T}\beta+z_{ij}^{\mathsf T}b+o_{ij}\right)\,dF_b(b). $$

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.

Key result: A GLMM specifies \(E(Y_{ij}\mid b_i,x_{ij},z_{ij})\) through its conditional link model. To obtain a mean averaged over random effects, average that conditional mean over \(F_b\). Do not replace the random effects by their mean inside a nonlinear inverse link and call the result the averaged mean.

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

$$ Y_{ij}\mid b_i,x_{ij}\sim\operatorname{Bernoulli}(p_{ij}(b_i)), \qquad \operatorname{logit}\{p_{ij}(b_i)\}=-1+0.5x_{ij}+b_i. $$

For an illustrative covariate value \(x_{ij}=2\) and random-effect value \(b_i=0.3\), the conditional linear predictor is

$$ \eta_{ij}(b_i)=-1+0.5(2)+0.3=0.3. $$

The inverse logit gives the conditional success probability:

$$ p_{ij}(b_i)=\frac{e^{0.3}}{1+e^{0.3}} =\frac{1.3499}{2.3499} \approx 0.5744. $$

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:

$$ Y_{ij}\mid b_i,x_{ij},t_{ij} \sim \operatorname{Poisson}\{\mu_{ij}(b_i)\}, \qquad \log\{\mu_{ij}(b_i)\} =\log(t_{ij})+0.1+0.4x_{ij}+b_i. $$

For \(t_{ij}=3\) weeks, \(x_{ij}=1\), and \(b_i=-0.2\), substitute the values into the predictor:

$$ \log\{\mu_{ij}(b_i)\}=\log(3)+0.1+0.4(1)-0.2 =\log(3)+0.3. $$

Exponentiating gives the conditional mean count:

$$ \mu_{ij}(b_i)=e^{\log(3)+0.3}=3e^{0.3} =3(1.3499)\approx 4.050. $$

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

$$ p(-0.8)=\frac{e^{0.4-0.8}}{1+e^{0.4-0.8}} =\frac{e^{-0.4}}{1+e^{-0.4}}\approx 0.4013, \qquad p(0.8)=\frac{e^{0.4+0.8}}{1+e^{0.4+0.8}} =\frac{e^{1.2}}{1+e^{1.2}}\approx 0.7685. $$

The mean averaged over the two random-effect values is

$$ E_b\{p(b)\}=0.5(0.4013)+0.5(0.7685)=0.5849. $$

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

$$ \operatorname{logit}^{-1}(0.4+E(b_i)) =\operatorname{logit}^{-1}(0.4) =\frac{e^{0.4}}{1+e^{0.4}} \approx 0.5987. $$

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:

$$ E(Y_{ij}\mid x_{ij},z_{ij}) =E_{b_i}\{E(Y_{ij}\mid b_i,x_{ij},z_{ij})\mid x_{ij},z_{ij}\} =E_{b_i}\{\mu_{ij}(b_i)\mid x_{ij},z_{ij}\}. $$

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:

$$ L_i(\beta,\theta) =\int \left\{\prod_j f(y_{ij}\mid b,x_{ij},z_{ij};\beta)\right\}\,dF_b(b;\theta). $$

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.

ApproachMean being modelledImportant distinction
GLMMConditional on the random effects and covariatesRequires a random-effect distribution; averaging over it is a further calculation
GLMMean under the specified GLM, without the random-effect conditioning structureDoes not represent cluster variation through random effects
Marginal modelMean averaged over the target population or clustersTargets 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.

Key takeaway: The conditional GLM component consists of a response distribution given the random effects and a link model for its conditional mean. A population-average mean is obtained by averaging that conditional mean over the random-effect distribution, not by simply setting the random effects to zero.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. In a GLMM, what does the conditional mean \(E(Y_{ij}\mid b_i,x_{ij},z_{ij})\) condition on?
  2. If \(E(b_i)=0\), must the inverse-link mean at \(b_i=0\) equal the mean averaged over random effects? Explain.
  3. A conditional model has \(\log(\mu)=\log(2)+0.2+b\). Find \(\mu\) when \(b=0.1\), and state what the answer represents.
  4. 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.

Clinical Biostats