The chi-square (χ²) test compares counts you observed with the counts you would expect if a hypothesis were true. Each category contributes (observed − expected)² ÷ expected, and the sum grows as the data drift away from the hypothesis. Under the null hypothesis the sum follows a chi-square distribution, which gives the p-value.
There are two common versions. The goodness-of-fit test checks whether one categorical variable follows a claimed distribution: is a die fair, are customers spread evenly over the weekdays, do genotype counts match a 9:3:3:1 ratio? The test of independence takes a contingency table of two categorical variables, such as treatment group and outcome, and asks whether they are related. Expected counts come from the row and column totals.
The chi-square approximation needs reasonably large expected counts, and a common rule is at least 5 in every cell. With smaller counts in a 2×2 table, use Fisher’s exact test; in larger tables, merge sparse categories. Effect size is reported as phi for 2×2 tables and Cramér’s V for larger ones.
How to use the Chi-Square Test Calculator
- Test
- Observed counts
- Expected distribution
- Expected counts or proportions
- Parameters estimated from the data: Reduces the degrees of freedom, e.g. 1 when fitting a Poisson mean
- Group 1, outcome yes (a)
- Group 1, outcome no (b)
- Group 2, outcome yes (c)
- Group 2, outcome no (d)
- Yates continuity correction
- Contingency table: one row per line
- Significance level (α)
Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.
How it works
Choose the test, then enter the counts. For goodness of fit, leave the expected values empty for equal proportions, or give expected counts or proportions (they are rescaled to the observed total). The calculator adds up (O − E)² ÷ E, finds the degrees of freedom and reads the right-tail p-value from the chi-square distribution.
Worked example
Goodness of fit. A café counts 22, 17, 15 and 26 customers on four mornings (80 in total). If visits were spread evenly, each morning would expect 20. χ² = (2² + 3² + 5² + 6²) ÷ 20 = 74 ÷ 20 = 3.70 with 3 degrees of freedom. The critical value is 7.815 and p = 0.296, so there is no evidence of uneven visits.
2×2 independence. Of 100 patients on treatment 1, 30 recover; of 100 on treatment 2, 45 recover. χ² = 200 × (30 × 55 − 70 × 45)² ÷ (100 × 100 × 75 × 125) = 4.80 with 1 df, p = 0.028. Recovery depends on the treatment at α = 0.05; φ = −0.155 indicates a small association.
Critical values of chi-square
| df | α = 0.10 | α = 0.05 | α = 0.01 |
|---|---|---|---|
| 1 | 2.706 | 3.841 | 6.635 |
| 2 | 4.605 | 5.991 | 9.210 |
| 3 | 6.251 | 7.815 | 11.345 |
| 4 | 7.779 | 9.488 | 13.277 |
| 5 | 9.236 | 11.070 | 15.086 |
| 10 | 15.987 | 18.307 | 23.209 |
Formula
χ² = Σ (O − E)² ÷ E · goodness of fit: df = k − 1 − (estimated parameters) · independence: E = row total × column total ÷ n, df = (r − 1)(c − 1) · 2×2 shortcut: χ² = n(ad − bc)² ÷ ((a + b)(c + d)(a + c)(b + d))
Worked example
Inputs: Test: Goodness of fit (one variable); Observed counts: 22, 17, 15, 26; Expected distribution: Equal for every category; Parameters estimated from the data: 0; Significance level (α): 0.05.
Results: p-value = 0.3; Chi-square statistic (χ²) = 3.7; Degrees of freedom = 3; Decision = Do not reject H₀ at α = 0.05 – p = 0.2957 > 0.05, so χ² = 3.7 is not extreme enough.; Critical χ² (right-tailed) = 7.8147; Observed and expected counts = Category Observed Expected O − E (O − E)²/E
───────────────────────────────────────────────────
1 22 20 2 0.2
2 17 20 −3 0.45
3 15 20 −5 1.25
4 26 20 6 1.8
Total 80 80 0 3.7.
Key terms
- Observed count (O)
- The number of cases actually recorded in a category or cell.
- Expected count (E)
- The count predicted by the null hypothesis, from the claimed proportions or from row total × column total ÷ n.
- Contingency table
- A table of counts that cross-classifies cases by two categorical variables.
- Cramér's V
- Effect size for tables of any size, √(χ² ÷ (n × (min(r, c) − 1))), between 0 and 1.
Frequently asked questions
When should I use Fisher's exact test instead?
When any expected count in a 2×2 table is below 5, or the total sample is small. Fisher's test computes the exact p-value without the chi-square approximation.
What is the critical chi-square value for 1 degree of freedom?
3.841 at α = 0.05, 6.635 at α = 0.01 and 10.828 at α = 0.001.
How do I calculate degrees of freedom?
Goodness of fit: categories − 1 (minus any parameters estimated from the data). Independence: (rows − 1) × (columns − 1). A 2×3 table has 2 df.
Does a chi-square test show the direction of an effect?
No. Compare the observed and expected counts (shown in the table) or the sign of phi to see which cells drive the result.
Should I use the Yates correction?
It makes the 2×2 test more conservative. Many statisticians now prefer the uncorrected test for large samples and Fisher's exact test for small ones; the option is here for comparison with textbooks that use it.
Can I use percentages instead of counts?
No. The test needs raw counts. Percentages hide the sample size, and χ² grows with n.
Is a fair-die test a goodness-of-fit test?
Yes. Enter the six face counts and leave the expected distribution as equal; df = 5 and the critical value at α = 0.05 is 11.07.