Tutorials › VEE Mathematical Statistics › Likelihood Ratio Tests Of Contingency Table Independence

VEE Mathematical Statistics · Likelihood Ratio Tests · Tutorial 643 of 880

Likelihood Ratio Tests Of Contingency Table Independence

Learn how independence determines fitted cell counts and how to use the likelihood ratio statistic to assess association in a contingency table.

Advanced 10 min read

What You'll Learn

  • State the multinomial model and null hypothesis for independence in an r-by-c table
  • Derive fitted expected counts from the row and column totals
  • Compute the G-squared likelihood ratio statistic, including cells with zero observations
  • Determine the degrees of freedom by comparing model parameter counts
  • Use the chi-square approximation and recognize conditions that can make it unreliable

Why Test Independence in a Contingency Table?

A contingency table records counts for two categorical variables measured on the same observational units. For example, a hypothetical study might record both the type of a claim and whether it was resolved within a specified period. The central question is whether the distribution of one variable changes across the categories of the other. A likelihood ratio test answers that question by comparing the best-fitting model under independence with a model that allows every cell probability to vary freely.

The test is aligned with the SOA VEE Mathematical Statistics syllabus. Its essential steps are to fit the independence model from the table margins, compare its likelihood with the unrestricted likelihood, and use the difference in model dimensions to determine the degrees of freedom.

Definition: In an \(r\)-by-\(c\) contingency table, let \(n_{ij}\) be the observed count in row \(i\), column \(j\), with row totals \(n_{i+}\), column totals \(n_{+j}\), and total \(N\). The variables are independent when their joint cell probabilities factor as \(p_{ij}=\alpha_i\beta_j\), where \(\sum_i\alpha_i=1\) and \(\sum_j\beta_j=1\).

Assume the \(N\) observational units are independent and each belongs to exactly one of the \(rc\) cells. Conditional on the fixed total \(N\), the cell counts then have a multinomial distribution with cell probabilities \(p_{ij}\). The null hypothesis is independence, \(H_0:p_{ij}=\alpha_i\beta_j\). The alternative is the unrestricted multinomial model, in which the \(rc\) cell probabilities need only sum to one. The ordinary test also assumes there are no structural zeros: a structural zero is a cell that is impossible by design, rather than a possible outcome that happened not to be observed.

Fitting the Independence Model

Under independence, the fitted probability for a cell is the product of its fitted row probability and fitted column probability. The data estimate those marginal probabilities by the observed proportions in the margins. Multiplying the fitted cell probability by \(N\) gives the fitted expected count.

$$ \widehat{\alpha}_i=\frac{n_{i+}}{N}, \qquad \widehat{\beta}_j=\frac{n_{+j}}{N}, \qquad E_{ij}=N\widehat{\alpha}_i\widehat{\beta}_j =\frac{n_{i+}n_{+j}}{N}. $$

The fitted counts preserve the observed margins: \(\sum_j E_{ij}=n_{i+}\) and \(\sum_i E_{ij}=n_{+j}\). These are expected counts under the fitted null model, not additional observed data. They are generally fractional, which is appropriate for model expectations.

Worked Example: Fitting Expected Counts in a Two-by-Three Table

A hypothetical service review classifies 100 cases by request type and whether the case was completed in the first, second, or third time band. The observed table is shown below. Test independence using a likelihood ratio test at the 5% significance level.

First bandSecond bandThird bandRow total
Type A20101040
Type B10203060
Column total303040100

Method: fit independence, then compare likelihoods. For Type A in the first band, the expected count is \(40(30)/100=12\). Applying the same calculation to every cell gives

$$ \begin{array}{c|rrr} &\text{First}&\text{Second}&\text{Third}\\ \hline \text{Type A}&12&12&16\\ \text{Type B}&18&18&24 \end{array} $$

The G-squared statistic is \(2\sum_{i,j} n_{ij}\ln(n_{ij}/E_{ij})\). The six cell contributions before multiplying by 2 are \(20\ln(20/12)=10.2165\), \(10\ln(10/12)=-1.8232\), \(10\ln(10/16)=-4.7000\), \(10\ln(10/18)=-5.8779\), \(20\ln(20/18)=2.1072\), and \(30\ln(30/24)=6.6943\). Their sum is \(6.6169\), so \(G^2=2(6.6169)=13.2338\).

