Tutorials › Generalized Linear Models › Individual and Grouped Binomial Data

Detecting Overdispersion · Tutorial 661 of 981

Individual and Grouped Binomial Data

Understand why individual Bernoulli and grouped binomial records can give different diagnostic totals even when they encode the same fitted probabilities.

Intermediate 10 min read

What You'll Learn

  • Write Pearson and deviance contributions for individual Bernoulli trials and grouped binomial counts.
  • Derive the exact differences between the two representations when each group shares one fitted probability.
  • Interpret how trial totals and within-group success proportions affect diagnostic totals.
  • Calculate diagnostics for groups with zero or full success counts using endpoint conventions.
  • Explain why grouping changes residual degrees of freedom and why the diagnostic totals should not be compared naively.

Why the Data Representation Matters

A binomial response can be stored one trial at a time, with each observation recorded as a success or failure, or as a count of successes out of a known number of trials. These representations can encode the same outcomes and use the same fitted success probabilities. Yet their Pearson and deviance diagnostics need not be equal. The reason is not a different mean model: the two representations use different saturated reference models and aggregate the trial-level residual information differently.

This distinction matters when interpreting a dispersion check. A grouped row represents a success count out of \(m_i\) trials; it is not equivalent, for diagnostic bookkeeping, to a single Bernoulli observation. The formulas below assume that all trials within a group have the same fitted probability. If trial-level fitted probabilities differ, the group generally cannot be represented by one ordinary binomial count with a common probability.

Definitions for the Two Representations

For group \(i\), let \(m_i\) be its positive integer number of trials, \(Y_i\) its observed number of successes, and \(\hat p_i\) its fitted success probability, with \(0\leq Y_i\leq m_i\) and \(0<\hat p_i<1\). Write \(\hat\mu_i=m_i\hat p_i\) for its fitted success count. The grouped binomial variance under the fitted model is \(m_i\hat p_i(1-\hat p_i)\).

Definition: The grouped Pearson contribution for group \(i\) is \(\displaystyle (Y_i-m_i\hat p_i)^2/\{m_i\hat p_i(1-\hat p_i)\}\). Its grouped binomial deviance contribution is \(\displaystyle 2\left[Y_i\log\{Y_i/(m_i\hat p_i)\}+(m_i-Y_i)\log\{(m_i-Y_i)/(m_i(1-\hat p_i))\}\right]\). A term with observed count zero is defined to be zero, using the convention \(0\log 0=0\).

For individual data, let \(Z_{ij}\in\{0,1\}\) denote trial \(j\) in group \(i\), so \(Y_i=\sum_{j=1}^{m_i} Z_{ij}\). Each trial has fitted probability \(\hat p_i\). Its Pearson contribution is \((Z_{ij}-\hat p_i)^2/\{\hat p_i(1-\hat p_i)\}\). Its Bernoulli deviance contribution is \(2[Z_{ij}\log(1/\hat p_i)+(1-Z_{ij})\log\{1/(1-\hat p_i)\}]\).

The individual deviance compares each trial with a saturated Bernoulli model, whose fitted probability for that observed trial is zero or one. The grouped deviance instead compares the observed group count with a saturated binomial model, whose fitted probability is \(Y_i/m_i\). This difference between reference models is central to the results below.

Worked Examples

Worked Example: Four Trials With Two Successes

Suppose \(m=4\), \(Y=2\), and \(\hat p=0.5\). The observed success proportion is \(q=Y/m=0.5\).

Grouped Pearson contribution. The fitted count is \(4(0.5)=2\), and the binomial variance is \(4(0.5)(0.5)=1\). Therefore the contribution is \((2-2)^2/1=0\).

Individual Pearson total. Each of the two successes contributes \((1-0.5)^2/0.25=1\); each of the two failures also contributes \((0-0.5)^2/0.25=1\). The total is \(1+1+1+1=4\).

Grouped deviance. The grouped saturated probability is \(2/4=0.5\), equal to the fitted probability, so both logarithms are \(\log(1)=0\) and the contribution is zero.

Individual deviance total. Each of the four trials contributes \(2\log 2\), so the total is \(8\log 2\approx5.5452\). The individual total exceeds the grouped total: the individual saturated model can fit each observed trial perfectly, while the grouped saturated model only matches the group proportion.

Worked Example: A Zero-Success Group and a Full-Success Group

Take two groups, each with \(m=5\) trials and fitted probability \(\hat p=0.2\). In the first group \(Y=0\); in the second \(Y=5\). The fitted count is \(1\), and the variance is \(5(0.2)(0.8)=0.8\) for each group.

