What Conditioning on Estimated Cluster Effects Means
A GLMM accounts for dependence within clusters by including random effects. For diagnostics, one option is to estimate those effects and calculate fitted values and residuals as though the estimates were known. This can be useful: it lets us inspect how observations depart from the fitted pattern within each cluster. But it is a plug-in calculation, not a statement that the random effects are known without error.
For observation \(i\) in cluster \(j\), let \(Y_{ij}\) be the response, \(x_{ij}\) the fixed-effect covariates, and \(b_j\) the cluster random effect. Write the conditional model as
Here \(g\) is the link function, \(\beta\) is the fixed-effect parameter vector, and \(z_{ij}\) specifies how the cluster effect enters the linear predictor. In a standard GLMM, the random effects have a specified distribution, commonly \(b_j\sim N(0,D)\). Conditional on the random effects and covariates, the responses are assumed independent and have the stated response distribution and mean-variance relationship.
The estimates \(\hat{b}_j\) are often empirical Bayes estimates, such as conditional modes or conditional means given the data and fitted model. They are estimated using information from the cluster’s responses, typically with shrinkage toward the random-effects distribution. Thus, these residuals are calculated conditional on estimates, not on the unobserved true effects.
Calculating Conditional Residuals
For a model with conditional variance \(V(\mu_{ij})=\operatorname{Var}(Y_{ij}\mid b_j,x_{ij})\), the plug-in conditional Pearson residual is
For a Poisson response, \(V(\mu)=\mu\), so the denominator is \(\sqrt{\hat{\mu}_{ij}}\). For a Bernoulli response with fitted probability \(\hat{p}_{ij}\), the variance is \(\hat{p}_{ij}(1-\hat{p}_{ij})\). For a binomial response with \(m_{ij}\) trials, the variance is \(m_{ij}\hat{p}_{ij}(1-\hat{p}_{ij})\).
A conditional deviance residual is the signed square root of the observation’s contribution to the conditional deviance. Its sign is the sign of \(Y_{ij}-\hat{\mu}_{ij}\). For a Poisson observation \(y\), the contribution is \(2[y\log(y/\hat{\mu})-(y-\hat{\mu})]\), with \(y\log(y/\hat{\mu})=0\) when \(y=0\). These formulas use the fitted conditional mean; they do not make discrete residuals exactly normal.
Worked Example: A Conditional Poisson Pearson Residual
Suppose a hypothetical fitted Poisson GLMM has log link \( \log(\mu_{ij})=\beta_0+\beta_1x_{ij}+b_j \). For one count observation, the fitted values are \(\hat{\beta}_0=-1.2\), \(\hat{\beta}_1=0.4\), \(x_{ij}=1\), and \(\hat{b}_j=0.3\). The observed count is \(Y_{ij}=2\). Treat these as outputs from a fit; this calculation does not estimate the random effect from this one observation.
First calculate the conditional linear predictor and mean:
The response residual is \(2-0.6065=1.3935\) counts. Under the conditional Poisson model, the fitted variance is \(0.6065\), giving
The count is about 1.79 conditional standard deviations above its fitted mean. This is a descriptive discrepancy, not a calibrated normal test statistic. For comparison, the signed deviance residual is \( \sqrt{2[2\log(2/0.6065)-(2-0.6065)]}\approx 1.409 \). Both calculations use the same conditional mean, but their scaling differs.
Worked Example: A Conditional Bernoulli Pearson Residual
Consider a hypothetical logistic random-intercept model with \( \operatorname{logit}(p_{ij})=\beta_0+\beta_1x_{ij}+b_j \). For one binary observation, suppose \(\hat{\beta}_0=-1.0\), \(\hat{\beta}_1=0.8\), \(x_{ij}=1\), and \(\hat{b}_j=0.4\). The recorded outcome is \(Y_{ij}=1\).
The conditional linear predictor is \(-1.0+0.8+0.4=0.2\), so the fitted probability is
The response residual is \(1-0.5498=0.4502\). The conditional Bernoulli variance is \(0.5498(1-0.5498)=0.2475\). Therefore,
The observed success is above the fitted conditional probability, with a Pearson residual of about 0.905. Since a single Bernoulli outcome can only be zero or one, this residual’s possible values are constrained by the fitted probability; it should not be interpreted as if it came from a continuous normal response.
Why Within-Cluster Patterns Can Be Informative
Conditioning on an estimated cluster effect adjusts the fitted mean for the cluster’s estimated overall level. After that adjustment, a sequence of residuals within the cluster can help expose a systematic departure that a single cluster-wide shift cannot explain. For example, residuals that tend to be negative early and positive late may suggest a time trend not represented in the fixed-effects structure. Such a pattern is a diagnostic clue, not by itself proof of a particular model failure.
Worked Example: A Pattern Hidden by a Cluster-Wide Average
In a hypothetical four-observation cluster, suppose the fitted model has a logistic intercept and a cluster random intercept, but no time effect. The fitted fixed intercept is zero, and the estimated cluster effect is zero. The conditional fitted probability is therefore \(0.5\) at each of four ordered times. The observed binary outcomes are \(0,0,1,1\).
For each observation, the conditional Bernoulli variance is \(0.5(1-0.5)=0.25\), so the Pearson residual denominator is \(0.5\). In time order, the residuals are
The residuals sum to zero, so their average gives no indication of an overall cluster shift. Their ordered pattern, however, changes from negative to positive. That pattern is consistent with a possible within-cluster time trend that the intercept-only conditional mean does not represent. A random intercept can adjust a cluster’s level; it cannot generally reproduce a changing response pattern over time.
Conditioning Can Understate Uncertainty
The conditional Pearson denominator uses the response variance at the plug-in fitted mean. It does not add uncertainty about the estimated random effect. This distinction follows from the law of total variance. For a future response \(Y\) and random effect \(b\), conditional on the observed data \(\mathcal{D}\),
The first term is response variation given the random effect. The second is variation in the conditional mean because the random effect remains uncertain. A plug-in conditional residual uses a fitted value such as \(V(\hat{\mu})\) and omits this second source of variation. Also, because the same cluster responses help estimate \(\hat{b}_j\), fitted residuals are not equivalent to residuals computed with an independently known effect.
For illustration, suppose a hypothetical Poisson prediction has two equally likely random-effect states that produce conditional means 1 and 4. The mean of these conditional means is 2.5, and their variance is 2.25. Since the conditional Poisson variance equals its mean, the predictive variance is \(2.5+2.25=4.75\), not 2.5. A plug-in calculation at a mean of 2.5 would use a standard deviation of \(\sqrt{2.5}=1.581\), whereas the predictive standard deviation is \(\sqrt{4.75}=2.179\). This illustration concerns prediction uncertainty; it does not imply that every fitted-residual variance can be corrected by this simple calculation.
The practical implication is measured: conditional residuals can be informative about lack of fit within clusters, but their apparent spread may be too small if read as though all fitted quantities were fixed and known. They are not automatically independent, identically distributed reference values, and conventional cutoffs should not be applied without justification.
Assumptions, Diagnostics, and Alternatives
The calculation is meaningful only relative to a stated fitted GLMM. Check that the response distribution and link are appropriate, that the conditional variance is correctly specified, and that the random-effects structure represents the intended clustering. Conditional independence of responses given the random effects and covariates is also part of the model assumption. An incorrect link, omitted predictor, excessive zero frequency, overdispersion, or unmodeled within-cluster dependence can all produce residual patterns.
When using conditional residuals, inspect more than their numerical size. Compare them across clusters and against observation order or relevant covariates; look for repeated structure rather than interpreting one large value in isolation. Consider whether a cluster contains enough information to estimate its effect reliably. With sparse outcomes, extreme fitted probabilities can make Pearson residuals large for a surprising observation, while many zero outcomes may still be quite compatible with the fitted model. Residual plots and summaries are diagnostics, not stand-alone tests with universal reference distributions.
Conditional residuals are most directly useful when the question concerns how observations depart from cluster-adjusted fitted means. Response residuals retain the outcome’s original units; Pearson residuals scale by the conditional variance; deviance residuals use likelihood-based contributions. Simulation-based residuals, introduced in the earlier material on simulation-based residuals for GLMMs, instead use simulated outcomes to assess discrepancies while accounting for the fitted response distribution. These approaches answer related but not identical diagnostic questions. Residuals marginalized over random effects use a different prediction target; they should not be substituted for conditional residuals without being clear about that target.
No residual type repairs model misspecification, and conditional residuals do not estimate the true random effects. Their main limitation is precisely their conditioning: they can clarify within-cluster fit while making uncertainty in the fitted cluster adjustment easy to overlook.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- A Poisson GLMM gives a conditional fitted mean of 3.0 for an observation with count 1. Calculate its response and Pearson residuals.
- For a Bernoulli observation with fitted conditional probability \(0.2\) and outcome 0, calculate the Pearson residual. Is it above or below the fitted probability?
- Why can residuals that sum to approximately zero within a cluster still reveal a problem?
- State the two components in the law of total variance relevant to uncertain random effects, and identify which one a plug-in conditional variance can omit.
Solutions. (1) The response residual is \(1-3=-2\) counts. The Poisson conditional variance is 3, so the Pearson residual is \(-2/\sqrt{3}=-1.155\). (2) The variance is \(0.2(0.8)=0.16\); the residual is \((0-0.2)/\sqrt{0.16}=-0.500\), below the fitted probability. (3) A cluster-wide sum can hide an ordered or covariate-related pattern, such as residuals changing from mostly negative to mostly positive. (4) Predictive variance is the expected conditional response variance plus the variance of the conditional mean across uncertain random effects. A plug-in conditional variance can omit the second component, the variation in the mean due to uncertainty about the random effect.