Tutorials › Generalized Linear Mixed Models (GLMM) › Response Residuals for Binary and Count GLMMs

Diagnostics and Predictive Checks for Sparse and Overdispersed Outcomes · Tutorial 608 of 698

Response Residuals for Binary and Count GLMMs

Learn to calculate and interpret observed-minus-fitted residuals for binary and count GLMMs without mistaking their discreteness or abundance of zeros for model failure.

Intermediate 10 min read

What You'll Learn

  • Define response residuals using fitted response-scale means.
  • Calculate residuals for Bernoulli and grouped binomial observations.
  • Interpret count residuals when many observed outcomes are zero.
  • Distinguish conditional from marginal residual interpretations.
  • Recognize why raw residual size alone is not a universal measure of unusualness.
  • Identify common diagnostic pitfalls and choose an appropriate follow-up check.

What a Response Residual Measures

A response residual compares an observed outcome with the outcome the fitted model expects on the original response scale. For a binary observation, it is the observed zero or one minus the fitted probability. For a count, it is the observed count minus the fitted expected count. This simple subtraction is useful because it preserves the outcome's units and direction: positive values mean the model's fitted mean was below the observation, and negative values mean it was above.

In a GLMM, the fitted response mean can be conditional on a cluster's estimated random effect or averaged over the random-effects distribution. These fitted values answer different questions, as in the earlier material on conditional and marginal fitted values. A residual must be calculated against the fitted value that matches the diagnostic target; the choice should be stated rather than left implicit.

Definition: A response residual (also called a raw residual) for observation \(i\) is the observed response minus its fitted conditional mean, \(r_i=y_i-\hat{\mu}_i\), or minus its fitted marginal mean, \(r_i=y_i-\hat{\mu}_{i,\mathrm{marg}}\), when the marginal target is intended. The fitted mean must be on the response scale and have the same units as \(y_i\).

For a Bernoulli response, \(Y_i\in\{0,1\}\), and the fitted response mean is the fitted event probability \(\hat{p}_i\). For a binomial response recording \(y_i\) successes in \(m_i\) trials, the fitted mean is \(m_i\hat{p}_i\), not just \(\hat{p}_i\). For a count response, the fitted mean is the expected count, often denoted \(\hat{\mu}_i\). These distinctions matter: subtracting a probability from a number of successes, for example, compares quantities with different units.

Model and Interpretation

Suppose observation \(i\) belongs to cluster \(j\), has covariates \(x_{ij}\), and has random effect \(b_j\). A standard GLMM specifies a conditional response distribution given the random effects, a linear predictor such as \(\eta_{ij}=x_{ij}^{T}\beta+z_{ij}^{T}b_j\), and a link relating that predictor to the conditional response mean. For example, a Bernoulli model has \(E(Y_{ij}\mid b_j,x_{ij})=p_{ij}\), while a count model has \(E(Y_{ij}\mid b_j,x_{ij})=\mu_{ij}\). The random effects have a specified distribution, and responses are typically assumed conditionally independent given those effects and the covariates, unless the model includes additional dependence.

A conditional residual uses a fitted mean such as \(\hat p_{ij}\) or \(\hat\mu_{ij}\) evaluated using an estimated random effect for that cluster. A marginal residual uses the model mean averaged over the random-effects distribution. Because the link is often nonlinear, applying the inverse link at an average random effect does not generally give the marginal mean. The fitted marginal value should therefore come from the model's marginalization, not from an unexamined substitution.

The following justification explains the basic zero-centering property, while also showing why it does not make response residuals independent or normally distributed.

$$ \begin{aligned} r_{ij} &= Y_{ij}-\mu_{ij}(b_j),\\ E(r_{ij}\mid b_j,x_{ij}) &=E(Y_{ij}\mid b_j,x_{ij})-\mu_{ij}(b_j)\\ &=\mu_{ij}(b_j)-\mu_{ij}(b_j)=0. \end{aligned} $$

