From a Response to a Deviance Residual
A deviance residual records how far one observation lies from its fitted mean, measured on the likelihood scale. For binomial and Poisson data, its calculation involves logarithms, so zero counts and boundary outcomes need particular care. The essential steps are to calculate the observation's unit deviance and then attach the sign of its response discrepancy.
For a grouped binomial observation, let \(y\) be the number of successes in \(m\) trials and let \(p\) be the fitted success probability. For a Poisson observation, let \(y\) be the observed count and let \(\mu\) be its fitted mean. All logarithms below are natural logarithms.
Thus the square of a signed deviance residual is the observation's deviance contribution. The sign is not a separate goodness-of-fit calculation: it indicates whether the observed response is above or below its fitted mean.
Deriving the Binomial Formula
For \(Y\sim\operatorname{Binomial}(m,p)\), the log-likelihood at observed count \(y\) is \(\log {m\choose y}+y\log p+(m-y)\log(1-p)\). When the model is saturated for this grouped observation, its fitted probability is \(y/m\), provided \(0<y<m\). Subtracting the fitted log-likelihood from the saturated log-likelihood cancels the binomial coefficient.
This formula also applies when \(y=0\) or \(y=m\) by using the zero-term convention. For one Bernoulli observation, set \(m=1\) and \(y\in\{0,1\}\). For grouped data, the entire row is one observation for this calculation; its trial count is not a multiplier to apply again after calculating the formula.
Worked Example: A Grouped Binomial Observation
A group has \(m=10\) trials, of which \(y=7\) are successes. Suppose the fitted probability is \(p=0.6\). The fitted mean number of successes is \(mp=10(0.6)=6\), so the response discrepancy is \(7-6=1\), which is positive.
The unit deviance is
Therefore the signed deviance residual is \(r_D=+\sqrt{0.43202}\approx 0.6573\). The sign is positive because the observed number of successes exceeds the fitted mean of six.
Deriving the Poisson Formula
For a Poisson observation with mean \(\mu>0\), the log-likelihood at count \(y\) is \(y\log\mu-\mu-\log(y!)\). The saturated model sets its mean to \(y\) when \(y>0\). Subtracting the fitted log-likelihood from the saturated log-likelihood cancels the factorial term and gives the following formula.
Consequently, a zero Poisson count has unit deviance \(2\mu\), not zero: the observation still disagrees with a positive fitted mean. At \(y=\mu\), the deviance and residual are both zero.
Worked Example: A Zero Poisson Count
Suppose a Poisson count is \(y=0\) and its fitted mean is \(\mu=2.5\). Using the zero-term convention,
The observed count is below the fitted mean, so the signed residual is \(r_D=-\sqrt{5}\approx -2.2361\). Although the count is zero, its deviance is finite and positive.
Worked Example: A Positive Poisson Count
Suppose \(y=4\) and \(\mu=2\). The count is above its fitted mean, so the residual will be positive. Calculate the deviance:
Thus \(r_D=+\sqrt{1.54518}\approx 1.2431\). Squaring this residual recovers the unit deviance, up to rounding.
Why the Deviances Are Nonnegative
A unit deviance must be nonnegative for its square root to define a real residual. The formulas above have this property, including at the response boundaries.
For the binomial case, put \(q=y/m\). Dividing the deviance by \(2m\) gives \(q\log(q/p)+(1-q)\log((1-q)/(1-p))\). For any positive \(u\), \(-\log u\geq 1-u\), since \(\log u\leq u-1\). Applying this inequality to each term with positive weight gives
Terms with zero weight contribute zero, so the inequality also holds when \(q=0\) or \(q=1\). Equality requires each positive-weight ratio to equal one, which gives \(q=p\). Hence the binomial deviance is nonnegative and vanishes exactly when \(y=mp\).
For the Poisson case, set \(x=y/\mu\). When \(y>0\), the deviance is \(2\mu g(x)\), where \(g(x)=x\log x-x+1\). Its derivative is \(g'(x)=\log x\), which is negative for \(0<x<1\), zero at \(x=1\), and positive for \(x>1\). Therefore \(g\) has its minimum, \(g(1)=0\), at \(x=1\). At \(y=0\), the zero-term convention gives \(d_{\mathrm{P}}=2\mu>0\). This proves the Poisson claim and its equality condition. \(\square\)
Boundary Values and Grouping
The binomial endpoints have simple forms. With \(0<p<1\), an all-failure group (\(y=0\)) has deviance \(2m\log(1/(1-p))\); an all-success group (\(y=m\)) has deviance \(2m\log(1/p)\). Their residual signs are negative if \(mp>0\) for \(y=0\), and positive if \(mp<m\) for \(y=m\).
Worked Example: All Failures and All Successes
Consider two groups, each with \(m=8\) trials and fitted probability \(p=0.25\). For the all-failure group, \(y=0\), so
For the all-success group, \(y=8\), so
The fitted mean is \(8(0.25)=2\) successes in either group. The first observed count is below two, and the second is above two, confirming the residual signs.
If a fitted binomial probability is exactly \(p=0\), the model assigns probability zero to any \(y>0\); its deviance is infinite. At \(y=0\), the fitted and saturated probabilities agree and the deviance is zero. Likewise, at \(p=1\), the deviance is infinite for \(y<m\) and zero for \(y=m\). These cases are interpreted through likelihoods, not by directly substituting into a formula containing division by zero. In standard Poisson GLMs fitted means are positive. If a model permits \(\mu=0\), then \(y>0\) has infinite deviance, while \(y=0\) has deviance zero.
Grouping changes what counts as one observation for deviance calculations. A grouped binomial row compares its observed success proportion \(y/m\) with its fitted probability \(p\), using one saturated probability for the row. Treating its \(m\) trials as separate Bernoulli observations instead uses a separate saturated fit for each trial. Those are different saturated models, so the resulting deviance contributions need not be the same. Use the representation of the data that matches the model and the intended observation units.
Common Mistakes and a Reliable Calculation
- Dropping the minus sign in the Poisson formula. The deviance contains \(-(y-\mu)\), not \(+(y-\mu)\). A quick check is that its value must be zero when \(y=\mu\).
- Evaluating \(0\log 0\) as an error. The corresponding likelihood contribution is defined by its limit and equals zero. A zero count can still have positive deviance through the remaining terms.
- Giving a residual the wrong sign. Compare \(y\) with \(mp\) for binomial data, not just with \(p\); compare \(y\) with \(\mu\) for Poisson data.
- Multiplying a grouped-binomial deviance by the number of trials afterward. The formula already includes both successes and failures through \(y\) and \(m-y\).
- Taking a square root before checking the calculation. A negative unit deviance indicates an algebra or numerical error for an ordinary finite fitted mean.
A dependable calculation is to write down the observation and fitted mean, evaluate the unit deviance using the zero-term conventions, take its nonnegative square root, and then attach the sign of the response minus fitted mean. For a zero discrepancy, the residual is zero.
Check Your Understanding
Use the formulas and boundary conventions above to work through these questions.
- For \(y=3\), \(m=5\), and \(p=0.4\), what is the grouped-binomial unit deviance, and what is the sign of its signed residual?
- For a Poisson observation with \(y=0\) and fitted mean \(\mu=1.2\), calculate the unit deviance and state the signed residual in terms of a square root.
- Why is the logarithmic term with coefficient \(y=0\) set to zero in the Poisson formula?
- What happens to the binomial deviance when \(p=0\) but \(y>0\)? Explain using the fitted model's likelihood.
- Why can the deviance for a grouped binomial row differ from the sum of deviances obtained by treating each trial as a separate Bernoulli observation?