Chi-Square Test Calculator

Test whether two categorical variables are independent (2x2 table), or whether observed counts fit expected percentages (goodness of fit). Enter whole counts, pick your significance level and read the verdict.

Updated

Embed this calculator

Paste this code into your page. The calculator runs inside the frame and links back to the full version.

Keep the credit link in place. Do not resell the calculator.

Formula

  • Statistic: chi2 = sum of (O - E)^2 / E over all cells or categories
  • 2x2 expected count: E = row total x column total / grand total, with df = 1
  • Yates correction (2x2): chi2 = sum of (max(0, |O - E| - 0.5))^2 / E
  • Goodness of fit: E = total x expected share, with df = categories - 1
  • p-value: the upper tail of the chi-square distribution, P(X >= chi2)

Worked example

Table 12, 5 / 7, 7 (total 31). Row totals are 17 and 14, column totals 19 and 12. Expected counts are 10.42, 6.58 / 8.58, 5.42. Then chi2 = 1.3716, df = 1, p = 0.2415. With Yates correction chi2 = 0.6411, p = 0.4233. At alpha 0.05 neither is significant.

Goodness of fit: observed 44, 56, 30 against shares 40, 40, 20 percent. Total 130, so expected 52, 52, 26. chi2 = 2.1538, df = 2, p = 0.3406.

Frequently asked questions

What does a chi-square test tell me?

It compares the counts you observed with the counts you would expect if the null hypothesis were true. For the table 12, 5 / 7, 7 the chi-square statistic is 1.3716 with 1 degree of freedom and p = 0.2415, so there is no evidence of an association at alpha 0.05.

When should I use the Yates continuity correction?

Yates subtracts 0.5 from each |observed minus expected| in a 2x2 table, which makes the test more conservative. It is often used when an expected count is below 10 or the total is small. For 12, 5 / 7, 7 it lowers chi-square from 1.3716 to 0.6411 and raises p to 0.4233.

How are expected counts and degrees of freedom calculated?

In a 2x2 table each expected count is row total times column total divided by the grand total, and df = (rows - 1) x (columns - 1) = 1. For goodness of fit, expected = total x expected share, and df = categories - 1. Three categories with 130 observations and shares 40, 40, 20 percent give expected counts 52, 52, 26 and df = 2.

What is the rule for minimum expected counts?

The chi-square approximation is reliable when nearly every expected count is at least 5. With smaller counts, a Fisher exact test is the usual alternative for 2x2 tables. This calculator shows the expected counts so you can check the rule yourself. The test also assumes independent observations; if any expected counts are below 5, treat the p-value with caution.

Why does goodness of fit need percentages that add to 100?

The expected shares describe the whole population, so they must total 100 percent (within 0.01). A category with a 0 percent share is ignored and must have 0 observed. At least two categories need a positive share.