How to use the chi-square test calculator
- Choose the test of independence for a table of counts (two categorical variables), or goodness of fit for one list of counts.
- Copy your table from Excel or Google Sheets, headings included, and paste it in. For goodness of fit, paste the categories and their counts, and pick equal or your own expected values.
- Keep the significance level at 0.05 unless your course says otherwise, then click Run chi-square test.
- Read χ², the degrees of freedom and the p-value, then the plain-English summary of which cells differ most from what was expected.
- Check the warning about small expected counts, and download the chart if you need it.
Chi-square test formula
Both tests compare the observed counts with the counts you would expect if the null hypothesis were true:
χ2 = Σ (O − E)2E
For a test of independence, each cell's expected count comes from its row and column totals:
E = row total × column totalgrand total , df = (r − 1)(c − 1)
For goodness of fit, the expected count is the total times the expected proportion, and df = k − 1.
- O
- The observed count in a cell or category
- E
- The expected count if the null hypothesis is true (no association, or the expected distribution)
- χ2
- The test statistic: the bigger it is, the further the data are from what was expected
- df
- Degrees of freedom: (rows − 1) × (columns − 1) for a table, or categories − 1 for goodness of fit
- r, c, k
- The number of rows, columns, and categories
Worked example
You roll a die 60 times and get 8 ones, 12 twos, 9 threes, 11 fours, 6 fives and 14 sixes. Is the die fair?
-
If the die is fair, each face is expected 60 ÷ 6 times
E = 10
-
Add up (O − E)² ÷ E for the six faces
χ2 = (8 − 10)² + (12 − 10)² + (9 − 10)² + (11 − 10)² + (6 − 10)² + (14 − 10)²10 = 4210 = 4.2
-
Degrees of freedom and p-value
df = 6 − 1 = 5, p = P(χ2 ≥ 4.2) = 0.521
What it means: p = 0.521 is far above 0.05, so there's no evidence the die is unfair. Rolls of 6 and 14 look uneven, but differences that size happen by chance in 60 rolls more than half the time. You can check χ² against the cutoff in the chi-square table: with 5 df at α = 0.05 it's 11.070, and 4.2 is well below it.
How to interpret the result
- p ≤ α (significant): for independence, the two variables are related; the pattern in the table is unlikely to be chance. For goodness of fit, the counts don't match the expected distribution.
- p > α (not significant): the data are consistent with no association, or with the expected distribution. That isn't proof they're equal, only a lack of evidence against it.
- Where the difference is: look at the cells with the largest contributions, (O − E)² ÷ E. The calculator names them and says whether each count is higher or lower than expected.
- How strong: for a table, Cramér's V gives the size of the association, which a p-value alone doesn't.
- Check the expected counts: if any are below 5, the p-value may not be accurate.
Already have a χ² value and just need its p-value? Use the p-value calculator. To chart the counts, paste them into the bar graph maker.