A better test statistic

The raw sum of squares on the previous page is a poor way to assess whether a contingency table has been sampled from a population with independence. A better statistic is χ2 (pronounced chi-squared), defined by

This more fairly assesses differences between nxy and exy when the exy vary in magnitude. Its distribution still depends on the number of rows and columns in the contingency table, but is no longer affected by either the number of individuals (the total count for the table) or the margins of the table.

Only the number of rows and number of columns in the table have much influence on the distribution of χ2.


Simulation

The diagram below again samples from two independent categorical variables.

Click Accumulate then take several samples to build up the distribution of the χ2 statistic.

Now increase the sample size and repeat. Observe that χ2 is approximately the same magnitude (usually between 0.5 and 15.0) regardless of the sample size.

Finally, use the pop-up menu labelled Model to change the model to one where the marginal probabilities for the two categorical variables are unequal (but there is still independence). Observe that the distribution of χ2 remains approximately the same.

Distribution of chi-squared statistic

When there is independence, the χ2 statistic has approximately a standard distribution called a chi-squared distribution whose shape only depends on the number of rows and columns in the table but not the sample size or the underlying joint probabilities.

If a contingency table with r rows and c columns is sampled from a population with independence, χ2 has a chi-squared distribution with (r - 1)(c - 1) degrees of freedom.

The chi-squared distribution is skew, and

The mean of the chi-squared distribution equals its degrees of freedom.


Shape of the chi-squared distribution

The diagram below shows the probability density function for the chi-squared distribution.

Use the pop-up menus to change the number of rows and columns in the table. Observe that: