When to use a chi-square test
Use the test of independence when you have two categorical variables and want to know if they are related — laid out as a contingency table (e.g. smoker/non-smoker × disease/no-disease). Use the goodness-of-fit test when you have one categorical variable and a theoretical distribution to compare it against (e.g. are die rolls uniform?).
Chi-square is for frequencies of categories. If your outcome is numeric, you want a t-test or ANOVA instead.
Assumptions, and how to check them
- Independent observations — each subject falls in exactly one cell; no repeated measures.
- Expected count ≥ 5 in roughly 80% of cells. The test uses a continuous approximation that breaks down with sparse cells.
- Raw counts — never enter percentages or proportions; the test needs the actual frequencies.
Worked example
A 2×2 table of treatment (A/B) by outcome (recovered/not): [[30, 10], [20, 40]]. The recovery rate is 75% under A versus 33% under B, and chi-square returns a large statistic with a small p-value — evidence that treatment and outcome are associated. Enter the table above to get the statistic, df = (rows−1)(cols−1), and p-value.
Common mistakes
- Entering percentages instead of counts — the single most common error.
- Small expected counts — with cells below ~5, switch to Fisher's exact test.
- Treating a significant result as a strong effect — report an effect size such as Cramér's V; chi-square grows with sample size.
- Using it on numeric data by binning unnecessarily, which throws away information.
If assumptions fail
For small samples or sparse 2×2 tables, use Fisher's exact test. For larger sparse tables, the G-test (likelihood-ratio) is an alternative. Details and validation are on the methodology page.