Zero successes. The Pearson contribution is \((0-1)^2/0.8=1.25\). The deviance contribution is \(2[0+5\log\{5/4\}]=-10\log(0.8)\approx2.2314\). Every individual outcome is a failure, so its Pearson total is \(5(0.2)^2/0.16=1.25\), and its deviance total is \(-10\log(0.8)\approx2.2314\).

Five successes. The Pearson contribution is \((5-1)^2/0.8=20\). The grouped deviance is \(2[5\log(5/1)+0]=10\log 5\approx16.0944\). The individual Pearson total is \(5(0.8)^2/0.16=20\), and the individual deviance total is \(-10\log(0.2)=10\log 5\approx16.0944\).

At these endpoints, the individual and grouped totals agree. The difference formulas below are zero when the observed proportion is zero or one. The calculations also show why endpoint groups should not be discarded: their contributions are well-defined when the fitted probability is strictly between zero and one.

Exact Relationships Between the Totals

Consider one group with \(m\) trials, observed success count \(y\), fitted probability \(p\in(0,1)\), and observed proportion \(q=y/m\). The identities in this section hold for any such values, so they also hold when \(p\) is an estimated fitted probability. They are algebraic comparisons of the diagnostics, not claims about their sampling distributions.

Theorem: When every trial in a group has the same fitted probability \(p\), the individual Pearson total minus the grouped Pearson contribution is \(\displaystyle m q(1-q)/\{p(1-p)\}\). The individual deviance total minus the grouped deviance contribution is \(\displaystyle -2m\{q\log q+(1-q)\log(1-q)\}\), where \(0\log 0=0\). Both differences are nonnegative.

Proof for Pearson diagnostics. Summing the individual contributions over \(y\) successes and \(m-y\) failures gives

$$ P_{\mathrm{individual}} = y\frac{1-p}{p}+(m-y)\frac{p}{1-p} = m\left\{q\frac{1-p}{p}+(1-q)\frac{p}{1-p}\right\}. $$

The grouped contribution is \(P_{\mathrm{grouped}}=m(q-p)^2/\{p(1-p)\}\). Subtracting and putting the terms over a common denominator yields

$$ P_{\mathrm{individual}}-P_{\mathrm{grouped}} = \frac{m\{q(1-p)^2+(1-q)p^2-(q-p)^2\}}{p(1-p)} = \frac{m q(1-q)}{p(1-p)}. $$

The last equality follows by expanding the numerator: \(q(1-p)^2+(1-q)p^2-(q-p)^2=q-q^2\). Since \(0\leq q\leq1\) and \(0<p<1\), the difference is nonnegative; it is zero exactly when \(q=0\) or \(q=1\).

Proof for deviance diagnostics. Summing the individual deviance contributions gives \(\displaystyle D_{\mathrm{individual}}=2m\{q\log(1/p)+(1-q)\log(1/(1-p))\}\). The grouped contribution is \(\displaystyle D_{\mathrm{grouped}}=2m\{q\log(q/p)+(1-q)\log((1-q)/(1-p))\}\). Subtracting cancels the terms involving the fitted probability:

$$ D_{\mathrm{individual}}-D_{\mathrm{grouped}} = -2m\{q\log q+(1-q)\log(1-q)\}. $$

For \(0<q<1\), both logarithms inside braces are negative, so the expression in braces is negative and the displayed difference is positive. At \(q=0\) or \(q=1\), the convention \(0\log0=0\) gives a difference of zero. Thus the difference is nonnegative for every allowed \(q\). This completes the proof. \(\square\)

The deviance difference is twice \(m\) times the binary entropy of the observed proportion, using natural logarithms. It is largest for proportions near one half and vanishes at the endpoints. For example, at \(m=4\) and \(q=0.5\), it is \(-8\{0.5\log(0.5)+0.5\log(0.5)\}=8\log2\approx5.5452\), agreeing with the first worked example.

Worked Example: Unequal Trial Totals Across Groups

Consider three groups with \((m_i,Y_i,\hat p_i)\) equal to \((2,1,0.25)\), \((4,3,0.5)\), and \((3,0,0.2)\). The fitted probabilities are constant within each group, but the trial totals and probabilities differ between groups.

Grouped Pearson total. For the first group, the residual is \(1-0.5=0.5\) and the variance is \(2(0.25)(0.75)=0.375\), giving \(0.25/0.375=2/3\). For the second, the residual is \(3-2=1\) and the variance is \(4(0.5)(0.5)=1\), giving \(1\). For the third, the residual is \(0-0.6=-0.6\) and the variance is \(3(0.2)(0.8)=0.48\), giving \(0.36/0.48=0.75\). The grouped total is \(2/3+1+0.75=29/12\approx2.4167\).

