Chi-square calculator
Enter your counts, get χ² and the p-value.
What does a chi-square test do?
It checks whether counts differ from what you expected more than chance would explain. 100 customers split 50, 30 and 20 across three stores, against an even split, give χ² = 14 with 2 degrees of freedom and p = 0.0009 — very unlikely to be chance. Formally, the null hypothesis is that the counts follow the distribution you specified, and the alternative is that they do not (NIST/SEMATECH e-Handbook, section 1.3.5.15).
How is chi-square calculated?
χ² = Σ (observed − expected)² ÷ expected, summed over all groups. The degrees of freedom are the number of groups minus 1. Squaring makes every gap count as positive, and dividing by the expected count lets a gap of 10 weigh more in a small group than in a large one. This df rule holds when the expected counts were fixed before you looked at the data. If you estimated parameters from the same data, for example the mean of a Poisson distribution, NIST reduces the degrees of freedom by one for each estimated parameter.
How do I enter expected values?
Enter counts or proportions — they are scaled to the same total as the observed counts. Leave them empty to test against equal groups.
Worked example: streaming services
OpenStax (Introductory Statistics 2e, Example 11.3) asks whether families in the far western United States use streaming services in the same pattern as the nation. Nationally 10%, 16%, 55%, 11% and 8% of families have 0, 1, 2, 3 and 4 or more services. Among 600 sampled western families the observed counts are 66, 119, 340, 60 and 15. Enter those as observed and 10, 16, 55, 11, 8 as expected; the expected counts become 60, 96, 330, 66, 48. The terms (O − E)² ÷ E are 0.60, 5.51, 0.30, 0.55, 22.69, which add up to χ² = 29.65 with 4 degrees of freedom. The p-value is about 0.000006, far below α = 0.01 (the 1% critical value is 13.28), so the western pattern differs from the national one. The last group, 4 or more services, supplies 77% of the total: the difference is mostly that far fewer families have four or more.
What is the critical value at 0.05?
3.841 for 1 degree of freedom, 5.991 for 2 and 11.070 for 5. A χ² above the critical value means p is below 0.05.
When is the test unreliable?
When expected counts are small — a common rule is at least 5 in every group. The calculator warns you if any is lower. NIST’s advice is to combine neighboring categories (for instance in the tails of a distribution) until each expected count reaches 5, and notes that the result depends somewhat on how the data are binned, so choose the categories before looking at the counts.
Common mistakes with the goodness-of-fit test
First, entering percentages as the observed values. Only the expected values may be proportions; the observed values must be real counts, because χ² grows with the sample size. The same 50%, 30%, 20% split from 1,000 customers instead of 100 gives χ² = 140 instead of 14. Second, keeping df = k − 1 after estimating parameters from the data, which makes the p-value too large. Third, treating a significant result as proof of a particular pattern: the test only says the counts differ from the expectation, and the per-group terms in the result table show where. Fourth, counting the same person or item more than once; every observation must be independent and fall in exactly one category.
Is this the same as the test of independence?
No. The goodness-of-fit test compares one set of counts with a stated distribution. The test of independence uses a table with two categorical variables and works out the expected counts from its own row and column totals. Use the chi-square test of independence calculator for a table.
Sources: NIST/SEMATECH e-Handbook of Statistical Methods, section 1.3.5.15 (“Chi-square goodness-of-fit test”); OpenStax, Introductory Statistics 2e, section 11.2 (Goodness-of-Fit Test, Example 11.3). Related: chi-square test of independence, critical value calculator, p-value calculator, Poisson distribution calculator and Fisher’s exact test calculator.