BiostatKit / Tests & intervals / Chi-square test
Chi-Square Test Calculator (2x2)
The chi-square test for a 2x2 table checks whether the proportion with an outcome differs between two groups. It compares observed counts with the counts expected if group and outcome were unrelated: chi-square = Σ (O - E)² / E, with 1 degree of freedom. If an expected count is under 5, use Fisher's exact test.
Enter a 2x2 table and get the Pearson chi-square with its P value, the Yates-corrected version, the Fisher exact P value, the expected counts and phi, plus a sentence for your manuscript and the R code that reproduces every number.
Your data never leaves your browser. No sign-up, no ads.Result
Test of association between group and outcome.
Sentence for your manuscript
Written in AMA style from your numbers. Check it against your own study design before you submit.
Reporting checklist
- STROBE 2007 (observational studies): describe all statistical methods (item 12) and report the numbers with the outcome in each group (item 15).
- CONSORT 2010 (trials): for each outcome give the result in each group and the effect size with its precision (item 17a). A P value alone is not an effect size: report the two percentages, and the risk difference, relative risk or odds ratio with a 95% CI.
- Name the test (Pearson, Yates-corrected or Fisher exact) and say why you chose it, for example because an expected count was under 5.
Methods wording. The association between group and outcome was tested with the Pearson chi-square test [2] without continuity correction (BiostatKit [1]); when any expected count was below 5, the Fisher exact test was used.
[1] BiostatKit. Chi-square test calculator. Accessed [date]. [URL]
[2] Pearson K. On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philos Mag. 1900;50(302):157-175.
Reproduce it in R
The script is filled in with your numbers. Paste it into R or RStudio and compare.
This calculator was checked against Python (SciPy chi2_contingency, fisher_exact and contingency.association) on 3 reference cases and matched to 4 significant digits. See the verification log.
How the chi-square test works
What it is
The chi-square test asks whether the share of people with the outcome differs between two groups more than chance would explain. It compares the counts you observed with the counts expected if group and outcome were unrelated. A small P value means the observed table would be unusual if there were no association.
How this page computes it
Expected count of each cell: E = row total x column total / N.
χ² = Σ (O - E)² / E over the four cells, with 1 degree of freedom. For a 2x2 table this equals N (ad - bc)² / [(a+b)(c+d)(a+c)(b+d)].
The Yates correction subtracts 0.5 from each |O - E| before squaring (no more than |O - E| itself, as in R and SciPy). The Fisher exact P is two-sided: the sum of the probabilities of all tables with the same margins that are no more likely than the observed one. phi = (ad - bc) / sqrt[(a+b)(c+d)(a+c)(b+d)].
Assumptions
- Each person is counted once, and people are independent. For paired yes/no data (before and after, matched pairs) use the McNemar test instead.
- For the chi-square approximation every expected count should be at least 5. If one is smaller, report the Fisher exact P.
- Group and outcome were defined before looking at the data.
Common mistakes
- Reporting only "P < .05". Give the two percentages and an effect size with its 95% CI; the odds ratio and relative risk calculators use the same table.
- Checking the observed counts instead of the expected counts for the "at least 5" rule.
- Entering percentages or means instead of counts.
- Reading a non-significant P as proof that the groups are the same.
Worked example
Step by step
30 of 100 people in group 1 and 15 of 100 in group 2 had the outcome: a = 30, b = 70, c = 15, d = 85.
Expected counts: 45 x 100 / 200 = 22.5 with the outcome and 77.5 without it in each group.
χ² = (30 - 22.5)²/22.5 + (70 - 77.5)²/77.5 + (15 - 22.5)²/22.5 + (85 - 77.5)²/77.5 = 6.45, df 1, P = .011. Yates-corrected χ² = 5.62 (P = .018); Fisher exact P = .017; phi = 0.18.
Press Load example above to see these numbers in the calculator.
How to read the result
The outcome was twice as common in group 1 (30%) as in group 2 (15%). If group and outcome were unrelated, a table this uneven would arise only about 1 time in 90 (P = .011).
All expected counts are above 5, so the Pearson P is appropriate. The test does not give the size of the effect: report the risk difference of 15 percentage points, or the relative risk or odds ratio with its 95% CI.
Frequently asked questions
Pearson, Yates or Fisher: which P value do I report?
If every expected count is 5 or more, the Pearson chi-square without correction is the usual choice. If any expected count is below 5, report the Fisher exact P. The Yates correction is conservative; some journals still ask for it, so it is shown as well.
What are the degrees of freedom of a 2x2 chi-square test?
One. In general the degrees of freedom are (rows - 1) x (columns - 1), so a 2x2 table has 1.
Does the chi-square test tell me how big the difference is?
No. It only tests whether there is an association. Report the two percentages with a risk difference, relative risk or odds ratio and its 95% CI. Phi is shown as a rough measure of strength.
Can I use it for a table with more than two rows or columns?
Not on this page, which takes a 2x2 table. In R, chisq.test() takes any table of counts.
Is my data stored or sent anywhere?
No. All calculations run in your browser tab. Nothing is uploaded, and the page works offline once loaded.
Related calculators
- Odds ratio calculator: Odds ratio, 95% CI, chi-square and Fisher p-values from a 2x2 table.
- Relative risk calculator: Relative risk, absolute and relative risk reduction with 95% CIs.
- Confidence interval for a proportion: Wilson, Clopper-Pearson exact and Wald 95% CIs for one proportion.
- All BiostatKit calculators