Tutorials › Generalized Linear Models › Poisson Goodness of Fit for Count Tables

Goodness of Fit and Calibration · Tutorial 786 of 981

Poisson Goodness of Fit for Count Tables

Use aggregate Poisson deviance and Pearson statistics to assess count-table fit and understand what fitted margins and cell discrepancies reveal.

Intermediate 11 min read

What You'll Learn

  • Define Poisson deviance and Pearson goodness-of-fit statistics for a count table
  • Compute both statistics from observed and fitted cell counts
  • Interpret a zero observed count without using an undefined logarithm
  • Relate fitted margins to the structure of a loglinear model
  • Identify the regularity conditions behind the chi-square reference approximation
  • Recognize when sparse expected counts make that approximation unreliable

Why assess fit across a count table?

A Poisson loglinear model assigns an expected count to each cell of a table. A goodness-of-fit assessment asks whether the observed counts are collectively compatible with those fitted expectations. Looking across the table matters: a model may reproduce some margins exactly while still missing the pattern of counts within cells. Two familiar summaries are the deviance and the Pearson statistic. They measure discrepancy in different ways, and their usual chi-square reference distributions are approximations whose reliability depends on the expected counts and the model.

The focus here is an aggregate assessment for a specified Poisson loglinear model. It is not a comparison between two candidate models. The fitted cell means, the model's constraints on those means, and the sampling assumptions all affect how the statistics should be read.

Poisson cell counts and the two statistics

Definition: Suppose a table has \(J\) non-structural cells, with observed counts \(Y_1,\ldots,Y_J\). Under Poisson sampling, the cell counts are independent and \(Y_k\sim\operatorname{Poisson}(\mu_k)\), where \(\mu_k>0\) is the model mean for cell \(k\). Let \(\hat\mu_k\) be the fitted mean. The aggregate Pearson statistic and Poisson deviance are $$ X^2=\sum_{k=1}^{J}\frac{(Y_k-\hat\mu_k)^2}{\hat\mu_k}, \qquad D=2\sum_{k=1}^{J}\left\{Y_k\log\left(\frac{Y_k}{\hat\mu_k}\right)-(Y_k-\hat\mu_k)\right\}. $$ For \(Y_k=0\), the term \(Y_k\log(Y_k/\hat\mu_k)\) is defined by continuity as zero.

The Pearson statistic adds squared residuals scaled by their fitted variances. The deviance compares the fitted model's Poisson log-likelihood with that of the saturated model, which assigns one unrestricted mean to each cell. The deviance contribution of cell \(k\) is nonnegative; for a zero count it is \(2\hat\mu_k\). Neither statistic says which cells drive the overall discrepancy, so it is useful to inspect cell-level residuals as well as the aggregate.

A loglinear model represents log means using specified predictors, commonly including row or column effects and selected interactions. The model's fitted means may therefore satisfy constraints such as reproducing selected margins. Those constraints affect the number of free parameters and hence the residual degrees of freedom.

Worked Example: A Two-by-Two Independence Fit

Suppose the observed table is

Column 1Column 2Row total
Row 112820
Row 261420
Column total182240

Under the row-and-column independence model, the fitted count is the product of the corresponding row and column totals divided by the grand total. The four fitted counts are therefore \(20(18)/40=9\), \(20(22)/40=11\), \(20(18)/40=9\), and \(20(22)/40=11\). They reproduce both sets of margins.

The Pearson statistic is $$ X^2=\frac{(12-9)^2}{9}+\frac{(8-11)^2}{11} +\frac{(6-9)^2}{9}+\frac{(14-11)^2}{11} =2+\frac{9}{11}+1+\frac{9}{11} =\frac{40}{11}\approx3.6364. $$

For the deviance, the observed and fitted totals are both 40, so the linear residual terms sum to zero. Thus $$ D=2\left[12\log(12/9)+8\log(8/11)+6\log(6/9)+14\log(14/11)\right]\approx3.6961. $$ The independence model has three free parameters in the four-cell table: two row effects and two column effects, less one redundant overall level. The residual degrees of freedom are \(4-3=1\). Both statistics are near 3.7, indicating a discrepancy that should be judged against a one-degree-of-freedom reference distribution, subject to the approximation conditions discussed below.

