Why Look Inside a Chi-Square Statistic?
A Pearson chi-square test for a two-way table produces one statistic summarizing how far the observed counts are from the counts expected under the null hypothesis. That overall number can indicate whether the table differs from what the null model predicts, but it does not show which cells account for the difference. Pearson residuals and cell contributions provide a direct decomposition: residuals show the direction and scaled size of a cell’s difference, while contributions show how much that cell adds to the overall statistic.
The calculations use the same observed and expected counts as the Pearson chi-square test. For inference, the observations must satisfy the design’s independence requirements, categories must be mutually exclusive, and the expected counts must be adequate for the chi-square approximation. In a homogeneity study, the groups are sampled independently and the category proportions are compared; in an independence study, the two categorical variables are recorded for the sampled individuals. The cell calculations themselves describe a table, but their inferential interpretation depends on an appropriate study design and the test conditions.
Calculating Residuals and Contributions
For a two-way table, the expected count in cell \(i,j\), under the null hypothesis of independence or homogeneity, is the row total multiplied by the column total and divided by the grand total. If \(R_i\) is row \(i\)'s total, \(C_j\) is column \(j\)'s total, and \(n\) is the grand total, then
Once the expected count is found, subtract it from the observed count. Dividing that difference by \(\sqrt{E_{ij}}\) gives the Pearson residual. Its sign preserves the direction: a positive value means the observed count exceeds its expected count, and a negative value means it falls below expectation. The cell contribution squares the difference, so it records the size of the discrepancy without its direction. Larger contributions indicate cells that add more to the overall statistic.
Both quantities are dimensionless. The residual expresses the observed-minus-expected difference relative to the square root of the expected count. The contribution is the squared version of that scaled difference. Neither quantity alone establishes that a particular cell is statistically significant; they describe the decomposition of the overall statistic. In particular, do not use procedures for adjusted or standardized residuals when interpreting these Pearson residuals.
Worked Example: A Two-Group, Two-Category Table
Suppose a hypothetical survey compares whether respondents in two groups support a proposal. The counts are:
| Group | Support | Do not support | Total |
|---|---|---|---|
| Group A | 28 | 12 | 40 |
| Group B | 22 | 18 | 40 |
| Total | 50 | 30 | 80 |
Under the null hypothesis of homogeneity, each group has the same support proportions. The expected counts are calculated from the margins. For Group A and “Support,” for example,
The other expected counts are \((40)(30)/80=15\), \((40)(50)/80=25\), and \((40)(30)/80=15\). Every expected count is at least 5, so the usual expected-count condition is satisfied. Assuming the hypothetical respondents were sampled independently within the design, the table is suitable for the standard chi-square approximation.
For Group A’s “Support” cell, the residual and contribution are
For Group A’s “Do not support” cell, the difference is \(12-15=-3\), so \(r_{12}=-3/\sqrt{15}\approx-0.775\), and \(Q_{12}=(-3)^2/15=0.600\). For Group B, the corresponding differences are \(22-25=-3\) and \(18-15=3\). Thus \(r_{21}=-3/5=-0.600\), \(Q_{21}=9/25=0.360\), \(r_{22}=3/\sqrt{15}\approx0.775\), and \(Q_{22}=9/15=0.600\).
The positive residual in Group A’s support cell says there were more supporters than expected there; the negative residual in Group B’s support cell says there were fewer than expected. The four contributions sum to \(0.360+0.600+0.360+0.600=1.920\). The values are contributions from each cell, not separate tests of those cells.
Why the Contributions Add to the Overall Statistic
The Pearson chi-square statistic for a two-way table is defined as the sum of the squared observed-minus-expected differences divided by their expected counts. The equality with the sum of squared Pearson residuals follows directly from the residual’s definition.
Summing this equality over all cells gives the result:
This identity is exact when the calculations use the unrounded counts and expected counts. It explains the distinct roles of the two quantities: retain the sign of \(r_{ij}\) to describe whether the observed count is above or below expectation, and use \(Q_{ij}=r_{ij}^2\) to express the cell’s nonnegative share of the total statistic.
Worked Example: Decomposing a Three-Category Table
Consider a hypothetical comparison of two groups across three response categories. The observed counts are:
| Group | Category 1 | Category 2 | Category 3 | Total |
|---|---|---|---|---|
| A | 25 | 10 | 15 | 50 |
| B | 15 | 20 | 15 | 50 |
| Total | 40 | 30 | 30 | 100 |
Under the null hypothesis of equal category proportions across the two groups, the expected counts in each row are \(50(40)/100=20\), \(50(30)/100=15\), and \(50(30)/100=15\). All six expected counts are at least 5. Suppose the groups were sampled independently and the observations within each group are independent; under these design and count conditions, the standard chi-square approximation is appropriate.
For Group A, the observed-minus-expected differences are \(25-20=5\), \(10-15=-5\), and \(15-15=0\). The residuals are therefore \(5/\sqrt{20}\approx1.118\), \(-5/\sqrt{15}\approx-1.291\), and \(0/\sqrt{15}=0\). Calculate the contributions directly from the exact differences:
For Group B, the differences are \(15-20=-5\), \(20-15=5\), and \(15-15=0\). Its residuals are approximately \(-1.118\), \(1.291\), and \(0\), and its contributions are \(25/20=1.250\), \(25/15\approx1.667\), and \(0\). Adding the unrounded contributions gives
The largest contributions come from the two cells in Category 2, where the observed counts differ from their expected counts by 5 and the expected count is 15. Category 3 contributes nothing because both observed counts equal their expected counts. The residual signs add useful direction: Group A is above expectation in Category 1 and below it in Category 2, while Group B has the reverse pattern.
Rounding and a Table With Unequal Expected Counts
Pearson residuals are often displayed to three decimal places, but a cell contribution should preferably be calculated from \((O_{ij}-E_{ij})^2/E_{ij}\), not by squaring a rounded residual. The displayed residual is an approximation, so its square can differ slightly from the contribution computed with full precision. This difference can also make the displayed contributions appear not to add exactly to the statistic.
Worked Example: Using Noninteger Expected Counts
In a hypothetical two-group comparison, suppose the observed counts are:
| Group | Outcome 1 | Outcome 2 | Total |
|---|---|---|---|
| A | 11 | 13 | 24 |
| B | 3 | 13 | 16 |
| Total | 14 | 26 | 40 |
Under the null hypothesis of equal outcome proportions, the expected counts are \(24(14)/40=8.4\), \(24(26)/40=15.6\), \(16(14)/40=5.6\), and \(16(26)/40=10.4\). The expected counts are all at least 5. Given independent observations and an appropriate group-sampling design, these counts satisfy the usual expected-count condition for Pearson chi-square inference.
In Group A’s Outcome 1 cell, the exact difference is \(11-8.4=2.6\). Its residual is \(2.6/\sqrt{8.4}\approx0.897\), and its contribution is
The other differences are \(13-15.6=-2.6\), \(3-5.6=-2.6\), and \(13-10.4=2.6\). The remaining residuals are approximately \(-0.658\), \(-1.099\), and \(0.806\). Calculate their contributions from the exact differences:
Using the unrounded quotients, their sum is \(0.8047619+0.4333333+1.2071429+0.6500000=3.0952381\), so \(\chi^2\approx3.095\). The display rounded to three decimals gives contributions totaling \(0.805+0.433+1.207+0.650=3.095\) here, but exact agreement is not guaranteed in every table. The calculation from the observed and expected counts defines the statistic; rounded residuals are for readable reporting.
What the Decomposition Does—and Does Not—Tell You
A cell contribution answers a limited but useful question: how much does this cell add to the Pearson chi-square statistic? Because the total is a sum of nonnegative contributions, cells with larger contributions account for more of the statistic. The Pearson residual supplies the direction of the difference that the contribution omits. Together they summarize each cell’s role in the overall discrepancy.
However, these values do not replace the overall test or change its conclusion. A large contribution is not automatically evidence that a single cell is significant, and inspecting many cells separately raises questions that require additional methods. Cell contributions also do not establish why counts differ. In particular, a table association does not by itself show that one category causes another. Interpret the table in light of its sampling or experimental design.
Common Mistake: Squaring a Rounded Residual
A frequent arithmetic error is to round a residual first and then square it as if it were exact. For example, if a cell has a difference of 8 and an expected count of 20, its exact contribution is
The residual is \(8/\sqrt{20}\approx1.789\). Squaring the rounded display gives \(1.789^2\approx3.201\), not 3.200. The small discrepancy is caused by rounding the residual before squaring, not by a failure of the identity. Calculate contributions from the exact difference and expected count, keep additional precision in intermediate calculations, and round only for the final presentation.
Check Your Understanding
Try these questions using the definitions and calculation rules above.
- A cell has \(O_{ij}=18\) and \(E_{ij}=13\). Calculate its Pearson residual and cell contribution, and state what the residual’s sign means.
- Why is a cell contribution never negative, even when the observed count is less than expected?
- In one sentence of algebra, show why summing all cell contributions gives the Pearson chi-square statistic.
- A residual is reported as \(-1.234\). Explain why squaring this displayed value may not reproduce the cell contribution exactly.
- What additional caution is needed before treating a large cell contribution as evidence that the particular cell is statistically significant?