Chi-Square Calculator
Chi square test for 2x2 tables: statistic, p value, and verdict.
What it does
Two way tables ask whether rows and columns move together or vary by chance. A drug trial with recoveries split by treatment is the classic case: the raw split looks promising, but small samples produce lopsided tables from noise alone. Chi square scores the surprise.
The tool above runs the Pearson 2x2 test the moment you type. Enter four whole counts. It returns the statistic, 1 degree of freedom, the p value, and a significant or not verdict at 0.05. Defaults of 30, 20, 10, 40 open solved at 16.67 with p below 0.0001.
Expected counts carry the logic. Under independence each cell should hold its row share times its column share: 50 row patients times 40 recoveries over 100 total puts 20 in the corner. Squared gaps scaled by expectation then sum to the statistic, so big relative misses count more than big absolute ones.
The 3.841 cutoff is the 95th percentile of the chi square distribution with one degree of freedom. Clearing it means tables this skewed arise under 5 percent of the time by luck, which researchers read as association rather than proof of cause.
Use the table for critical values and worked tables, then run the data. When any expected count dips under 5, stop: gather more observations or switch to the Fisher exact test instead.
How to use
- Enter the four cell counts as whole numbers.
- Check that totals and expected counts look sane.
- Read chi square first, then p value.
- Compare against 3.841 at the 0.05 level.
- Report significant or not with the p value.
- Gather more data when expected counts fall short.
Formula
- O
- Observed counts a, b on row one; c, d on row two.
- E
- Row times column over grand total N.
- N
- Sum of all four cells.
- df
- (2 - 1) x (2 - 1) = 1.
Pearson chi square for 2x2 contingency tables without Yates correction. Expected counts come from the margins under independence. The p value uses the chi square distribution with 1 degree of freedom; the page refuses tables with any expected count below 5.
Worked example
Example: 2x2 trial table, 100 patients
Treatment trial: 30/20 recover or not on drug, 10/40 on placebo. Test independence.
- Totals: rows 50 and 50, columns 40 and 60, N = 100.
- Expected: row x col / N gives 20, 30, 20, 30.
- Cell terms: (30-20)^2/20 = 5, (20-30)^2/30 = 3.33, twice more.
- Sum: 5 + 3.33 + 5 + 3.33 = 16.67 on 1 degree of freedom.
- p value below 0.0001, far under 0.05.
- Verdict: significant; treatment and outcome associate.
Reference table
| Case | Chi square | p | Verdict |
|---|---|---|---|
| df 1 at 0.05 (cutoff) | 3.841 | 0.05 | Beat it to claim significance |
| Worked trial 30/20/10/40 | 16.67 | <0.0001 | Significant |
| Even table 10s | 0 | 1 | Not significant |
| Table 20/30/10/40 | 4.76 | 0.0291 | Significant |
Limits
- 2x2 tables only; bigger tables differ.
- No Yates correction applied.
- Expected counts below 5 invalidate it.
- Association is not causation.
Common mistakes
- Testing percentages instead of counts.
- Ignoring the expected 5 rule.
- Reading p as the chance the null is true.
- Running tiny tables and trusting the verdict.
- Forgetting Yates exists when reporting.
Try it yourself
Quick checks. Answers sit tucked under each question.
Perfectly even 10, 10, 10, 10?
Every expected count is 10. Gaps are zero, so chi square 0, p 1, not significant.
Table 20, 30, 10, 40?
Expected 15, 35, 15, 35. Terms 1.67 + 0.71 + 1.67 + 0.71 = 4.76, p 0.0291, significant at 0.05.
Table 1, 1, 1, 1?
Each expected count is 1, under 5, so the page refuses with a collect more data message.
Questions
What does this page test?
Whole counts in a contingency table, testing whether rows and columns associate. Goodness of fit variants compare one row against theory.
Why 1 degree of freedom?
(Rows - 1) x (columns - 1). A 2x2 table has 1 degree of freedom; bigger tables gain more.
What is the cutoff?
3.841 for df 1 at 0.05. Beat it and the result is significant; the page applies exactly this rule.
What does the p value mean?
The tail chance of a chi square this large under independence. Small p means the table looks rigged against chance.
Expected counts below 5?
Collect more data or use Fisher exact. Chi square trusts the approximation only when every expected count reaches 5.
Yates correction?
Yates subtracts 0.5 per cell for 2x2 tables, giving conservative answers. This page runs uncorrected Pearson; note the choice in reports.
Sources
- OpenStax Statistics: chi square formula review
- NIST Engineering Statistics Handbook: chi square goodness of fit