Contingency tables

Section of Chi-squared tests, part of Statistical inference

Contingency tables

Type Section
Taught in Chi-squared tests
Part Statistical inference

A contingency table classifies n individuals by two factors, with r rows and c columns. Write O_{ij} for the count in row i and column j, R_i for the row total and C_j for the column total. If the individuals are sampled independently, the rc cell counts are multinomial with cell probabilities p_{ij}.

Independence of the two factors says that each cell probability factors into a row probability times a column probability, H_0:p_{ij}=a_ib_j for all i,j. The maximum likelihood estimates are the row and column proportions, \widehat a_i=R_i/n and \widehat b_j=C_j/n, so the fitted count under independence is

E_{ij}=n\,\widehat a_i\widehat b_j=\frac{R_i\,C_j}{n}.

Definition 1 (Chi-squared test of independence) For an r\times c contingency table with fitted counts E_{ij}=R_iC_j/n, the statistic

T=\sum_{i=1}^r\sum_{j=1}^c\frac{(O_{ij}-E_{ij})^2}{E_{ij}}

is approximately \chi^2_{(r-1)(c-1)} when the row and column factors are independent. Large values are evidence against independence.

Article: Chi-squared test of independence →

The degrees of freedom are counted as before. There are rc cells, so rc-1 to start with. The row probabilities sum to one, so r-1 of them are free, and similarly c-1 column probabilities. That leaves rc-1-(r-1)-(c-1)=(r-1)(c-1).

Example 1 (Belief in ESP) A survey asks 114 artists and 344 non-artists how strongly they believe in extra-sensory perception.

Strong Moderate None Total
Artists 67 41 6 114
Non-artists 129 183 32 344
Total 196 224 38 458

Question. Is belief in ESP independent of being an artist?

Solution. The fitted counts are R_iC_j/458. For artists with strong belief, 114\times196/458=48.79; the six fitted counts are

Strong Moderate None
Artists 48.79 55.76 9.46
Non-artists 147.21 168.24 28.54

The six contributions (O_{ij}-E_{ij})^2/E_{ij} are 6.80, 3.91, 1.27, 2.25, 1.29 and 0.42, so T=15.94 on (2-1)(3-1)=2 degrees of freedom. The p-value is 0.0003. Independence is firmly rejected. The largest contributions come from artists: more of them hold strong belief, and fewer moderate belief, than independence predicts.

A 2\times2 table is a comparison of two proportions. With rows as groups and columns as success and failure, the Pearson statistic equals the square of the two-proportion z statistic with the pooled standard error, and \chi^2_1 is the law of a squared standard normal. The two tests are the same test, except that the chi-squared version is automatically two-sided.

The same table can be read as a response model, with one factor the response and the other the covariate. The saturated log-linear or multinomial-logit fit, and the likelihood-ratio comparison with the independence model, belong to the categorical and deviance chapters rather than to a second copy of this statistic.

Key idea

Expected counts come from the hypothesis. The Pearson statistic is the sum of squared differences divided by those expectations. The degrees of freedom are the number of free cells left after every estimated parameter has been counted.

Numerical examples are in Chi-squared examples.

Used in

See also

Pearson statistic · Pearson chi-squared approximation · Pearson test with estimated parameters · Chi-squared test of independence · Counts in categories · Chi-squared test with known cell probabilities · Chi-squared test with estimated parameters · Observed and expected counts

Glossary and index