Chi Square Calculator
Type a table of counts and the chi square calculator tests whether rows and columns are independent, or test observed counts against expected ones. Every cell's expected count and contribution is shown.
Chi-square statistic
- Chi-square statistic Sum over all 6 cells of (observed - expected)^2 / expected, where expected = row total x column total / grand total. Each cell's share is in the table below.
- 8.52587
- Degrees of freedom (rows - 1) x (columns - 1) = 1 x 2.
- 2
- p-value The chance of a chi-square at least this large if the null hypothesis were true. Always the upper tail.
- 0.0141
- Critical value at 0.05 Chi-square above 5.991 on 2 degrees of freedom has a p-value below 0.05.
- 5.991
- Result 8.52587 is above 5.991: counts this far from the expected ones would be unusual if the null hypothesis held. That shows a difference exists, not how big or important it is.
- reject at 0.05
- Cramer's V sqrt(chi-square / (N x (min(rows, columns) - 1))): the strength of the association from 0 to 1, which chi-square alone does not give, since it grows with the sample size.
- 0.2666
- Totals Row totals 65, 55; column totals 40, 40, 40.
- N = 120
| Cell | Observed | Expected | (O - E)^2 / E |
|---|---|---|---|
| Row 1, column 1 | 28 | 21.6667 | 1.85128 |
| Row 1, column 2 | 22 | 21.6667 | 0.00512821 |
| Row 1, column 3 | 15 | 21.6667 | 2.05128 |
| Row 2, column 1 | 12 | 18.3333 | 2.18788 |
| Row 2, column 2 | 18 | 18.3333 | 0.00606061 |
| Row 2, column 3 | 25 | 18.3333 | 2.42424 |
| Total | 120 | 120 | 8.52587 |
- The null hypothesis is that the row variable and the column variable are independent. Rejecting it says they are associated; it does not say which causes which.
How the Chi Square Calculator works
A chi-square test compares counts you observed with the counts you would expect if a hypothesis were true. The chi-square formula is the same for both kinds of test: χ² = Σ (O - E)² / E, summed over every cell, where O is the observed count and E the expected one. Squaring makes every gap positive, and dividing by E scales each gap to what is typical for a count of that size.
Test of independence. Enter a contingency table: one row per group, one column per outcome. The default table is pass and fail counts for three teaching methods (example data): 28, 22 and 15 passed; 12, 18 and 25 failed. If outcome were independent of method, each cell's expected count would be its row total times its column total over the grand total. Here every column total is 40 and the grand total is 120, so the pass row expects 65 x 40 / 120 = 21.67 in each column and the fail row expects 18.33. The cell for method C passing contributes (15 - 21.67)² / 21.67 = 2.05. All six contributions sum to 8.526 on (2 - 1) x (3 - 1) = 2 degrees of freedom, a p-value of 0.0141. The critical value at 0.05 is 5.991, so independence is rejected: pass rates differ by method. Cramer's V of 0.267 puts a size on the association, which chi-square does not, because it grows with the sample.
Goodness of fit. Enter observed counts for each category and what you expected, as counts, proportions or a ratio. Mendel's pea counts are the classic: 315, 108, 101 and 32 seeds against a 9:3:3:1 ratio. Out of 556 seeds that ratio expects 312.75, 104.25, 104.25 and 34.75, and χ² comes to 0.470 on 3 degrees of freedom, p = 0.9254. The counts fit the ratio closely. The degrees of freedom are the number of categories minus one, less one more for every parameter estimated from the same data.
When the test breaks down. The p-value comes from the chi-square distribution, which only approximates the true distribution of the statistic, and the approximation fails when expected counts are small. The usual rule wants every expected count to be at least 5, or at the least no more than 20% of them below 5 and none below 1. The result flags any cell under 5. The fixes are to merge sparse categories, collect more data, or use an exact test. The test also needs counts of independent observations: percentages, averages, or the same person counted twice all break it.
Chi Square Calculator FAQ
What is the chi-square formula?
χ² = Σ (O - E)² / E: for each cell, square the gap between the observed and expected count, divide by the expected count, and add them up. For a test of independence, E = row total x column total / grand total.
How do you find degrees of freedom for a chi-square test?
For a test of independence, (rows - 1) x (columns - 1): a 2 x 3 table has 2. For goodness of fit, the number of categories minus 1, minus one more for each parameter estimated from the data.
What does the p-value mean in a chi-square test?
The probability of a chi-square statistic at least as large as yours if the null hypothesis were true. Below your significance level, usually 0.05, the counts differ from the expected ones by more than chance would usually produce.
What if an expected count is less than 5?
The chi-square approximation becomes unreliable and the p-value can be off. Merge small categories, gather more data, or use an exact test such as Fisher's exact test for a 2 x 2 table.