Degrees of freedom and the chi-square approximation

For a regular loglinear model with \(J\) cells and \(p\) identifiable free parameters, the residual degrees of freedom are \(J-p\). The count \(p\) is the dimension of the fitted mean model, not simply the number of terms printed in a formula: redundant parameters and constraints must be handled correctly. Structural-zero cells are not ordinary observed cells and should be excluded from \(J\).

Theorem: Consider a fixed number \(J\) of independent Poisson counts from a correctly specified, regular loglinear model of rank \(p\). Suppose the true cell means are positive and increase proportionally with a common exposure factor \(t\), with \(t\to\infty\); the model is identifiable and smooth in a neighborhood of the true parameter; and the information matrix is nonsingular. Then, under these conditions, both the Pearson statistic and the deviance converge in distribution to a chi-square random variable with \(J-p\) degrees of freedom.

The theorem gives the basis for the common reference approximation; it does not say that a chi-square distribution is exact for a finite table. Its large-exposure condition keeps every cell's expected count increasing. If some expected counts are small, the approximation can be poor even when the total count is large.

1
Standardize the counts.
At the true means, write \(W=\operatorname{diag}(\mu_1,\ldots,\mu_J)\). For Poisson counts, \(\operatorname{Var}(Y_k)=\mu_k\), so \(W^{-1/2}(Y-\mu)\) converges to a \(J\)-dimensional standard normal vector as all means grow proportionally.
2
Account for fitted parameters.
For a loglinear model with design matrix \(A\) of rank \(p\), the fitted residuals, to first order, are the standardized count fluctuations projected off the model's \(p\)-dimensional fitted tangent space. The corresponding projection onto that space is \(P=W^{1/2}A(A^\mathsf{T}WA)^{-1}A^\mathsf{T}W^{1/2}\), which has rank \(p\).
3
Obtain the limiting sum of squares.
The Pearson statistic is, to first order, the squared length of the standardized fluctuation after projection by \(I-P\). This is a projection of rank \(J-p\). A standard normal vector projected onto a fixed rank-\((J-p)\) subspace has squared length distributed as \(\chi^2_{J-p}\).
4
Relate deviance to Pearson's statistic.
Taylor expansion of each deviance contribution around the fitted mean gives \(2\{Y_k\log(Y_k/\hat\mu_k)-(Y_k-\hat\mu_k)\}=(Y_k-\hat\mu_k)^2/\hat\mu_k\) to second order, with the summed higher-order terms negligible in the stated increasing-mean regime. Thus the deviance has the same limiting distribution. \(\square\)

In a two-way independence model for an \(r\)-by-\(c\) table with positive fitted means, the model has \(r+c-1\) free parameters. Hence \(J-p=rc-r-c+1=(r-1)(c-1)\). This familiar result is a special case of the general parameter-count rule, not a separate count based on how many margins happen to be displayed.

Worked Example: A Common-Mean Model and a Zero Cell

Consider four independent Poisson counts \(0,10,20,30\), fitted by a model with a common mean. The total is 60, so the maximum-likelihood fitted mean in each cell is \(60/4=15\). The model has one free parameter, giving \(4-1=3\) residual degrees of freedom.

For the Pearson statistic, $$ X^2=\frac{(0-15)^2}{15}+\frac{(10-15)^2}{15} +\frac{(20-15)^2}{15}+\frac{(30-15)^2}{15} =15+\frac{25}{15}+\frac{25}{15}+15 =\frac{100}{3}\approx33.3333. $$

The zero count contributes \(2(15)=30\) to the deviance. For the other cells, retaining the linear terms in the defining formula gives $$ \begin{aligned} D=2\big[&15+10\log(10/15)+5\\ &+20\log(20/15)-5+30\log(30/15)-15\big] \approx44.9868. \end{aligned} $$ The linear terms cancel overall because the fitted and observed totals are both 60. Equivalently, \(D=2[10\log(10/15)+20\log(20/15)+30\log(30/15)]\approx44.9868\). The zero cell is well-defined in the deviance formula; it is not a reason to omit that cell from the table.

Fitted margins and cell-level discrepancies

In contingency tables, the model structure determines which margins are fitted exactly. For example, the two-way independence model fits row and column margins, while leaving the interaction pattern as the source of lack of fit. A small aggregate statistic indicates that the table is broadly compatible with the fitted pattern; it does not establish that every cell is close to its fitted count. Conversely, a few large cell discrepancies can dominate an aggregate statistic.

Worked Example: Independence With Fitted Row and Column Margins

Take this two-by-three table:

Column 1Column 2Column 3Row total
Row 18121030
Row 21281030
Column total20202060

Under independence, each fitted count is its row total times its column total divided by 60, so all six fitted counts are 10. The fitted margins agree with the observed margins. The Pearson statistic is $$ X^2=4\left(\frac{(8-10)^2}{10}\right)+2\left(\frac{(10-10)^2}{10}\right)=\frac{16}{10}=1.6. $$ The deviance is $$ D=2\left[2\{8\log(8/10)+12\log(12/10)\}\right]\approx1.6109. $$ There are \(6-(2+3-1)=2\) residual degrees of freedom. Although the margins match exactly, the table's interior cell pattern is not identical to independence: the deviations in the first two columns remain and contribute to both statistics.

Interpreting discrepancies and avoiding common errors

The Pearson statistic and deviance often tell a similar story, but they weight discrepancies differently. Pearson's contributions divide squared residuals by the fitted means. Deviance contributions use the Poisson likelihood and can respond differently to large relative departures. When the statistics disagree, inspect the cell contributions and expected counts rather than choosing whichever summary supports a preferred conclusion.

The chi-square approximation needs particular care with sparse tables. Small expected counts make the normal approximation to individual Poisson counts less reliable, and a handful of rare cells can make an aggregate reference p-value misleading. There is no universal expected-count cutoff that guarantees validity. Assess the number and pattern of small fitted counts, the table structure, and whether the sampling model is credible. A zero observed count alone does not imply a sparse expected count: in the common-mean example, that cell had fitted mean 15.

  • Do not log zero as an ordinary number. Use the limiting convention \(0\log(0/\hat\mu_k)=0\); the zero cell still contributes \(2\hat\mu_k\) to deviance.
  • Do not drop the linear terms cell by cell without checking. They cancel in the total only when the fitted and observed totals agree, as they do for a model with an intercept fitted to the total.
  • Do not count displayed model terms mechanically. Use the rank of the identifiable mean model to obtain \(J-p\).
  • Do not treat fitted margins as proof of overall fit. Margins can match exactly while cell-level interactions remain unexplained.
  • Do not interpret the chi-square approximation as exact. It depends on the Poisson assumptions, a regular interior fit, and sufficiently large expected counts.

These statistics assess fit under the Poisson variance assumption \(\operatorname{Var}(Y_k)=\mu_k\). If variability beyond that assumption is present, the usual reference assessment can be misleading; the consequences of estimating a dispersion adjustment require separate treatment.

Key takeaway: Compute aggregate deviance and Pearson statistics from the fitted cell means, use the identifiable model rank to determine residual degrees of freedom, and interpret the results alongside fitted margins and expected cell counts. A reference chi-square value is an approximation, not a substitute for checking the table and its assumptions.

Check Your Understanding

Use the definitions and examples above to answer these questions.

  1. For a table with 12 non-structural cells and a regular loglinear model of rank 8, what are the residual degrees of freedom?
  2. What is the deviance contribution of a cell with observed count zero and fitted mean 4?
  3. In a two-way independence model, which margins are fitted, and what kind of cell pattern can still contribute to lack of fit?
  4. Why can a large total count fail to ensure a reliable chi-square approximation in a table with sparse cells?
  5. When do the linear terms in the total Poisson deviance cancel, and why should they not automatically be omitted from each individual cell contribution?
Clinical Biostats