The degrees of freedom are \((2-1)(3-1)=2\). The 5% upper-tail critical value for a chi-square distribution with 2 degrees of freedom is 5.991. Since \(13.2338>5.991\), reject independence at the 5% level. The data provide evidence of an association between request type and time band. This calculation avoids the common mistake of treating the six cell probabilities as six free parameters under the null; independence constrains them.

Deriving the Likelihood Ratio Statistic

The likelihood comparison makes precise why the statistic uses observed counts divided by fitted counts. Under the multinomial model, the likelihood is proportional to \(\prod_{i,j}p_{ij}^{n_{ij}}\); the multinomial coefficient is the same under both hypotheses and cancels in the likelihood ratio. Under the unrestricted model, the maximum likelihood estimate is \(\widehat p_{ij}=n_{ij}/N\). Under independence, it is \(\widehat p_{ij}=(n_{i+}/N)(n_{+j}/N)=E_{ij}/N\).

1
Write the maximized likelihoods.
Ignoring the common multinomial coefficient, the unrestricted maximum is \(\prod_{i,j}(n_{ij}/N)^{n_{ij}}\), and the independence maximum is \(\prod_{i,j}(E_{ij}/N)^{n_{ij}}\).
2
Form the likelihood ratio.
The likelihood ratio is the null-model maximum divided by the unrestricted maximum. Taking minus twice its logarithm gives \(-2\sum_{i,j}n_{ij}\ln[(E_{ij}/N)/(n_{ij}/N)]\).
3
Simplify.
The factors \(N\) cancel inside each logarithm, leaving \(G^2=2\sum_{i,j}n_{ij}\ln(n_{ij}/E_{ij})\). A large value means the unrestricted model fits substantially better than independence.
Theorem: For a table with positive row and column probabilities, no structural zeros, and independent observational units, the likelihood ratio statistic for independence is \(G^2=2\sum_{i,j}n_{ij}\ln(n_{ij}/E_{ij})\). If \(n_{ij}=0\), define that cell's contribution as \(0\). Under \(H_0\), its large-sample reference distribution is approximately chi-square with \((r-1)(c-1)\) degrees of freedom.

The degrees of freedom follow by counting parameters. The unrestricted multinomial model has \(rc-1\) free parameters because the \(rc\) probabilities sum to one. Under independence, the row probabilities have \(r-1\) free parameters and the column probabilities have \(c-1\), for a total of \(r+c-2\). The difference is

$$ (rc-1)-(r+c-2)=(r-1)(c-1). $$

This is the number of independent restrictions imposed by the independence hypothesis. It is also the degrees of freedom for the usual asymptotic likelihood ratio test.

Interpreting and Checking the Test

The chi-square calibration is an approximation, not an exact identity for every finite table. It is most dependable when the sample is large enough that the expected counts are not too small. There is no single absolute threshold that guarantees accuracy in every setting, so examine the fitted counts and be cautious when many are small. If the approximation is poor, the usual chi-square p-value may not be reliable; an exact or other suitable method may be needed.

A zero observed count is different from a structural zero. If an otherwise possible cell happens to have no observations, its contribution to \(G^2\) is defined by the limit \(n\ln(n/E)\to0\) as \(n\) decreases to zero. The cell remains in the table and its expected count is still calculated from the margins. If a cell is structurally impossible, however, the ordinary full-table independence model and its degrees-of-freedom formula do not automatically apply; the model must be formulated for the allowed cells.

Worked Example: A Possible Cell With No Observations

In a hypothetical equipment audit, 40 units are classified by design group and whether a specified inspection flag was recorded. The observed table is \(\begin{pmatrix}20&0\\0&20\end{pmatrix}\). Assume all four outcomes are possible, and test independence at the 5% level.

Method: retain all possible cells and use the zero-count convention. Both row totals are 20, both column totals are 20, and \(N=40\). Therefore every fitted expected count is \(20(20)/40=10\). The two zero-count cells contribute zero. The other two contribute \(20\ln(20/10)=20\ln 2\) each, so

$$ G^2=2\{20\ln 2+0+0+20\ln 2\} =80\ln 2 =55.4518. $$

The degrees of freedom are \((2-1)(2-1)=1\), and the 5% critical value is 3.841. Since \(55.4518>3.841\), reject independence. All four expected counts equal 10, so this example does not raise a small-expected-count concern. The common mistake is to delete a cell just because its observed count is zero; doing so would change the model and the test.