Individual Pearson total. The exact excess for the first group is \(2(0.5)(0.5)/\{(0.25)(0.75)\}=8/3\); for the second it is \(4(0.75)(0.25)/0.25=3\); and for the third it is zero because its observed proportion is zero. Therefore the individual total is \(29/12+8/3+3=89/12\approx7.4167\).

Grouped deviance total. The first contribution is \(2\log(4/3)\approx0.5754\). The second is \(2\{3\log(3/2)+\log(1/2)\}\approx1.0465\). The third is \(-6\log(0.8)\approx1.3389\). Their sum is approximately \(2.9608\).

Individual deviance total. The first group adds \(-4\{0.5\log(0.5)+0.5\log(0.5)\}=2.7726\) to its grouped contribution. The second adds \(-8\{0.75\log(0.75)+0.25\log(0.25)\}\approx4.4987\). The third adds zero. The individual total is therefore approximately \(2.9608+2.7726+4.4987=10.2321\) (rounding the unrounded grouped terms gives approximately \(10.2326\)).

The trial totals matter in both sums: each group’s contribution and the individual-versus-grouped difference scale with \(m_i\). One must use each group’s own fitted probability and trial total rather than treating all three rows as single Bernoulli observations.

Likelihood, Degrees of Freedom, and Interpretation

When trials in a group have the same covariates and probability, grouping does not change the fitted parameter estimates under the ordinary binomial likelihood. The individual likelihood contribution is \(p^y(1-p)^{m-y}\); the grouped binomial likelihood contribution is \(\binom{m}{y}p^y(1-p)^{m-y}\). The factor \(\binom{m}{y}\) does not depend on the model parameters, so it does not change the maximizer. But the saturated likelihoods used to define deviance do differ, which explains why equal fitted estimates do not imply equal deviances.

Grouping also changes the row count used in the usual residual degrees of freedom. If there are \(G\) grouped rows and the fitted model matrix has rank \(r\), the usual grouped residual degrees of freedom are \(G-r\). If the same trials are entered as \(N=\sum_i m_i\) Bernoulli rows with replicated covariates and the same rank \(r\), the individual-data convention gives \(N-r\). These bookkeeping differences are one reason not to compare the resulting Pearson or deviance ratios as if they were calculated from the same observational units.

The binomial variance benchmark is \(m_i p_i(1-p_i)\) for a grouped count and \(p_i(1-p_i)\) for one Bernoulli trial. The identities proved above describe how the residual totals change under aggregation; they do not establish that either representation is evidence of extra variation. Interpretation still depends on how the data were collected and modeled, as well as on the diagnostic calibration appropriate to that representation.

Common Mistakes

  • Treating a group as one Bernoulli trial. A row with \(Y_i=3\) successes out of \(m_i=4\) trials is a binomial count, not a single success indicator. Use its trial total in both its fitted count and its variance.
  • Assuming the grouped and individual deviances are equal. The fitted probabilities may match, but the saturated reference models differ. The exact difference is nonnegative, and its sign is \(-2m\{q\log q+(1-q)\log(1-q)\}\), not \(2m\) times the expression in braces.
  • Dropping zero- or full-success groups because a logarithm appears to be undefined. Apply \(0\log0=0\), or use the endpoint formulas. With an interior fitted probability, both diagnostics are finite at either endpoint.
  • Collapsing trials that have different fitted probabilities. The identities require one common fitted probability within each group. If probabilities vary across trials, a single grouped binomial likelihood generally does not preserve the individual model.
Key takeaway: Preserve the trial total and the data representation when calculating binomial diagnostics. With a common fitted probability within each group, individual Pearson and deviance totals exceed or equal grouped totals by explicit nonnegative amounts; those totals and their degrees of freedom should not be interchanged.

Check Your Understanding

Use the definitions and identities above to answer these questions.

  1. For \(m=6\), \(y=3\), and fitted probability \(p=0.4\), calculate the difference between the individual and grouped Pearson contributions.
  2. Why can grouped and individual data produce the same fitted parameter estimate but different deviance values?
  3. For a group with \(y=0\), write its grouped Pearson and deviance contributions in terms of \(m\) and \(p\).
  4. At which observed proportions is the individual-minus-grouped deviance difference zero, and why?
  5. What condition on fitted probabilities is needed before replacing trial-level Bernoulli observations by one grouped binomial count?
Clinical Biostats