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.
Reversible category merge preview
Assign each original category a merge-group number. Group numbers start at 1 without gaps. Observed and expected counts are summed within each group. The original model stays available for comparison; Apply explicitly transfers the grouped counts.
Merging changes the categories and degrees of freedom of the test. Compare the original and merged models with their own assumptions; a smaller statistic does not establish that one model is preferable. Zero expected counts or nonpositive remaining df make ordinary GOF inference unavailable. Preview supports at most 200 original categories and preserves their mapping.