All guides

Chi-Square Tests Explained: When Counts Meet Expectations

A test for counts, not measurements

Chi-square works where t-tests cannot: on counts in categories. A die rolled 60 times should show each face about 10 times; a genetics cross should produce offspring in a 3 to 1 ratio; a survey's answers should distribute across parties in known proportions. The test statistic adds up, for every category, the squared difference between observed and expected counts divided by the expected count. Big mismatches inflate the sum; a chi-square near its degrees of freedom means the fit is ordinary. The p-value then comes from the chi-square distribution, whose shape depends only on the degrees of freedom, typically the number of categories minus one for goodness of fit.

A worked miniature

Roll a die 60 times and see faces come up 8, 12, 9, 11, 10, 10 against an expectation of 10 each. The contributions are 0.4, 0.4, 0.1, 0.1, 0 and 0, summing to a chi-square of 1.0 on 5 degrees of freedom, a p-value around 0.96: utterly consistent with fairness. Now imagine one face appearing 25 times; its contribution alone is 22.5, the total leaps, and the p-value collapses. Notice the test's honesty: it never says which face is suspect, only that the overall pattern is unlikely under the expectation. Follow-up inspection finds the culprit; the statistic merely raises the alarm, which is the correct division of labour.

The rules in the small print

Chi-square has conditions that matter. Expected counts should mostly be at least 5, because the reference distribution is an approximation that frays with tiny expectations; combining sparse categories is the usual repair. The data must be counts, never percentages or measurements, and observations must be independent. For two-way tables, the same statistic tests independence between two categorical variables, with degrees of freedom equal to (rows minus 1) times (columns minus 1). The test also shares the family limitation of all significance tests: with enormous samples, trivial departures from expectation become significant, so read the actual differences beside the p-value. A percentage-point table next to the statistic keeps the conclusion proportionate. The chi-square family has quieter members worth knowing. The goodness-of-fit test compares one categorical variable against a claimed distribution, the tool that catches loaded dice and rigged lotteries. McNemar's test handles paired categories, such as the same voters before and after a campaign. All share the same engine: observed counts against expected counts, squared gaps scaled by expectation, summed and judged against the chi-square distribution with the appropriate degrees of freedom. Learn the engine once and the whole family becomes variations in what counts as expected, which is why this distribution repays more study than its plain appearance suggests.

Try it with your own numbers

The free calculators that go with this guide:

Run a chi-square test