Hypothesis tests
Chi-Square Test Calculator
Test whether two categorical variables are associated, or whether observed counts match the distribution you expected.
Also called chi square calculator, chi-squared test calculator, Pearson's chi-square calculator.
Have a spreadsheet? Drop a CSV here
Or . CSV, TSV or plain text. You pick which column is which after it loads — the names in your file do not have to match ours. The file is read in your browser and never uploaded.
How to read this result
χ² adds up how far each cell sits from what independence predicts, scaled by how large that cell was expected to be. It is always positive and always upper-tailed: any departure in any direction makes it larger, which is why there is no two-tailed version to choose.
A significant result says the variables are associated. It does not say how, or how strongly. That is what the standardised residuals table is for: cells beyond about ±2 are the ones driving the result, and their sign tells you whether that combination occurred more or less often than independence predicts.
Cramér's V is the effect size. χ² grows with the sample size — double every count and χ² doubles while the pattern is unchanged. V divides that out, giving a number between 0 and 1 that is comparable across studies. Around 0.1 is a weak association, 0.3 moderate, 0.5 strong.
Watch the expected counts, not the observed ones. The approximation behind the p-value needs expected counts of about 5 or more. Small observed counts are fine; small expected counts are not, and for a 2×2 table the fix is Fisher's exact test, which needs no approximation at all.
The formula
- the observed count in a cell
- the count expected if the two variables were independent
- the total number of observations
Degrees of freedom: (rows − 1)(columns − 1) for a test of independence, categories − 1 for goodness of fit.
Effect size
Cramér's V. For a 2×2 table it is the phi coefficient, and it equals the absolute correlation between the two binary variables.
Worked example
Does a training course change pass rates?
One hundred candidates, half of whom took a preparation course. Of the 50 who took it, 35 passed; of the 50 who did not, 20 passed. That looks like a large difference — but with 50 people per group, how large a difference does chance produce?
| passed | failed | |
|---|---|---|
| course | 35 | 15 |
| no course | 20 | 30 |
- Work out the margins.rows 50 and 50; columns 55 passed and 45 failed; n = 100
- Expected count for each cell: row total × column total ÷ n.course/passed = 50 × 55 / 100 = 27.5; course/failed = 22.5; and the same for the second row
- For each cell, square the gap and divide by the expected count.(35 − 27.5)² / 27.5 = 56.25 / 27.5 = 2.045 (15 − 22.5)² / 22.5 = 2.500
- Add all four terms. By symmetry the second row contributes the same as the first.χ² = 2 × (2.045 + 2.500) = 9.091
- Degrees of freedom: (2 − 1)(2 − 1) = 1. Look χ² up in the upper tail.p = 0.00257
- Scale it into an effect size.V = √(9.091 / (100 × 1)) = 0.302
The pass rate is 70% with the course and 40% without. The test says that gap is unlikely to be chance; it says nothing about whether the course caused it, since the people who chose to take it may differ in other ways.
Checked against R's chisq.test(matrix, correct = FALSE).
The calculator above is loaded with these numbers by the Load the worked example button.
Assumptions, and when to use something else
- Counts, not percentages or means. Feeding percentages into a chi-square test produces a number that depends on whether you typed 70 or 0.70, which is a clear sign it is meaningless.
- Each observation appears in exactly one cell. One hundred people in a 2×2 table means one hundred counts in total. Repeated measurements of the same people belong in McNemar's test.
- Expected counts of about 5 or more. The classic guidance is that no expected count should be below 5; the modern, more relaxed version allows up to 20% of cells below 5 provided none is below 1.
- Independent observations. Clustered sampling — several members of the same household, several measurements from the same machine — breaks the test in a way that makes the p-value too small.
- A 2×2 table with small countsFisher's exact testComputes the exact probability by enumerating every table with the same margins. No minimum expected count, no approximation.
- The same subjects measured twiceMcNemar's testPaired yes/no data — before and after, two raters on the same items. Chi-square would treat the pairs as independent and get it wrong.
- Comparing two proportions and you want a direction and an intervalz-test for proportionsGives the same p-value for a 2×2 table plus the difference in proportions and a confidence interval for it.
- You want the strength of the associationOdds ratioFor a 2×2 table, the odds ratio with its confidence interval says how much more likely the outcome is in one group.
Questions people ask
What is the difference between a chi-square test of independence and goodness of fit?
Independence tests one sample cross-classified by two variables — are they related? Goodness of fit tests one variable against a distribution you specify — do these counts match what I expected? The arithmetic is nearly identical; the degrees of freedom differ, and so does the question.
What if my expected counts are below 5?
For a 2×2 table, use Fisher's exact test, which is exact and has no such requirement. For a larger table, combine sparse categories into meaningful groups — but combine them for a reason, not to make the number work.
Should I use Yates's continuity correction?
Usually not. It was designed to make the continuous chi-square distribution better approximate discrete counts in a 2×2 table, and it overcorrects: the resulting test is noticeably conservative. If the counts are small enough for the correction to matter, they are small enough to warrant Fisher's exact test instead.
Can chi-square tell me the direction of the association?
Not on its own — χ² is always positive and symmetric in that sense. The standardised residuals table shows which cells are over- and under-represented, and for a 2×2 table the odds ratio gives the direction and the magnitude together.
How many rows and columns can I use?
Any number. Paste a 2×2 or a 7×5; the calculator works out the degrees of freedom and the expected counts from the shape of what you paste.