Skip to main content

Chi-Square Test Calculator

Enter a contingency table or goodness-of-fit data to get expected frequencies, the χ² statistic, degrees of freedom, p-value, a significant-or-not verdict at your chosen α, Yates' correction for 2×2 tables, and Cramér's V effect size.

100% private — all math runs in your browser, nothing is uploaded

Test of independence (r × c table)

Tests whether two categorical variables are associated. Enter observed counts (whole numbers or decimals).

2
2

How the chi-square test works

Test of independence

For each cell, the expected count under "no association" is E = (row total × column total) ÷ grand total. The test statistic is χ² = Σ (O − E)² / E with df = (rows − 1)(columns − 1) degrees of freedom. The p-value is the upper-tail probability P(χ²df ≥ observed) from the chi-square distribution. If p < α, reject the null hypothesis of independence.

Goodness of fit

Compare k observed counts against expected counts (or proportions): χ² = Σ (O − E)² / E with df = k − 1. For Mendel's peas [315, 101, 108, 32] against the 9:3:3:1 ratio, χ² ≈ 0.47, df = 3, p ≈ 0.93 — the data are consistent with the claimed ratio.

Effect size

Cramér's V = √(χ² / (n · min(r−1, c−1))) ranges from 0 to 1. Interpretation follows Cohen's conventions, which depend on df* = min(r−1, c−1): df* = 1 → 0.10 small, 0.30 medium, 0.50 large; df* = 2 → 0.07 / 0.21 / 0.35; df* = 3 → 0.06 / 0.17 / 0.29. For goodness of fit, Cohen's w = √(χ² / n) uses the fixed benchmarks 0.10 / 0.30 / 0.50.

Chi-square vs. our A/B test calculator: the A/B test calculator compares two conversion rates with a two-proportion z-test plus uplift and sample-size planning. Chi-square is the general tool — it handles any r×c table. For a plain 2×2 A/B comparison, both agree closely. Related: standard normal distribution calculator, average and standard deviation calculator.

Frequently asked questions

What is a chi-square test?

A chi-square test checks whether categorical data differs from what you would expect under a null hypothesis. The test of independence asks whether two categorical variables are associated (for example, whether treatment outcome depends on the drug given). The goodness-of-fit test asks whether one categorical variable follows a claimed distribution (for example, whether a die is fair). Both compare observed counts O with expected counts E using the statistic χ² = Σ(O−E)²/E.

How do you calculate a chi-square statistic by hand?

Take the 2×2 table [[20,10],[10,20]]: row totals are 30 and 30, column totals are 30 and 30, grand total 60, so every expected count is E = (30×30)/60 = 15. Each cell contributes (O−E)²/E = (20−15)²/15 = 1.6667, and 4 × 1.6667 = 6.6667. With df = (2−1)(2−1) = 1, the p-value is about 0.0098, which is below 0.05, so the association is statistically significant.

What does the p-value mean in a chi-square test?

The p-value is the probability of getting a chi-square statistic at least as large as the one observed, assuming the null hypothesis is true. In the example above (χ² = 6.6667, df = 1) the p-value is about 0.0098, meaning such a lopsided table would occur by chance only about 0.98% of the time if the variables were truly independent. A p-value below your α (commonly 0.05) means the result is statistically significant.

What is Yates' continuity correction and when do I need it?

Yates' correction subtracts 0.5 from each |O−E| before squaring, compensating for the fact that the continuous chi-square distribution approximates discrete counts. It applies only to 2×2 tables. For the table [[20,10],[10,20]], the uncorrected χ² is 6.6667 (p ≈ 0.0098); with Yates' correction it drops to 5.4 (p ≈ 0.0201). Both are significant at α = 0.05 here, but the correction is more conservative. Enable the Yates checkbox above only for 2×2 tables.

How do I compute expected frequencies for a contingency table?

For each cell, expected frequency E = (row total × column total) / grand total. This is the count you would see if the two variables were perfectly independent. For example, in a table with row totals 30 and 30 and column totals 30 and 30 (grand total 60), every cell has E = (30×30)/60 = 15. The calculator above shows the full expected-frequency table next to your observed data.