This calculation assumes the conditional mean is correctly specified and uses the true model mean. The corresponding marginal statement follows by averaging over the random-effects distribution: if the marginal mean is \(E_b\{\mu_{ij}(b)\}\), then \(E\{Y_{ij}-E_b[\mu_{ij}(b)]\mid x_{ij}\}=0\). In practice, fitted parameters and random effects are estimated from the data, so residuals need not sum to zero or have exact mean zero in a particular fitted sample. Nor does zero mean imply independence: observations in a cluster can remain dependent marginally through their shared random effect.

Bernoulli and Binomial Outcomes

Worked Example: Bernoulli Residuals for Event and Non-Event Outcomes

Consider a hypothetical fitted Bernoulli GLMM for four patients, with conditional fitted event probabilities \(0.20,\ 0.35,\ 0.60,\) and \(0.80\). Suppose the observed outcomes are \(0,\ 1,\ 0,\) and \(1\), respectively. For each patient, calculate \(r_i=y_i-\hat p_i\).

For patient 1, \(r_1=0-0.20=-0.20\). For patient 2, \(r_2=1-0.35=0.65\). For patient 3, \(r_3=0-0.60=-0.60\). For patient 4, \(r_4=1-0.80=0.20\).

The positive residuals say that an event occurred more often than the fitted probability alone would suggest for those observations; the negative residuals say that no event occurred when the fitted event probability was positive. Each residual is bounded between \(-1\) and \(1\). Its magnitude is not, by itself, a standardized measure of surprise. For example, a residual of \(0.65\) is not automatically more diagnostically unusual than every smaller residual; the fitted probability and the model's response variability also matter.

A Bernoulli response has only two possible values, so raw residuals also have only two possible forms at any given fitted probability: \(1-\hat p_i\) if the outcome is one, and \(-\hat p_i\) if it is zero. Consequently, residuals from observations with similar fitted probabilities repeat or cluster at the same values. This discreteness is a property of the response, not a calculation error.

Worked Example: A Grouped Binomial Residual

In a hypothetical cluster, a group has \(m_i=12\) trials and \(y_i=5\) successes. The fitted conditional probability of success is \(\hat p_i=0.25\). The fitted expected number of successes is \(m_i\hat p_i=12(0.25)=3\). Thus the response residual is

$$ r_i=y_i-m_i\hat p_i=5-12(0.25)=5-3=2\ \text{successes}. $$

The observed group had two more successes than its fitted expected count. If the same fitted probability applied to a group of 12 trials with zero successes, its residual would instead be \(0-3=-3\) successes. The denominator \(m_i\) is essential: using \(5-0.25=4.75\) would incorrectly subtract a probability from a success count.

Count Outcomes and Many Zeros

For a count response, a zero observation has response residual \(0-\hat\mu_i=-\hat\mu_i\). It is therefore negative whenever the fitted expected count is positive. This does not mean every zero indicates a poor fit. A count model with a low fitted mean can assign substantial probability to zero. Under a conditional Poisson model, for example, \(P(Y_i=0\mid b_j,x_{ij})=\exp(-\mu_{ij})\). When \(\mu_{ij}=0.2\), this probability is about \(0.819\); when \(\mu_{ij}=0.6\), it is about \(0.549\). Zeros are quite compatible with those fitted means.

Worked Example: Residuals in a Sparse Count Sample

Suppose a hypothetical Poisson GLMM gives conditional fitted means \(0.2,\ 0.6,\ 1.1,\) and \(2.0\) for four observations, whose observed counts are \(0,\ 0,\ 0,\) and \(4\). The response residuals are:

  • Observation 1: \(0-0.2=-0.2\) counts.
  • Observation 2: \(0-0.6=-0.6\) counts.
  • Observation 3: \(0-1.1=-1.1\) counts.
  • Observation 4: \(4-2.0=2.0\) counts.

Three of the four observations are zero, but the first two zeros occur where the conditional Poisson probabilities of zero are about \(\exp(-0.2)=0.819\) and \(\exp(-0.6)=0.549\). The third zero has probability \(\exp(-1.1)\approx0.333\). Those calculations do not establish that the whole model is adequate; they show why counting zeros without regard to their fitted means is insufficient. The residual sum here is \(-0.2-0.6-1.1+2.0=0.1\) counts. There is no requirement that it equal zero.