Worked Example: Reading a Weak Departure From Independence

A hypothetical screening program records two categories of follow-up and two categories of a screening result for 80 participants. The counts are \(\begin{pmatrix}30&10\\10&30\end{pmatrix}\). Calculate the likelihood ratio statistic and decide at the 5% level.

Method: compare each observed count with the count fitted from the margins. Each row total and each column total is 40, and \(N=80\). Thus all expected counts are \(40(40)/80=20\). The log contributions are \(30\ln(30/20)=30\ln(1.5)=12.1640\) for each of the two 30-count cells, and \(10\ln(10/20)=10\ln(0.5)=-6.9315\) for each of the two 10-count cells. The sum is \(2(12.1640)+2(-6.9315)=10.4650\), giving

$$ G^2=2(10.4650)=20.9300, \qquad \text{df}=1. $$

Because \(20.9300>3.841\), reject independence at the 5% level. The negative contributions from cells below their fitted counts are intentional: the statistic combines all cells, and the total deviance is nonnegative. A mistake is to discard negative cell terms or to take their absolute values; neither operation is part of the likelihood ratio calculation.

Common Exam Traps

  • Forgetting to divide by the grand total. The expected count is \(n_{i+}n_{+j}/N\), not just the product of the margins. Without division by \(N\), the fitted counts will not sum to \(N\).
  • Using the wrong degrees of freedom. Do not use \(rc-1\), the unrestricted parameter count, as the test's degrees of freedom. Subtract the independence-model parameter count to get \((r-1)(c-1)\).
  • Confusing an observed zero with an impossible cell. An observed zero contributes zero to the statistic, but remains a possible cell. A structural zero requires a different model formulation.
  • Interpreting rejection too broadly. Rejection indicates evidence against independence; it does not by itself identify which categories drive the association or establish a causal relationship.
  • Using the approximation without checking expected counts. The chi-square reference distribution is asymptotic. Small expected counts can make its calibration unreliable, even when the statistic itself is computed correctly.
Key takeaway: Fit independence from the observed margins, calculate \(G^2=2\sum n_{ij}\ln(n_{ij}/E_{ij})\), and compare it with a chi-square distribution having \((r-1)(c-1)\) degrees of freedom. The test relies on independent observational units and an adequate large-sample approximation.

Check Your Understanding

For each table, compute fitted counts from the margins before calculating or interpreting the test. Unless stated otherwise, assume independent observational units and no structural zeros.

  1. A hypothetical two-category review has counts \(\begin{pmatrix}18&12\\12&18\end{pmatrix}\). Find the expected counts, \(G^2\), and degrees of freedom; state the 5% decision. (Answer: expected counts 15 in every cell; \(G^2=2.4163\), df \(=1\); do not reject at 5%.)
  2. A hypothetical study records two groups across three outcome bands, with table \(\begin{pmatrix}14&6&10\\6&14&10\end{pmatrix}\). Find the fitted counts and test at 5%. (Answer: expected counts 10 in every cell; \(G^2=6.5826\), df \(=2\); reject at 5%.)
  3. A hypothetical audit yields \(\begin{pmatrix}24&16\\12&28\end{pmatrix}\). Calculate the expected table and \(G^2\), then compare with the 5% critical value. (Answer: expected table \(\begin{pmatrix}18&22\\18&22\end{pmatrix}\); \(G^2\approx7.3921\), df \(=1\); reject at 5%.)
  4. A hypothetical program records counts \(\begin{pmatrix}9&3\\6&6\\5&11\end{pmatrix}\) in a three-by-two table. Find the fitted counts, degrees of freedom, and test decision at 5%. (Answer: expected table \(\begin{pmatrix}6&6\\6&6\\8&8\end{pmatrix}\); \(G^2\approx5.4454\), df \(=2\); do not reject at 5%.)
  5. A hypothetical two-by-two table has counts \(\begin{pmatrix}25&0\\5&20\end{pmatrix}\), and all four outcomes are possible. Compute the fitted counts and \(G^2\), treating the zero correctly. (Answer: expected table \(\begin{pmatrix}15&10\\15&10\end{pmatrix}\); \(G^2=2[25\ln(5/3)+5\ln(1/3)+20\ln2]\approx42.2810\), df \(=1\); reject at 5%.)
Clinical Biostats