Home ↓
CalculatorsVerified

Math & Geometry

Chi-Square Test Calculator (2×2 Contingency Table)

The chi-square test of independence is one of the most widely used tests in statistics. It asks whether two categorical variables are related, for example whether a treatment group and a control group differ in the share of patients who recover, or whether customers who saw one version of a web page bought more often than those who saw another. The data are arranged in a contingency table; this calculator handles the common 2×2 case, with two groups and a yes-or-no outcome. The test compares the counts actually observed with the counts you would expect if the two variables were completely unrelated. Each expected count equals its row total multiplied by its column total, divided by the grand total. The chi-square statistic adds up the squared differences between observed and expected counts, each divided by the expected count. A large value means the observed pattern is unlikely to have arisen by chance if there were no association. For a 2×2 table there is one degree of freedom, and the p-value equals twice the upper tail of the standard normal distribution at the square root of the statistic, which this calculator computes directly. The results show the p-value, the statistic, whether the result is significant at the conventional 5 percent level, the proportions in each group, the odds ratio and the expected counts. The test is reliable when every expected count is at least about 5; with smaller samples, use Fisher’s exact test. The optional Yates continuity correction makes the test more conservative. Statistical significance does not prove cause and effect, and a large sample can make small, unimportant differences significant.

How to use this calculator

  1. Enter the counts for group 1 with and without the outcome.
  2. Enter the counts for group 2 with and without the outcome.
  3. Choose whether to apply the Yates continuity correction.
  4. Read the p-value and whether the association is significant.
  5. Check that all expected counts are at least 5.

Interpreting the result

A small p-value means the data would be unusual if the groups really had the same rate, so you have evidence of an association. It does not say how large the difference is, which is why the proportions and odds ratio matter too.

Results close to the 0.05 threshold, as in the example, are sensitive to the method chosen. Report the exact p-value and the method rather than only significant or not.

Larger tables and alternatives

Chi-square tests also work for larger tables, with degrees of freedom equal to (rows − 1) × (columns − 1), but this calculator focuses on the common 2×2 case.

For small samples, Fisher’s exact test gives an exact p-value. For paired data, such as before and after measurements on the same people, McNemar’s test is appropriate instead.

Formula & method

Expected count = row total × column total ÷ grand totalχ² = Σ (observed − expected)² ÷ expected (with Yates: (|O − E| − 0.5)²)A 2×2 table has 1 degree of freedom; p = 2 × (1 − Φ(√χ²))Check that all expected counts are at least 5; otherwise use Fisher’s exact test

E = row total × column total ÷ N. χ² = Σ (O − E)² ÷ E (Yates: Σ (|O − E| − 0.5)² ÷ E). df = 1, p = 2[1 − Φ(√χ²)]. Odds ratio = (a × d) ÷ (b × c).

Worked example

20 of 50 in group 1 and 30 of 50 in group 2 said yes

  1. Every expected count = 50 × 50 ÷ 100 = 25.
  2. χ² = 4 × (5² ÷ 25) = 4.0.
  3. p = 2 × (1 − Φ(2)) ≈ 0.0455; with Yates, χ² = 3.24 and p ≈ 0.072.

Answer: Significant at the 5% level without the correction (p ≈ 0.046), but not with Yates (p ≈ 0.072).

Frequently asked questions

What does the p-value mean?

It is the probability of seeing an association at least this strong if the two variables were actually independent; a p-value below 0.05 is conventionally called statistically significant.

When should I use the Yates correction?

It makes the test more conservative for small samples; many statisticians now prefer Fisher’s exact test when expected counts are small and the uncorrected test otherwise.

What is an odds ratio?

The odds of the outcome in group 1 divided by the odds in group 2; a value of 1 means no difference.

Can I enter percentages?

No, the test needs actual counts, because the sample size affects the result.

Why must expected counts be at least 5?

The chi-square approximation becomes unreliable for small expected counts, giving misleading p-values.

Does significance prove causation?

No, an association can be caused by confounding factors; only well-designed experiments support causal conclusions.