The chi-square (χ²) test of independence checks whether two categorical variables are related. Is product preference related to age group? Is vaccination status related to region? Do pass rates differ between schools? If both of your variables are categories rather than measurements, this is usually the test you need.
In this guide
When to use the chi-square test of independence
- You have two categorical variables (nominal or ordinal), for example gender × voting intention, or treatment group × recovered (yes/no).
- Each participant appears in exactly one cell of the table.
- Your data are counts (frequencies), not percentages or means.
If you have a single categorical variable and want to compare its distribution with expected proportions (for example, "are the four flavours chosen equally often?"), use the chi-square goodness-of-fit test instead. For the same people measured twice on a yes/no outcome, use the McNemar test.
Hypotheses
- H₀: the two variables are independent (no association).
- H₁: the two variables are associated.
How the test works
The test compares the observed counts in each cell with the counts you would expect if the variables were unrelated. For each cell:
expected count = (row total × column total) ÷ grand total
The χ² statistic adds up the squared differences, scaled by the expected counts:
χ² = Σ (observed − expected)² ÷ expected
The degrees of freedom are (rows − 1) × (columns − 1). The bigger χ² is relative to its degrees of freedom, the stronger the evidence of an association.
Assumptions
- Independent observations. Each person is counted once.
- Adequate expected counts. No expected count below 1, and no more than 20% of cells with expected counts below 5. For 2×2 tables with small expected counts, use Fisher's exact test.
- Counts, not percentages. Convert percentages back to counts before running the test.
Worked example
A brand surveys 300 customers and asks whether they would recommend it. It wants to know if recommendation differs by age group.
Observed counts
| Would recommend? | 18–29 | 30–49 | 50+ | Total |
|---|---|---|---|---|
| Yes | 62 | 48 | 30 | 140 |
| No | 38 | 52 | 70 | 160 |
| Total | 100 | 100 | 100 | 300 |
Expected counts (if age and recommendation were unrelated): 46.7 "yes" and 53.3 "no" in every age group. All expected counts are well above 5, so the assumption is met.
Result: χ²(2, N = 300) = 20.68, p < .001.
Recommendation rates clearly differ by age group: 62% of 18–29-year-olds would recommend the brand, compared with 48% of 30–49-year-olds and 30% of those aged 50 and over.
Which cells drive the result? Standardized residuals
A significant χ² tells you there is an association somewhere. Adjusted standardized residuals show where. Values beyond ±1.96 indicate cells that differ significantly from expectation at α = .05 (beyond ±2.58 for α = .01).
| Would recommend? | 18–29 | 30–49 | 50+ |
|---|---|---|---|
| Yes | +3.76 | +0.33 | −4.09 |
| No | −3.76 | −0.33 | +4.09 |
Younger customers recommend more often than expected, and customers aged 50+ less often. The middle group is close to expectation.
Effect size: Cramér's V
χ² grows with sample size, so it is not an effect size. Use Cramér's V:
V = √( χ² ÷ (N × (k − 1)) ), where k is the smaller of the number of rows and columns.
Here, V = √(20.68 ÷ (300 × 1)) = .26.
Rough benchmarks depend on the degrees of freedom. For df* = k − 1 = 1, Cohen's guidelines are .10 (small), .30 (medium) and .50 (large); for df* = 2 they are about .07, .21 and .35. So V = .26 is a small-to-medium association. For 2×2 tables, Cramér's V equals the phi coefficient (φ).
How to report it in APA 7
A chi-square test of independence showed a significant association between age group and willingness to recommend the brand, χ²(2, N = 300) = 20.68, p < .001, Cramér's V = .26. Customers aged 18–29 were more likely to recommend the brand (62%) than those aged 30–49 (48%) or 50 and over (30%).
Include the contingency table (counts and percentages) in your results section or an appendix. Readers need it to understand the pattern.
Yates' correction and the likelihood ratio test
- Yates' continuity correction is sometimes applied to 2×2 tables. It makes the test conservative, and many statisticians no longer recommend it; Fisher's exact test is a better option when counts are small.
- The likelihood ratio chi-square (G²) is an alternative statistic that usually gives very similar results with adequate samples.
The free chi-square calculator reports Pearson's χ², the Yates-corrected value for 2×2 tables, the likelihood ratio test, expected counts, residuals and Cramér's V, so you can report whichever your field expects.
Common mistakes
- Running the test on percentages. It needs raw counts.
- Ignoring small expected counts. Merge sparse categories if that makes sense, or use Fisher's exact test.
- Counting the same person more than once, for example with multiple-response survey questions.
- Stopping at "significant". Report Cramér's V and describe which cells drive the effect.
Frequently asked questions
What is the minimum sample size for a chi-square test?
There is no fixed minimum sample size. The rule is about expected counts: no expected count below 1, and no more than 20% of cells below 5. If that fails in a 2×2 table, use Fisher's exact test.
What is the difference between chi-square test of independence and goodness of fit?
The test of independence checks whether two categorical variables are related. The goodness-of-fit test compares one categorical variable with a set of expected proportions.
How do I interpret Cramér's V?
Cramér's V runs from 0 (no association) to 1 (perfect association). Interpretation depends on table size; for a 2×2 table, about .10 is small, .30 medium and .50 large.
Can I use chi-square for ordinal variables?
Yes, but it ignores the ordering. If both variables are ordinal, a test of trend or a rank correlation such as Spearman's rho can be more powerful.