What this calculator does
The chi-square goodness of fit test compares observed counts against what a hypothesis predicts. Five categories observed at 18, 22, 20, 24, 16 against an expectation of 20 each gives a statistic of 2.000 on 4 degrees of freedom, which is a very good fit.
The statistic is built from squared differences divided by the expected count, and that division is what makes it work. A discrepancy of 5 against an expected 20 is substantial; the same discrepancy against an expected 5,000 is nothing. Dividing by the expectation puts every category on a comparable footing.
The formula
For each category, the difference between observed and expected is squared and divided by the expected count, and those contributions are summed. Degrees of freedom are the number of categories minus one, since the totals are constrained to match. The result must be compared with a critical value for that many degrees of freedom.
| Term | Meaning |
|---|---|
| χ² statistic | The sum of (O−E)²/E across categories. Zero means a perfect match. |
| Expected counts | What the hypothesis predicts, which must be counts rather than proportions. |
| Degrees of freedom | Categories minus one for a goodness of fit test. |
| Expected count rule | Each expected count should be at least 5 for the approximation to hold. |
The inputs explained
| Field | What to enter |
|---|---|
| Observed counts (comma separated) | Observed counts, comma separated. These must be actual counts, not percentages. |
| Expected counts (comma separated) | Expected counts under your hypothesis, in the same order. The totals should match the observed total. |
When to use it
Testing whether a die is fair
Comparing observed face counts against equal expected counts is the textbook application.
Checking a distribution against theory
Whether observed category shares match a genetic ratio, a published breakdown or a historical pattern.
Validating a sample
Whether a sample demographic breakdown matches the population it was drawn from.
Worked examples
Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.
How does the fit affect the statistic?
Observed counts ranging from a perfect match to a strong trend.
| Observed counts | Chi-square statistic | Degrees of freedom | Total observed, expected |
|---|---|---|---|
| 20, 20, 20, 20, 20 | 0 | 4 | 100.000, 100.000 |
| 18, 22, 20, 24, 16 | 2.000 | 4 | 100.000, 100.000 |
| 10, 15, 20, 25, 30 | 12.500 | 4 | 100.000, 100.000 |
| 35, 25, 20, 12, 8 | 22.900 | 4 | 100.000, 100.000 |
Questions
What is a significant chi-square value?
It depends on the degrees of freedom. At 4 degrees of freedom the 5% critical value is 9.49 and the 1% value is 13.28. A statistic above the critical value means the observed counts differ from expectation by more than chance comfortably explains.
Do I need expected counts of at least 5?
It is the standard guideline, since the chi-square approximation degrades when expected counts are very small. If some categories fall below 5, combine adjacent categories or use an exact test such as Fisher exact test instead.
Can I enter percentages instead of counts?
No. The test depends on the actual sample size, since the same percentage discrepancy from 100 observations and from 10,000 carries completely different evidential weight. Entering percentages would effectively claim a sample size of 100.
What is the difference from a chi-square test of independence?
Goodness of fit compares one set of observed counts against a theoretical expectation, with df = categories − 1. The test of independence compares a two-way table against the expectation from independent row and column totals, with df = (rows−1)(columns−1).
For comparing three or more group means, see the one-way ANOVA calculator. For small expected counts, see the Fisher’s exact test calculator.