# Chi-Square Test Calculator (2x2)

> Free chi-square test calculator for a 2x2 table. Get the Pearson and Yates chi-square, Fisher exact P, expected counts and phi, a sentence and R code.

Canonical: https://biostatkit.com/chi-square-test

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.

## 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

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.

### 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.

## 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.

Method: Pearson chi-square with and without the Yates correction, Fisher exact test (two-sided), phi coefficient.

## 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](https://biostatkit.com/odds-ratio): Odds ratio, 95% CI, chi-square and Fisher p-values from a 2x2 table.
- [Relative risk calculator](https://biostatkit.com/relative-risk): Relative risk, absolute and relative risk reduction with 95% CIs.
- [Confidence interval for a proportion](https://biostatkit.com/confidence-interval-proportion): Wilson, Clopper-Pearson exact and Wald 95% CIs for one proportion.
- [All BiostatKit calculators](https://biostatkit.com/)

## References

1. 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. doi:[10.1080/14786440009463897](https://doi.org/10.1080/14786440009463897)
2. Yates F. Contingency tables involving small numbers and the χ2 test. Suppl J R Stat Soc. 1934;1(2):217-235. doi:[10.2307/2983604](https://doi.org/10.2307/2983604)
3. Fisher RA. On the interpretation of χ2 from contingency tables, and the calculation of P. J R Stat Soc. 1922;85(1):87-94. doi:[10.2307/2340521](https://doi.org/10.2307/2340521)
4. Agresti A. Categorical Data Analysis. 3rd ed. Hoboken, NJ: Wiley; 2013.
5. von Elm E, Altman DG, Egger M, Pocock SJ, Gøtzsche PC, Vandenbroucke JP; STROBE Initiative. The Strengthening the Reporting of Observational Studies in Epidemiology (STROBE) statement: guidelines for reporting observational studies. Lancet. 2007;370(9596):1453-1457. doi:[10.1016/S0140-6736(07)61602-X](https://doi.org/10.1016/S0140-6736%2807%2961602-X)

Author: TS.BS. Vũ Duy Kiên (https://www.vuduykien.com)
