331+ free tools. No sign-up. No hidden fees. Explore the toolkit

Chi-Square Calculator

The chi-square test compares what you observed with what you would expect if nothing interesting were going on. Run a test of independence on a contingency table (2×2 up to 4×4, with Yates' correction), or a goodness-of-fit test against expected counts.

Pick a test type, enter your counts, and get the χ² statistic, degrees of freedom, p-value, expected frequencies and the verdict at α = 0.05 instantly.

Enter counts (whole numbers, 0 or more). Changing the table size loads the worked-example values for that size.

Result

Expected frequencies

Save to Pinterest
Note: The p-value comes from the chi-square distribution, computed with the regularized incomplete gamma function, accurate to about 1e-12 — the same method used by R and SciPy, cross-checked against SciPy 1.11.4. The test assumes independent observations and counts, not percentages; it is unreliable when expected frequencies fall below 5. This calculator is for education and quick checks — it is not a substitute for professional statistical advice.

How It Works

The chi-square test compares what you observed with what you would expect if nothing interesting were going on. For a test of independence, you arrange counts in a contingency table; the expected count in each cell is (row total × column total) ÷ grand total, which is what you would see if the two variables were unrelated. For a goodness-of-fit test, you supply the expected counts directly. Either way, the statistic is the same: χ² = Σ (O − E)² ÷ E, summed over every cell. The degrees of freedom are (rows − 1) × (columns − 1) for independence, or categories − 1 for goodness-of-fit. Chi-square works on counts in categories; to compare the means of two groups, use a t-test.

The p-value is the probability of a χ² at least this large under the chi-square distribution, computed here with the regularized incomplete gamma function — accurate to about 1e-12, the same method used by R and SciPy. If p is below 0.05, the result is significant: the variables are associated (independence test) or the data does not match the expected distribution (goodness-of-fit). Yates' continuity correction, for 2×2 tables only, subtracts 0.5 from each |O − E| difference before squaring, making the test slightly more conservative.

Worked Example

Independence, 2×2: the table [[30, 10], [20, 30]] has row totals 40 and 50, column totals 50 and 40, and grand total 90. The expected frequencies are 22.2222, 17.7778, 27.7778, 22.2222, giving χ² = 11.0250 with 1 degree of freedom and p = 0.0009 — significant at α = 0.05. With Yates' correction, χ² = 9.6531 and p = 0.0019. Independence, 3×3: [[20, 15, 10], [25, 20, 5], [10, 10, 30]] gives χ² = 31.7666, df = 4, p < 0.0001 — strongly significant. Goodness-of-fit: observed 90, 60, 50 against expected 100, 60, 40 gives χ² = 3.5000, df = 2, p = 0.1738 — not significant, so the data is consistent with the expected distribution.

Assumptions

Last reviewed: 15 November 2026.

Built and tested by SumKitTool — see how we check our numbers.

How to Use This Calculator

Pick a test type, enter your counts, and the result updates live as you type.

  1. Choose the test type — independence from a contingency table, or goodness-of-fit from observed and expected lists.
  2. Enter your counts — pick the table size (2×2 up to 4×4) and fill in the cells, or paste the two lists for goodness-of-fit. Tick Yates' correction for a 2×2 table if you want it.
  3. Read the answer — the χ² statistic, the degrees of freedom, the p-value, the expected frequencies table and the verdict at α = 0.05.

The Reset button restores the worked example (2×2 table [[30, 10], [20, 30]] — χ² = 11.0250, p = 0.0009).

Tips and Practical Advice

Frequently Asked Questions

What is the chi-square test of independence?

It tests whether two categorical variables are associated — whether knowing one tells you anything about the other. You arrange the counts in a contingency table, and the test compares the observed counts with the counts you would expect if the variables were independent. For example, a 2×2 table of 30, 10, 20, 30 gives χ² = 11.0250 with 1 degree of freedom and p = 0.0009 — strong evidence that the two variables are associated, not independent.

What is Yates' correction, and when should I use it?

Yates' continuity correction subtracts 0.5 from each |observed − expected| difference before squaring, which makes the test slightly more conservative. It applies to 2×2 tables only, where the chi-square distribution approximates a discrete distribution. For the worked example, the uncorrected χ² is 11.0250 (p = 0.0009) and with Yates' correction it is 9.6531 (p = 0.0019) — the same conclusion here, but the correction can matter near the 0.05 boundary. This calculator applies it only when the table is 2×2, even if the box is ticked for a larger table.

What is the goodness-of-fit test?

It tests whether observed counts match an expected distribution. You enter the counts you observed and the counts you expected — for example, 90, 60 and 50 observed against 100, 60 and 40 expected gives χ² = 3.5000 with 2 degrees of freedom and p = 0.1738, which is not significant: the data is consistent with the expected distribution. The classic use is checking whether a die is fair, or whether survey answers match a known split.

What if some expected frequencies are below 5?

The chi-square approximation gets unreliable when expected frequencies are small — the usual rule is that every expected frequency should be at least 5. This calculator warns you when any expected frequency falls below 5. If that happens, try combining categories to raise the counts, collecting more data, or — for a 2×2 table — using Fisher's exact test, which does not rely on the approximation. A row or column that totals zero makes the test undefined, and the calculator shows a clear message instead of a number.

Last updated: