What Is a Chi-Square Test?
A chi-square (χ²) test is a hypothesis test that compares observed counts with the counts expected under a null hypothesis.
Large gaps between observed and expected counts give a large χ² statistic and a small p-value. Karl Pearson introduced the chi-square test in 1900, and it remains the standard test for categorical data such as survey answers, product choices and genotypes. Chi-square tests work on counts, not means; tests on means live in the Z Test Calculator.
Types of Chi-Square Tests
There are 3 types of chi-square tests.
Test of Independence
A chi-square test of independence checks whether 2 categorical variables are related in one sample. Example: is product preference related to gender among 140 shoppers?
Goodness-of-Fit Test
A chi-square goodness-of-fit test checks whether one categorical variable follows an expected distribution. Example: does a die land on each face one-sixth of the time?
Test of Homogeneity
A chi-square test of homogeneity checks whether several populations share the same distribution of one categorical variable. The calculation matches the test of independence; only the sampling design differs, with a separate sample from each population.
Chi-Square Formula and Expected Frequencies
O is an observed count and E is the expected count. For a test of independence, each expected count is:
For a goodness-of-fit test with equal proportions, every expected count equals N / k.
Degrees of Freedom for Chi-Square
The degrees of freedom are (r − 1)(c − 1) for a test of independence and k − 1 for a goodness-of-fit test. A 2 × 3 table has (2 − 1)(3 − 1) = 2 degrees of freedom, and a die with 6 faces has 5.
Assumptions (Expected Counts ≥ 5)
A chi-square test needs 3 assumptions:
- Counts, not percentages: the table holds raw frequencies.
- Independent observations: each subject appears in exactly one cell.
- Large enough expected counts: every expected count is at least 5 (some texts allow 20% of cells between 1 and 5).
How to Use the Chi Square Calculator
To use the chi square calculator, follow 2 steps:
- Paste the observed counts, one row per line, with columns separated by commas. A single row runs a goodness-of-fit test against equal proportions.
- Set α.
The heatmap colours each cell by its standardized residual (O − E) / √E: gold cells hold more than expected and teal cells fewer. The chart beside it shows the χ² distribution with the statistic and critical value. The assumption check flags expected counts below 5.
Interpreting Chi-Square Results and Cramér's V
A significant χ² means the variables are associated (or the distribution differs from the expected one), and Cramér's V measures how strong the association is.
Harald Cramér proposed V in 1946. V runs from 0 (no association) to 1 (perfect association); 0.1 is small, 0.3 medium and 0.5 large. The cells with the largest residuals drive a significant result.
Chi-Square Examples
There are 2 worked examples below.
Example 1: Gender × Product Preference (Independence)
140 shoppers: women chose products A, B, C as 20, 15, 25; men chose 30, 35, 15.
- Expected countswomen 21.43, 21.43, 17.14; men 28.57, 28.57, 22.86
- Chi-squareχ² = 9.844, df = (2 − 1)(3 − 1) = 2
- P-valuep = 0.0073
- Cramér's V√(9.844 / 140) = 0.265 (small to medium)
- DecisionReject H₀: preference is related to gender. Women chose product C more often than expected.
Example 2: Is a Die Fair? (Goodness of Fit)
A die rolled 60 times lands 8, 12, 9, 11, 6 and 14 times on faces 1 to 6.
- Expected counts60 / 6 = 10 per face
- Chi-squareχ² = (4 + 4 + 1 + 1 + 16 + 16) / 10 = 4.20, df = 5
- Critical valueχ²* = 11.07 at α = 0.05
- P-valuep = 0.521
- DecisionFail to reject H₀: the counts fit a fair die.
Chi-Square vs. Fisher's Exact Test
Use the chi-square test for large samples, and Fisher's exact test for 2 × 2 tables with expected counts below 5. Fisher's exact test computes the exact p-value from the hypergeometric distribution, so no approximation is involved. Analyse small 2 × 2 tables with the Fisher exact test calculator.
FAQs
When should I use Yates' continuity correction?
Use Yates' continuity correction only for 2 × 2 tables, and many statisticians skip it. Frank Yates proposed subtracting 0.5 from each |O − E| in 1934. The correction makes the test conservative; for small expected counts, Fisher's exact test is the better fix.
Can I enter percentages instead of counts?
No, a chi-square test needs raw counts, not percentages. The statistic depends on the sample size, so 30% of 100 and 30% of 1,000 give very different χ² values. Convert percentages back to counts before testing.
Is a 2×2 chi-square the same as a two-proportion z-test?
Yes, a 2 × 2 chi-square test without continuity correction equals a two-tailed two-proportion z-test, with χ² = z². z = 2.41 matches χ² = 5.82, and both give p = 0.016. Test two percentages directly with the two proportion z test.
How do I find which cells drive a significant result?
Look at the standardized residuals, (O − E) / √E, and focus on cells beyond ±2. The heatmap colours these residuals, so the brightest cells drive the result. Adjusted residuals divide by an extra factor for a stricter check. For paired yes/no data, use the McNemar test instead of a chi-square test.
How do I report a chi-square test in APA format?
Report a chi-square test as χ²(df, N = total) = value, p = value, with an effect size. Example: "Product preference was related to gender, χ²(2, N = 140) = 9.84, p = .007, V = .27." Look up the critical value for any df with the critical value calculator.