The chi-square test answers a simple question: are the counts you observed in a set of categories close enough to what you'd expect โ€” under a stated hypothesis โ€” that the difference could plausibly be chance? This calculator runs the two most common versions, goodness-of-fit and test of independence, and reports the chi-square statistic, degrees of freedom, and p-value so you can make that call.

How the chi-square test works

Every chi-square test compares an observed count O to an expected count E in each category or cell, using ฯ‡ยฒ = ฮฃ(O โˆ’ E)ยฒ / E. Squaring the difference means both over- and under-counts push ฯ‡ยฒ up, and dividing by E means the same absolute gap matters more in a category where you expected few observations than in one where you expected many. The resulting ฯ‡ยฒ is compared against the chi-square distribution for the appropriate degrees of freedom to get a p-value โ€” the probability of seeing a deviation this large (or larger) if the null hypothesis were true.

Goodness-of-fit vs. independence โ€” which do I need?

Use goodness-of-fit when you have one categorical variable and want to know if its distribution matches a specific expected pattern โ€” a fair die, a known population split, or a claimed ratio. Use the test of independence when you have two categorical variables recorded together for the same subjects (a contingency table) and want to know if they're related โ€” does treatment group affect outcome, does region affect preference. The math is the same formula in both cases; the only difference is how the expected counts are derived and how degrees of freedom is computed.

Reading the p-value and the low-expected-count guard

Compare the p-value to your chosen significance level ฮฑ (0.05 by default): p < ฮฑ means reject the null hypothesis โ€” the observed pattern is unlikely to be chance alone. p โ‰ฅ ฮฑ means you don't have enough evidence to rule out chance. The chi-square approximation itself relies on expected counts being reasonably large โ€” as a rule of thumb, every cell should have an expected count of at least about 5. This calculator flags a warning whenever any expected count falls below that threshold, since the p-value becomes less reliable with very sparse categories or cells.