Test categorical data two ways: independence in a table (rows × columns of observed counts) or goodness of fit (observed counts against expected counts). Get the chi-square statistic, degrees of freedom, the expected table and the p-value.
For independence: (rows − 1) × (columns − 1). For goodness of fit: categories − 1 (minus any parameters estimated from the data, which this calculator does not do).
The standard rule of thumb wants most expected counts at least 5. With tiny expected counts the chi-square approximation weakens — Fisher's exact test is the classic alternative for small 2×2 tables.
For independence: the two variables are associated — not that one causes the other. For goodness of fit: the observed pattern departs from the expected model more than chance alone would typically produce.
Because checking expected counts is part of doing the test honestly — you can see exactly which cells drive the statistic.
χ² = Σ (O − E)² ÷ E over all cells. For independence, E for a cell = (row total × column total) ÷ grand total, and df = (r − 1)(c − 1). For goodness of fit, E values are supplied by the model and df = categories − 1. The p-value is the right tail of the chi-square distribution, computed via the incomplete gamma function.
Inputs: table [[10, 20], [20, 10]].
Steps: Row totals 30 and 30; column totals 30 and 30; grand total 60. Every E = 30 × 30 ÷ 60 = 15. Each cell contributes (5² ÷ 15) = 1.667; four cells give χ² = 6.667. df = (2−1)(2−1) = 1. p = P(χ²₁ ≥ 6.667) ≈ 0.0098.
Result: χ² = 6.667, df 1, p ≈ 0.0098. Goodness-of-fit check: observed [10, 20, 30] against expected [20, 20, 20] gives χ² = 5 + 0 + 5 = 10 on 2 df, p ≈ 0.0067.
Add this calculator to your own website or blog — it is completely free, needs no sign-up, and always shows the latest version. Copy the code below and paste it into your page where you want the calculator to appear. Keeping the small “Powered by Loona Automation” credit line under the embed helps keep this tool free — but you are free to style or remove it; the tool works either way.