Chi-Square Calculator
Chi-square goodness of fit or test of independence: χ², degrees of freedom, p-value and expected counts, with a warning when expected counts are small.
Result…
How it's calculated
χ² = Σ (O − E)² ÷ E Goodness of fit: df = categories − 1 − estimated parameters Contingency: E = row total × column total ÷ N, df = (rows − 1)(columns − 1) Yates (2 × 2): χ² = Σ (|O − E| − 0.5)² ÷ E p = P(χ²_df ≥ χ²)
The chi-square test compares counts you observed with the counts you would expect if a hypothesis were true. Goodness of fit checks one set of categories against a claimed pattern (a fair die, a genetic ratio, market shares). The contingency test checks whether two classifications are independent, such as treatment against outcome, from a table of counts. The p-value comes from the chi-square distribution through the regularised incomplete gamma function. The approximation needs reasonably large expected counts: a common rule of thumb is at least 5 in every cell, and the calculator warns when any is lower. Yates' correction makes a 2 × 2 test more conservative; statisticians disagree about whether to use it, so say which you used.
Your numbers, step by step
About the Chi-Square calculator
This chi-square calculator runs the two everyday chi-square tests on counts. The goodness of fit test checks whether one set of category counts matches an expected pattern, such as a fair die, a 9 : 3 : 3 : 1 genetic ratio or last year's market shares. The contingency table test checks whether two classifications are independent, such as treatment against outcome or region against preference. Enter observed counts with equal expectations, proportions or expected counts, or paste a table one row per line. You get χ², the degrees of freedom, the p-value, the critical value and the decision, plus Cramér's V for tables. The steps list every expected count and each (O − E)² ÷ E term, and a warning appears when any expected count is below 5. An optional Yates correction is available for 2 × 2 tables.
How to use it
- Choose the “Test”: “Goodness of fit” for one row of counts, or “Contingency table” for a table.
- For goodness of fit, enter the “Observed counts” and choose under “Expected” whether all categories are equal, or type proportions or expected counts.
- For a table, type the “Table of counts (one row per line)”, and switch on the “Yates continuity correction (2 × 2 only)” if your course or journal asks for it.
- Pick the “Significance level (α)”.
- Read the p-value, χ², degrees of freedom and decision, and check the warning about small expected counts.
Worked example
A die rolled 60 times shows 8, 9, 12, 11, 6 and 14 of each face. A fair die expects 60 ÷ 6 = 10 of each, so χ² = (8 − 10)² ÷ 10 + … + (14 − 10)² ÷ 10 = 4.2 with 6 − 1 = 5 degrees of freedom. The p-value is 0.521, well above 0.05, and the critical value is 11.07, so there is no evidence the die is unfair. For the 2 × 2 table 20, 15 / 30, 35, χ² = 1.099 with 1 degree of freedom and p = 0.2945; with the Yates correction χ² = 0.7033 and p = 0.4017.
Updated
Questions people ask
How do I calculate a chi-square statistic?
For each category or cell, subtract the expected count from the observed count, square it and divide by the expected count, then add up all those terms. In a contingency table each expected count is its row total times its column total divided by the grand total.
How many degrees of freedom does a chi-square test have?
For goodness of fit it is the number of categories minus 1, minus one more for each parameter you estimated from the same data. For a contingency table it is (rows − 1) × (columns − 1), so a 2 × 2 table has 1.
What if some expected counts are below 5?
The chi-square p-value relies on an approximation that gets worse with small expected counts, and a common rule of thumb asks for at least 5 in every cell. Combine sparse categories or collect more data; for a 2 × 2 table, an exact test such as Fisher's is the usual alternative.
Should I use the Yates correction?
It makes the 2 × 2 test more conservative, giving a larger p-value. Statisticians disagree on whether it is needed, so follow your course or journal and say which version you report.
Can I enter percentages instead of counts?
Not as the observed values: the test depends on how many observations you have, so 30% of 20 and 30% of 2,000 give very different answers. Percentages are fine for the expected pattern, which is scaled to your total. For a z or t statistic instead of counts, use the p-value calculator.