When many observations are zero, their response residuals are all nonpositive and can have different magnitudes because their fitted means differ. A pattern of numerous negative residuals may prompt a model check, especially if zeros occur where fitted means imply they should be uncommon. But a large number of zeros can also be expected when fitted means are small. The raw residual alone does not distinguish these situations, and a single zero with a negative residual is not evidence by itself for an extra-zero mechanism.

What Response Residuals Can and Cannot Tell You

Response residuals retain the natural units of the outcome, which makes their signs and arithmetic direct. Their main limitation is that those units do not put observations on a common variability scale. Under a Bernoulli model, the conditional variance is \(p_{ij}(1-p_{ij})\); for a binomial count it is \(m_i p_{ij}(1-p_{ij})\); and for a Poisson count it is \(\mu_{ij}\). Thus, even if two observations have the same response residual, that difference can have different significance relative to the model's expected variation.

Raw residuals are also discrete, can be strongly asymmetric, and are constrained by the response's support. A Bernoulli residual cannot exceed one in absolute value, while a count residual cannot be below \(-\hat\mu_i\) but can be positive and unbounded. It is therefore inappropriate to expect them to resemble independent normal errors. The conditional-independence assumption does not remove marginal cluster dependence, and fitted random effects can affect conditional residuals. Interpretation should keep the chosen conditional or marginal target in view.

Response residuals are a useful first check of direction and discrepancy in the original outcome units. They are not a complete diagnostic by themselves. Pearson residuals scale discrepancies using a model-based standard deviation; deviance residuals are based on likelihood contributions; randomized quantile residuals and simulation-based residuals address other features of discrete outcomes. Those alternatives answer related but distinct diagnostic questions. A sensible workflow starts by checking whether response-scale differences have interpretable signs and units, then uses a diagnostic suited to the suspected failure mode rather than treating raw residual magnitude as a universal score.

When examining residuals, note which fitted values were used, the response scale, and the observational unit. For a grouped binomial outcome, report residuals in successes; for a count, report them in counts. With clustered data, retain cluster identifiers so a set of similar discrepancies in one cluster is not mistaken for a set of independent pieces of evidence.

Common Pitfalls

  • Subtracting on mismatched scales. For \(y_i\) successes in \(m_i\) trials, \(y_i\) must be compared with \(m_i\hat p_i\), not with \(\hat p_i\).
  • Calling every zero a model failure. A zero can be likely when its fitted count mean is small. Consider the fitted mean and model-implied probability of zero.
  • Comparing raw magnitudes as though they were standardized. A difference of one count can be modest under one fitted mean and more concerning under another. Raw residuals do not account for this varying response variance.
  • Assuming residuals should sum to zero or be independent. That identity is not generally imposed in a GLMM, and shared random effects can induce marginal dependence.
  • Ignoring the fitted-value target. A conditional residual and a marginal residual compare the observation with different expectations. State which one is being interpreted.
Key takeaway: A response residual is observed outcome minus fitted response mean. Calculate it on the response scale, use the correct expected count for binomial data, and interpret its sign and units without treating its raw magnitude as a standardized measure of fit.

Check Your Understanding

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

  1. A Bernoulli observation is \(y=0\), and its fitted event probability is \(0.30\). What is its response residual, and what does the sign mean?
  2. A group has 8 binomial trials, 3 observed successes, and fitted success probability \(0.40\). Calculate its response residual in successes.
  3. A count observation is zero with fitted mean \(0.15\). Calculate its response residual. Under a conditional Poisson model, calculate the probability of zero to three significant figures.
  4. Why is a response residual of \(2\) counts not necessarily more unusual than a response residual of \(1\) count from another observation?

Solutions. (1) \(r=0-0.30=-0.30\). It is negative because the observed non-event is below the fitted event probability on the response scale. (2) The fitted expected successes are \(8(0.40)=3.2\), so \(r=3-3.2=-0.2\) successes. (3) \(r=0-0.15=-0.15\) counts; \(P(Y=0)=\exp(-0.15)\approx0.861\), so this zero is quite compatible with that Poisson mean. (4) Response residuals are unscaled: the model-based variability depends on the fitted mean and response distribution. The two differences cannot be ranked as standardized evidence from their raw sizes alone.

Clinical Biostats