Chi-Square Test Calculator
Compute the chi-square (χ²) statistic from observed and expected frequencies to test goodness of fit or independence. Use it whenever you need to determine whether categorical data match a theoretical distribution.
About this calculator
The chi-square statistic measures how much observed categorical frequencies deviate from expected frequencies under the null hypothesis. The formula is: χ² = Σ [(Oᵢ − Eᵢ)² / Eᵢ], summed over all categories. Each term squares the difference between observed (O) and expected (E) counts, then divides by E to standardize by the expected magnitude. A χ² of zero means perfect agreement; larger values indicate greater discrepancy. The computed statistic is compared against a critical value from the chi-square distribution with degrees of freedom df = (number of categories − 1) for a goodness-of-fit test, or df = (rows − 1)(columns − 1) for an independence test. If χ² exceeds the critical value at your chosen α, you reject the null hypothesis. A key assumption is that each expected frequency should be at least 5; small expected counts make the chi-square approximation unreliable.
How to use
A die is rolled 60 times. Each face is expected to appear 10 times. Suppose face 1 shows 14 times and face 2 shows 7 times (illustrating two categories). Step 1: Category 1: (14 − 10)² / 10 = 16/10 = 1.6. Step 2: Category 2: (7 − 10)² / 10 = 9/10 = 0.9. Step 3: χ² = 1.6 + 0.9 = 2.5. Enter observed_1 = 14, expected_1 = 10, observed_2 = 7, expected_2 = 10. With df = 1 and α = 0.05, the critical value is 3.841. Since 2.5 < 3.841, we fail to reject the null hypothesis.
Frequently asked questions
What is the difference between a chi-square goodness-of-fit test and a chi-square test of independence?
A goodness-of-fit test compares observed frequencies in a single categorical variable against theoretically expected frequencies — for example, checking whether a die is fair. A test of independence uses a contingency table to determine whether two categorical variables are related — for example, whether gender and voting preference are associated. Both use the same χ² formula, but degrees of freedom differ: df = k − 1 for goodness-of-fit, and df = (r − 1)(c − 1) for independence, where r and c are the numbers of rows and columns.
Why must expected frequencies be at least 5 in a chi-square test?
The chi-square distribution is a continuous approximation to the discrete distribution of the test statistic. When expected counts are very small (below 5), the approximation breaks down and the test produces inflated Type I error rates — meaning it rejects the null hypothesis too often. In such cases, Fisher's exact test is the preferred alternative for 2×2 tables, as it computes exact probabilities without relying on large-sample approximations. For larger tables with sparse cells, consider combining categories or collecting more data.
How do I choose the correct degrees of freedom for a chi-square test?
Degrees of freedom control the shape of the chi-square distribution and therefore the critical value threshold. For a goodness-of-fit test with k categories, df = k − 1, because once k − 1 frequencies are known the last is determined by the total. For a contingency table test of independence with r rows and c columns, df = (r − 1)(c − 1). Using the wrong df will give you the wrong critical value, potentially leading to incorrect conclusions. Always verify the number of independent categories or cells before entering the degrees of freedom.