The chi-square test is a statistical method that compares observed counts in categories against the counts you would expect if no real effect existed. It converts each mismatch into a standardized score, squares it, and sums those scores into one number. A sufficiently large total signals that the pattern in your data is unlikely to arise from chance alone.
That single number, written as χ², works for two distinct jobs. One checks whether two categorical variables are associated. The other checks whether a set of observed counts fits a theorized distribution. Both rest on the same arithmetic engine, and both depend on assumptions that, when violated, produce confident nonsense.
The Pearson Statistic, Step by Step
Start with a contingency table: rows for one categorical variable, columns for another. Each cell holds a count of cases falling into that combination. The test asks a counterfactual question. If the two variables were completely independent, how many cases would each cell hold?
The expected count for any cell equals the row total times the column total, divided by the grand total. That formula falls directly out of probability theory. If the row proportion and column proportion were independent, their product gives the joint proportion, and multiplying by the sample size converts it to a count.
For each cell, subtract the expected count from the observed count. Square that difference, so positive and negative deviations cannot cancel. Divide by the expected count, which weights the deviation by how large a fluctuation that cell could plausibly show. Sum these cell contributions and you have χ².
The squaring explains the test's sensitivity profile. A deviation of 10 in a cell expecting 100 contributes 1.0. The same deviation of 10 in a cell expecting 5 contributes 20. Small expected counts therefore dominate the statistic, and this is why sparse cells destabilize the test.
A tiny table makes the logic concrete. Suppose a clinic records 60 patients: 30 treated, 30 untreated. Recovery counts are 24 and 18 respectively. Expected recovering cases are 30 × 42 / 60 = 21 for each group. The contributions are (24 − 21)² / 21 = 0.43 and (18 − 21)² / 21 = 0.43, giving χ² ≈ 0.86. With one degree of freedom, that sits well below any conventional cutoff. The apparent difference is consistent with chance.
Degrees of Freedom and the Shape of the Null Distribution
Degrees of freedom for a contingency table equal (rows − 1) times (columns − 1). A 2×2 table has one degree of freedom. A 3×4 table has six. The number is not bookkeeping; it determines which chi-square distribution the statistic is compared against.
The chi-square distribution is right-skewed and bounded at zero. With one degree of freedom it falls steeply from a peak near zero. As degrees of freedom climb, the distribution shifts right and flattens toward a normal shape. This matters because the same statistic can be unremarkable in one setting and extreme in another.
The conventional cutoffs are 3.84 at one degree of freedom and 5.99 at two, both at the 0.05 level. At one degree of freedom, the 0.01 cutoff is 6.63. Reporting a p-value rather than a bare threshold comparison conveys more information, and modern practice favors it.
Professional caveat: the p-value answers only whether the observed pattern is compatible with independence. It says nothing about the size or practical importance of the association. A large sample can render a trivial departure statistically significant.
Effect Sizes That Survive Large Samples
Because significance scales with sample size, a chi-square result needs a companion measure of association strength. Three are common, and each answers a slightly different question.
Phi (φ) is defined for 2×2 tables and equals the square root of χ² divided by n. It ranges from 0 to 1 for 2×2 tables. Cramér's V generalizes phi to larger tables by dividing χ² by n times the smaller of (rows − 1) and (columns − 1), then taking the square root. Cohen's w compares observed proportions against expected ones and underpins power calculations.
Rough benchmarks exist and should be treated as rough. For Cramér's V at one degree of freedom, values near 0.10 are small, 0.30 medium, and 0.50 large. These labels shift with table dimensions, so quoting them without the df is misleading.
A study with 10,000 records might return χ² = 40 with one degree of freedom, a p-value below 0.001, and a phi of 0.06. The association is real but explains a trivial fraction of the variation. Reporting only the p-value would overstate the finding.
Where the Test Breaks: Sparse Cells and Dependency
The Pearson statistic follows its reference distribution only approximately, and the approximation degrades as expected counts shrink. The long-standing rule of thumb holds that no expected count should fall below 1, and no more than 20 percent of cells should fall below 5. Modern simulation work suggests the 5 rule is conservative, but the 1 floor remains a hard boundary.
When sparse cells appear, exact tests offer a remedy. Fisher's exact test computes the probability of the observed table directly, without relying on a large-sample approximation, and is the standard choice for small 2×2 tables. For larger sparse tables, permutation or Monte Carlo methods substitute for the asymptotic distribution.
A second failure mode is dependency. The Pearson test assumes each observation contributes to exactly one cell. When the same subject appears in multiple categories, the counts are not independent, and the statistic inflates. McNemar's test handles paired binary data, and the Stuart-Mantel-Haenszel approach handles matched designs.
Expected count below 1 in any cell: do not trust the asymptotic p-value. More than 20 percent of cells with expected counts under 5: switch to an exact or simulated method. Repeated measures or matched pairs: the standard test is invalid. Categories defined after inspecting the data: the p-value is no longer calibrated. Multiple chi-square tests on the same dataset without correction: inflated false-positive rate. Very large n with trivial effect size: significance without meaning.
Chi-Square Against the Alternatives
The chi-square test is one option among several for categorical data, and the choice depends on design and sample size.
| Method | Best suited to | Key constraint | Output |
|---|---|---|---|
| Pearson chi-square | Unpaired categorical association | Adequate expected counts | χ² and p-value |
| Fisher's exact test | Small 2×2 tables | Computationally heavier in large tables | Exact p-value |
| G-test (likelihood ratio) | Larger tables, model comparisons | Same expected-count rules | G statistic |
| McNemar's test | Paired binary outcomes | Exactly two categories per subject | χ² and p-value |
| Cochran-Mantel-Haenszel | Stratified 2×2 tables | Requires consistent strata | Adjusted odds ratio |
| Goodness-of-fit chi-square | Observed versus theorized distribution | Fixed expected proportions | χ² and p-value |
The G-test and Pearson test usually agree closely; they diverge mainly in small samples or extreme cells. The G-test has a useful additive property: contributions from independent studies sum to a combined statistic, which suits meta-analytic work.
A Short History of the Statistic
The test's lineage matters because it explains why the method is so widely embedded in software.
| Period | Development |
|---|---|
| 1900 | Karl Pearson publishes the χ² goodness-of-fit statistic |
| 1920s | Fisher derives exact tests and clarifies degrees of freedom |
| 1930s | Contingency-table applications spread through genetics and agriculture |
| 1950s | Cochran and Mantel develop stratified methods |
| 1970s | Computing makes routine chi-square analysis practical |
| 1980s | Simulation studies refine the expected-count rules |
| Present | Default in statistical software, paired with effect sizes |
The statistic predates modern computing by decades, which is why its assumptions were calibrated by hand-computed tables and why those rules remain conservative.
Reading a Chi-Square Output Correctly
Practical action begins with the table, not the p-value. Inspect the standardized residuals: the observed minus expected difference divided by the square root of expected. A residual beyond roughly 2 in absolute value flags a cell driving the result. Reporting which cells deviate is more informative than reporting the total.
Next, confirm the assumptions. Count expected values per cell. If sparse, switch methods. Check independence of observations. Then compute an effect size and report it alongside the p-value and degrees of freedom.
For planning, run a power calculation before collecting data. Detectable effect size depends on n, df, and the chosen alpha and power. Small associations in small tables demand large samples, and a pilot count of cell proportions gives the input needed.
State the null hypothesis in terms of independence or fit, not "no difference." Report χ², df, p-value, and an effect size together. Show the contingency table with expected counts. Identify cells with large standardized residuals. Specify which exact test was used if assumptions failed. Correct for multiple comparisons when running several tests.
Any single one of these steps reduces misreading. Together they make the output auditable.
What the Test Cannot Tell You
The chi-square test establishes compatibility with a null model; it does not establish causation, direction, or magnitude beyond the reported effect size. Association between two categorical variables can arise from a third variable that influences both, and the test has no mechanism for detecting confounding.
The test also ignores ordering. Categories are treated as unordered labels, so a monotonic trend across ordinal groups is invisible to the standard statistic. Linear-by-linear association tests or ordinal regression capture that structure.
Sample size cuts both ways. Small samples lack power to detect real associations, and the asymptotic approximation weakens. Large samples detect trivial associations and invite overinterpretation. Neither problem is solved by the test itself; both require judgment outside the arithmetic.
Finally, the test presumes categories are exhaustive and mutually exclusive. Overlapping or ill-defined categories violate the counting logic at its base, and no post-hoc correction rescues a badly designed variable. When the categories are wrong, the statistic is precise about the wrong thing.