What are degrees of freedom in a chi-square test?

Degrees of freedom measure how many independent pieces of information feed the test. For a test of independence on an r×c table, df = (r−1)(c−1): a 2×2 table has df = 1, a 2×3 table has df = 2, and a 3×3 table has df = 4. For goodness of fit with k categories, df = k−1. Larger tables need larger χ² values to reach significance, which is exactly what the p-value calculation accounts for.

What is Cramér's V and how do I interpret it?

Cramér's V measures effect size — how strong the association is, on a 0 to 1 scale — computed as V = √(χ²/(n·min(r−1,c−1))). Unlike the p-value, it does not grow just because the sample is large. Interpretation follows Cohen's conventions, which depend on df* = min(r−1,c−1): for df* = 1, 0.10 is small, 0.30 medium, 0.50 large; for df* = 2, 0.07/0.21/0.35; for df* = 3, 0.06/0.17/0.29. For the [[20,10],[10,20]] example, V = 0.333, a medium effect.

When is a chi-square test not valid? (expected counts below 5)

Cochran's rule: the chi-square approximation is unreliable if more than 20% of expected counts are below 5, or if any expected count is below 1. This calculator warns you automatically — for example, the table [[5,1],[1,5]] has expected counts of 3 in all four cells, so it raises the warning even though χ² = 5.3333 (p ≈ 0.0209). With small samples, consider Fisher's exact test for 2×2 tables or collect more data.

What is the difference between test of independence and goodness of fit?

The test of independence uses a two-way contingency table to test association between two variables. Goodness of fit uses one row of observed counts against expected counts or proportions to test a claimed distribution. A classic goodness-of-fit example is Mendel's pea data [315, 101, 108, 32] against the 9:3:3:1 ratio: χ² ≈ 0.47, df = 3, p ≈ 0.93 — not significant, so the data are consistent with the 9:3:3:1 ratio. Use the goodness-of-fit tab above for this mode.

What chi-square value is significant at p = 0.05?

It depends on degrees of freedom: the critical values at α = 0.05 are 3.841 for df = 1, 5.991 for df = 2, and 7.815 for df = 3. A handy self-check: entering χ² = 3.841 with df = 1 gives p ≈ 0.0500, and χ² = 5.991 with df = 2 gives p ≈ 0.0500. Any observed χ² larger than the critical value for your df is significant at the 0.05 level.

Does a significant chi-square result prove causation?

No. A significant chi-square test shows an association between categorical variables, not that one causes the other. Confounding variables, selection bias, or reverse causation can all produce significant associations. Treat the result as evidence of a relationship worth investigating further, and report the effect size (Cramér's V) alongside the p-value so readers can judge practical importance.

My 2×2 table has very small counts. Should I still use chi-square?

If any expected count is below 5, the chi-square p-value is only approximate — this calculator will flag it with a Cochran warning. For 2×2 tables with tiny samples, Fisher's exact test is the safer choice because it computes exact probabilities instead of an approximation. As a rule of thumb, chi-square is comfortable when all expected counts are at least 5.

How is this different from an A/B test calculator?

An A/B test calculator (like our ab-test tool) compares two conversion rates with a two-proportion z-test and adds business metrics such as uplift and sample-size planning. The chi-square test of independence is the more general tool: it handles any r×c table (for example, 3 page variants × 4 outcome categories), while the A/B calculator is specialized for the 2×2 conversion case. For a plain 2×2 A/B comparison both approaches agree closely.

Can a result be significant but have a tiny effect size?

Yes — with a huge sample, even a trivial association becomes statistically significant. That is why this calculator always reports an effect size next to the p-value. Compare: the table [[100,10],[10,100]] gives χ² = 147.27 (p ≈ 6.8×10⁻³⁴) with Cramér's V = 0.82, a genuinely large effect. But the same proportions with 100× less data could be significant with a small V. Always read the p-value (is it real?) together with V (does it matter?).

Free tool by NRTechStudio