Introduction
A contingency table records counts for combinations of categories. A Poisson loglinear model treats those cell counts as responses and represents patterns in their expected counts through main effects and interactions. Comparing a model with main effects only to one that includes interactions gives a direct test of whether the two categorical variables are associated.
The key is to keep the statistical question and the calculation connected: the added interaction terms specify the alternative hypothesis, and the difference in deviances measures how much the fitted likelihood improves when those terms are included. The test is approximate in general, so its chi-square interpretation depends on the usual regularity and large-sample conditions for a likelihood-ratio test.
Independence and Association in Loglinear Models
Let \(Y_{ij}\) be the count in row category \(i\) and column category \(j\) of an \(r\)-by-\(c\) table, where \(i=1,\ldots,r\) and \(j=1,\ldots,c\). In the Poisson sampling formulation, the cell counts are independent Poisson random variables with means \(\mu_{ij}>0\). Write \(y_{ij}\) for the observed count.
The parameters in a loglinear model need constraints for unique parameter labels. For example, one may impose sum-to-zero constraints on the row and column effects, and corresponding margin constraints on interaction effects. These constraints identify the parameters; they do not change the fitted means or the hypotheses being tested.
For a two-by-two table, the independence hypothesis is \(\mu_{11}\mu_{22}=\mu_{12}\mu_{21}\), or, equivalently, \(\mu_{11}\mu_{22}/(\mu_{12}\mu_{21})=1\). In larger tables, independence requires this cross-product equality for every choice of two rows and two columns. Thus, adding the interaction block tests whether the table needs association terms beyond its row and column main effects.
Fitting the Independence Model
Let \(y_{i+}=\sum_j y_{ij}\) be the observed row totals, \(y_{+j}=\sum_i y_{ij}\) the observed column totals, and \(n=\sum_i\sum_j y_{ij}\) the grand total. The independence-model fitted means are the products of the corresponding margins divided by the grand total.
To verify the result, write the Poisson log-likelihood, omitting no terms that depend on the means, as \(\ell=\sum_{i,j}\{y_{ij}\log(\mu_{ij})-\mu_{ij}-\log(y_{ij}!)\}\). Under independence, \(\mu_{ij}=\exp(\lambda+\alpha_i+\beta_j)\). The score for a row effect is the observed row total minus its fitted row total, and the score for a column effect is the observed column total minus its fitted column total. The score for the intercept is the observed grand total minus the fitted grand total.
Now set \(\hat{\mu}_{ij}=y_{i+}y_{+j}/n\). Summing over columns gives \(\sum_j\hat{\mu}_{ij}=y_{i+}(\sum_j y_{+j})/n=y_{i+}\), because \(\sum_j y_{+j}=n\). Similarly, \(\sum_i\hat{\mu}_{ij}=y_{+j}\), and summing all fitted cells gives \(n\). Every score is therefore zero. The log-likelihood is concave in the canonical parameters: its Hessian is \(-X^\mathsf{T}\operatorname{diag}(\mu_{ij})X\), where \(X\) is the model matrix. After imposing identifying constraints, \(X\) has full column rank, so this Hessian is negative definite for positive fitted means. The stationary fit is consequently the maximum-likelihood fit. \(\square\)
If a row or column total is zero, the displayed fitted means include zeros and the maximum can lie on the boundary rather than at finite loglinear parameter values. The worked tables below have positive margins, so the interior argument applies directly.
From Deviance to the Test Statistic
For any fitted model \(M\), its deviance is twice the log-likelihood difference between the saturated model and \(M\). In a table with positive observed counts, the saturated model fits \(\hat{\mu}_{ij}=y_{ij}\). Subtracting the two Poisson log-likelihoods gives \(D(M)=2\sum_{i,j}\{y_{ij}\log(y_{ij}/\hat{\mu}_{ij})-(y_{ij}-\hat{\mu}_{ij})\}\).
Both the independence fit and the saturated fit have fitted grand total \(n\). Therefore the linear difference terms sum to zero for their deviance difference, giving the familiar likelihood-ratio statistic for independence:
For the saturated model, \(D(\text{saturated})=0\). A zero observed count contributes zero to the sum, using the convention \(0\log(0/x)=0\) for \(x>0\). The statistic is also \(2\{\ell(\text{saturated})-\ell(\text{independence})\}\), because the Poisson factorial terms cancel in the likelihood ratio.
The independence model has \(r+c-1\) identifiable parameters: one overall level and \(r-1\) and \(c-1\) independent main-effect contrasts. The saturated model has \(rc\) cell means. Their dimension difference is \(rc-(r+c-1)=(r-1)(c-1)\). Under the null hypothesis, with independent Poisson sampling, positive means, an identifiable regular model, and a large-sample regime in which expected counts grow, the likelihood-ratio statistic is approximately chi-square with \((r-1)(c-1)\) degrees of freedom. This is the standard nested-model likelihood-ratio calibration.
Worked Example: Testing Association in a Two-by-Two Table
Suppose the observed counts for two binary characteristics are \((30,10)\) in the first row and \((20,40)\) in the second row. The row totals are \(40\) and \(60\), the column totals are \(50\) and \(50\), and \(n=100\). Compare independence with the saturated model.
Under independence, the fitted counts are the products of margins divided by 100: \(\hat{\mu}_{11}=40(50)/100=20\), \(\hat{\mu}_{12}=40(50)/100=20\), \(\hat{\mu}_{21}=60(50)/100=30\), and \(\hat{\mu}_{22}=60(50)/100=30\). Thus the observed and fitted tables are \[ \begin{pmatrix}30&10\\20&40\end{pmatrix} \quad\text{and}\quad \begin{pmatrix}20&20\\30&30\end{pmatrix}. \]
Calculate the likelihood-ratio statistic cell by cell: \(G^2=2\{30\log(30/20)+10\log(10/20)+20\log(20/30)+40\log(40/30)\}\). The four terms inside braces are approximately \(12.16395\), \(-6.93147\), \(-8.10930\), and \(11.50728\). Their sum is \(8.63046\), so \(G^2\approx17.2609\).
There is one added interaction degree of freedom, since \((2-1)(2-1)=1\). The chi-square reference tail probability is approximately \(0.00003\). The observed table provides strong evidence against independence, under the stated large-sample calibration. Its observed odds ratio is \((30\cdot40)/(10\cdot20)=6\), consistent with the direction of association reflected by the interaction. This test does not, by itself, establish a causal relationship.
Worked Example: A Two-by-Three Independence Test
Consider the table with first-row counts \(20,30,50\) and second-row counts \(40,30,30\). The row totals are both \(100\), the column totals are \(60,60,80\), and \(n=200\). The independence-model expected counts in each row are therefore \(30,30,40\).
The deviance difference is \(G^2=2\{20\log(20/30)+30\log(30/30)+50\log(50/40)+40\log(40/30)+30\log(30/30)+30\log(30/40)\}\). The six terms in braces are approximately \(-8.10930,0,11.15718,11.50728,0,-8.63046\), with sum \(5.92470\). Hence \(G^2\approx11.8494\).
The degrees of freedom are \((2-1)(3-1)=2\). For a chi-square variable with two degrees of freedom, the upper-tail probability at this value is \(\exp(-G^2/2)=\exp(-5.92470)\approx0.00267\). The table therefore gives evidence that row and column category are associated. The result tests the interaction block jointly; it does not identify which cell differences are responsible without further examination.
Worked Example: Observed Counts Exactly Consistent With Independence
Take the two-by-two table with rows \((12,18)\) and \((8,12)\). The row totals are \(30,20\), the column totals are \(20,30\), and the grand total is \(50\). The fitted counts under independence are \(30(20)/50=12\), \(30(30)/50=18\), \(20(20)/50=8\), and \(20(30)/50=12\). They match every observed cell.
Each log ratio in the deviance calculation is \(\log(1)=0\), so \(G^2=0\). The observed odds ratio is \((12\cdot12)/(18\cdot8)=144/144=1\), also matching the independence hypothesis. The statistic indicates no likelihood improvement from adding the interaction for these data. It does not prove that the underlying variables are independent; it says that this table shows no departure from the fitted independence model.
Common Pitfall and Interpretation
A frequent error is to use the deviance of the smaller model alone as though it were the comparison statistic. The test statistic is the difference in deviances, with the reduced-model deviance first: \(D(\text{independence})-D(\text{saturated})\). Since the saturated model has zero deviance here, the difference equals the independence-model deviance, but that shortcut depends on this specific full model. In a comparison of two nonsaturated nested models, both deviances must be fitted and subtracted.
Another error is to treat an interaction test as a test of causation. The null hypothesis is a statement about association in the modeled cell means. Study design and other assumptions determine whether a causal interpretation is warranted. Likewise, a small \(p\)-value indicates incompatibility with the null model under the reference distribution; it does not quantify the practical importance of the association.
Check Your Understanding
Use these questions to check both the modeling interpretation and the calculation.
- For an \(r\)-by-\(c\) table, what null hypothesis is represented by the Poisson loglinear model with row and column main effects only?
- Explain why the independence-model fitted mean in cell \((i,j)\) is \(y_{i+}y_{+j}/n\).
- What are the degrees of freedom for testing independence in a three-by-four table?
- Why is the likelihood-ratio statistic formed as the reduced-model deviance minus the larger-model deviance?
- If the test rejects independence, what does that establish, and what does it not establish?