Why Grouping Changes the Deviance Reference
A binomial response can be recorded as one success-or-failure result per individual, or as a total number of successes among several trials sharing a set of predictors. These representations can describe the same underlying outcomes, but their residual deviances need not be equal. The reason is not that the fitted probabilities must differ: it is that the two representations use different saturated models as their reference.
This distinction matters when reading GLM output. For grouped data, one response row represents a group of trials, and residual degrees of freedom are counted from those rows. For individual binary data, each trial is a response row. Counting the number of people or trials in place of the number of grouped response rows can therefore produce a misleading interpretation.
Grouped-Binomial Deviance
Suppose the fitted model gives group \(j\) probability \(\hat p_j\). The observed number of successes is \(y_j\), and the observed number of failures is \(m_j-y_j\). The grouped-binomial deviance is twice the log-likelihood difference between the grouped saturated model and the fitted model. Equivalently, it is the sum of the following contributions:
Here \(G\) is the number of grouped response rows. Use the convention \(0\log(0/a)=0\) for \(a>0\), so a group with no observed successes or no observed failures has a well-defined contribution. A fitted probability of exactly 0 or 1 requires care: if that prediction assigns probability zero to an outcome that occurred, the fitted log-likelihood is minus infinity and the deviance is infinite.
The formula assumes binomial sampling within each group: conditional on the modeled probability \(p_j\), the \(m_j\) trials in group \(j\) have the same success probability, and the group count has a binomial distribution. The usual likelihood also treats the groups as independent. The predictor model determines how the probabilities \(p_j\) are related across groups.
Why the Formula Holds
For one group, the binomial log-likelihood, apart from notation for its parameters, is \(\log {m_j \choose y_j}+y_j\log(p_j)+(m_j-y_j)\log(1-p_j)\). The combinatorial term is the same under the fitted and saturated models, so it cancels in their difference. The saturated probability \(y_j/m_j\) maximizes the remaining log-likelihood: differentiating with respect to \(p_j\) gives \(y_j/p_j-(m_j-y_j)/(1-p_j)=0\), whose solution is \(p_j=y_j/m_j\) for an interior count. Substituting this probability into twice the log-likelihood difference gives the group’s contribution in the deviance formula. At \(y_j=0\) or \(y_j=m_j\), the maximum is at the corresponding boundary, and the zero-term convention gives the same expression by continuity.
This derivation also explains what deviance measures: it compares the fitted model with a more flexible model that can match each observed group proportion. A small value means the fitted probabilities are close, in likelihood terms, to those group-specific proportions. It does not mean that every individual binary outcome is predicted correctly.
Worked Example: Computing Deviance for Three Groups
Hypothetical scenario. A model is fitted to three groups of policyholders, with a binary outcome recorded for each trial. Assume independent binomial group counts with \(Y_j\sim\operatorname{Binomial}(m_j,p_j)\). The fitted probabilities are supplied by the model; no interest-rate or mortality assumption is relevant to this statistical calculation.
| Group | Trials \(m_j\) | Observed successes \(y_j\) | Fitted probability \(\hat p_j\) |
|---|---|---|---|
| 1 | 10 | 2 | 0.20 |
| 2 | 10 | 6 | 0.50 |
| 3 | 20 | 12 | 0.50 |
Method. Calculate each group’s contribution using the grouped-binomial deviance formula, then add the contributions. This avoids treating all 40 trials as if their individual binary outcomes were being compared with the same grouped saturated model.
Group 1. There are \(10-2=8\) failures. The fitted expected counts are \(10(0.20)=2\) successes and \(10(0.80)=8\) failures, exactly the observed counts. Thus \(D_1=2[2\log(2/2)+8\log(8/8)]=0\).
Group 2. There are \(10-6=4\) failures. The fitted counts are 5 successes and 5 failures, so \(D_2=2[6\log(6/5)+4\log(4/5)]\). Using \(\log(1.2)=0.182322\) and \(\log(0.8)=-0.223144\), \(D_2=2[6(0.182322)+4(-0.223144)]=2[1.093932-0.892576]=0.4027\).
Group 3. There are \(20-12=8\) failures. The fitted counts are 10 and 10, so \(D_3=2[12\log(12/10)+8\log(8/10)]\). Therefore \(D_3=2[12(0.182322)+8(-0.223144)]=2[2.187864-1.785152]=0.8054\).
Total and check. The residual deviance is \(D=0+0.4027+0.8054=1.2081\), rounded to four decimal places. Both nonzero contributions are nonnegative, as expected because the saturated model cannot have a lower maximized likelihood than the fitted model. If the design matrix has rank 2, the residual degrees of freedom are \(3-2=1\), since there are three grouped response rows.
Residual Degrees of Freedom Count Response Rows
For the standard GLM residual-degrees-of-freedom convention, the residual degrees of freedom are the number of response rows minus the rank of the design matrix. The rank is the number of linearly independent columns in that matrix, including the intercept when present. It is not necessarily the number of named predictors plus one: redundant or linearly dependent columns do not increase the rank.
For \(G\) grouped-binomial rows, the count is \(G-\operatorname{rank}(X)\). For \(N\) individual Bernoulli rows, it is \(N-\operatorname{rank}(X)\). In the grouped case, each row is one binomial response, even though it represents \(m_j\) trials. In the individual case, each row is one binary response. The same total number of trials can therefore produce different residual degrees of freedom depending on how the response has been represented.
Worked Example: Counting Degrees of Freedom After Grouping
Hypothetical scenario. A binary outcome is recorded for 80 independent individuals. Their predictor values fall into four patterns, with 20 individuals in each pattern. A logistic model uses an intercept and one predictor, and its design matrix has rank 2. Assume the individual outcomes are conditionally Bernoulli with probabilities given by that model.
Grouped representation. The 80 outcomes are summarized into four success counts, one for each predictor pattern. There are \(G=4\) grouped response rows. Thus the grouped residual degrees of freedom are \(4-2=2\).
Individual representation. If the data are instead entered as 80 separate binary responses, there are \(N=80\) response rows. The design-matrix rank remains 2, so the standard individual-row residual degrees of freedom are \(80-2=78\).
Check and interpretation. The predictor information is the same, but the response-row count changes from 4 to 80, giving degrees of freedom 2 and 78 respectively. The grouped count is not \(80-2\): the grouped likelihood has four response rows. Nor does the individual-row count imply that the individual saturated model represents the same reference as the grouped saturated model.
Replicated Groups Versus Individual Binary Records
Consider \(m\) individual Bernoulli observations that share the same predictor values and therefore have the same fitted probability \(\hat p\). If they are grouped, their total \(y\) has a binomial distribution with parameters \(m\) and \(p\). For estimation of the regression parameters, grouping these identical-predictor observations preserves the likelihood apart from a binomial coefficient that does not depend on the regression parameters. Thus the fitted probabilities and coefficient estimates can be unchanged.
The absolute residual deviance is different because its saturated reference changes. In the grouped representation, the saturated model estimates one probability \(y/m\) for the whole group. In the individual representation, the saturated model can fit each observed binary response separately, assigning probability 1 to its observed outcome (at the boundary). Therefore, the individual Bernoulli deviance for these records is \(-2[y\log(\hat p)+(m-y)\log(1-\hat p)]\), whereas the grouped deviance also subtracts the log-likelihood of the group-specific saturated probability. The individual-row deviance is at least as large as the grouped deviance for the same fitted probability.
This distinction does not mean that aggregation changes the evidence for comparing two models fitted to the same data and using the same grouping convention. Likelihood-ratio comparisons between those models use the difference in their log-likelihoods; the parameter-independent binomial coefficients cancel. The caution concerns comparing absolute residual deviances across representations as if they had the same saturated reference.
Worked Example: One Replicated Group in Two Representations
Hypothetical scenario. Twelve independent trials share identical predictors. Six outcomes are successes and six are failures. A model gives each trial the fitted probability \(\hat p=0.50\). Thus the grouped count has \(Y\sim\operatorname{Binomial}(12,0.50)\), while the ungrouped records are 12 Bernoulli outcomes with probability 0.50.
Grouped calculation. The grouped saturated proportion is \(6/12=0.50\), which matches the model prediction. Hence \(D_{\mathrm{grouped}}=2[6\log(6/6)+6\log(6/6)]=0\).
Individual calculation. For each of the six successes, the individual saturated model assigns probability 1 to success, while the fitted model assigns probability 0.50. Each success contributes \(-2\log(0.50)\). Each of the six failures contributes the same amount. Therefore \(D_{\mathrm{individual}}=-2[6\log(0.50)+6\log(0.50)]=-24\log(0.50)=24\log 2=16.6355\), rounded to four decimal places.
Check and interpretation. The grouped deviance is 0 because the fitted probability equals the observed group proportion; the individual deviance is positive because the individual saturated model fits each 0 or 1 separately. For a model containing only an intercept, the design rank is 1: the grouped residual degrees of freedom are \(1-1=0\), while the individual-row convention gives \(12-1=11\). The nonzero individual deviance is not a contradiction; it answers a different saturated-reference comparison.
Boundary Counts and Practical Checks
Groups with zero successes or zero failures are common enough to deserve an explicit calculation. The convention for zero terms makes the formula straightforward, but the nonzero part of the contribution must still be retained. If \(y_j=0\), the success term vanishes and the contribution is \(-2m_j\log(1-\hat p_j)\). If \(y_j=m_j\), the failure term vanishes and the contribution is \(-2m_j\log(\hat p_j)\). These expressions apply when the fitted probability assigns positive probability to the observed outcome.
When interpreting output, first identify whether each response row contains an individual 0 or 1, a success count and trial count, or a proportion accompanied by trial weights. Then identify the number of rows and the design-matrix rank. A proportion without its trial count does not by itself specify the same binomial likelihood as a proportion weighted by that count.
Determine whether a row is one Bernoulli observation or one grouped binomial count. For a grouped response, record both \(y_j\) and \(m_j\).
For grouped data, compare with one fitted proportion per group. For individual binary data, the saturated reference can fit the individual 0/1 outcomes separately.
Use the deviance formula appropriate to the representation, and count response rows minus design-matrix rank. Do not substitute the trial total for the grouped row count.
Common Exam Trap
A frequent error is to expand grouped data conceptually into all its trials when counting residual degrees of freedom, while still using the grouped deviance formula. These choices refer to different response representations and different saturated models. A second error is to assume that equal fitted coefficients imply equal residual deviances. Equal coefficients can coexist with different absolute deviances because the reference likelihoods differ.
The degrees-of-freedom calculation is a bookkeeping fact about the fitted response representation. It does not, by itself, establish that a model is adequate or determine why a fit is poor. Interpret deviance and degrees of freedom together with the model specification and the form in which the data were supplied.
Check Your Understanding
For each problem, identify the relevant response representation before calculating.
- A grouped response has \(m=10\), \(y=3\), and fitted probability \(\hat p=0.20\), with \(Y\sim\operatorname{Binomial}(10,0.20)\). Calculate its deviance contribution to four decimal places. (Answer: 0.5634)
- A grouped-binomial model has 5 response rows and a design matrix of rank 3. What are its residual degrees of freedom? If the same trials are entered as 60 individual Bernoulli rows with design-matrix rank 3, what are the individual-row residual degrees of freedom? (Answer: 2 grouped; 57 individual)
- Twelve identical-predictor Bernoulli trials have 6 successes, and the fitted probability is 0.50. What are the grouped deviance and the individual-row deviance, to four decimal places? (Answer: 0.0000 grouped; 16.6355 individual)
- Two grouped rows each have \(m=10\). The first has \(y=0\) and fitted probability 0.25; the second has \(y=10\) and fitted probability 0.80. Calculate total deviance to four decimal places. If the design-matrix rank is 1, give the residual degrees of freedom. (Answer: 10.2165 deviance; 1 residual degree of freedom)