Chi-Square Goodness of Fit Calculator
Enter your observed counts and the distribution you expect. The test checks whether the counts are consistent with it, category by category.
Checked on November 21, 2026. Results computed by our statistics engine, version 1.0.0.
On this page
What goodness of fit tests
The goodness-of-fit test asks whether one categorical variable follows a distribution you state in advance. The null hypothesis is that the population proportions equal your expected proportions. Expected counts are those proportions times the total N, and the test has (categories − 1) degrees of freedom, fewer if you estimated parameters from the same data.
The expected distribution must come from theory or an outside source, not from the data you are testing. A genetics ratio, a manufacturer's stated color mix or last year's market shares all work.
Worked example: Mendel's peas
In his 1866 paper Mendel crossed pea plants and counted 556 seeds of four kinds. A 9:3:3:1 ratio is what simple inheritance of two independent traits predicts. These counts are pre-filled above; the result is our calculation from Mendel's published counts.
| Seed type | Observed | Expected | (O − E)² / E |
|---|---|---|---|
| Round yellow | 315 | 312.75 | 0.0162 |
| Round green | 108 | 104.25 | 0.1349 |
| Wrinkled yellow | 101 | 104.25 | 0.1013 |
| Wrinkled green | 32 | 34.75 | 0.2176 |
The contributions add to χ² = 0.4700. With 3 degrees of freedom, p = 0.9254. The counts fit the 9:3:3:1 ratio very closely: a χ² this small or smaller would happen by chance only about 7% of the time, which is why Mendel's data have been discussed for their unusually good fit.
Worked example with stated proportions
R's help page tests counts of 89, 37, 30, 28, 2 against proportions 0.4, 0.2, 0.2, 0.15, 0.05 (R reference output). Choose "Proportions that add to 1" and enter both lists to reproduce χ² = 9.9901, df 4, p = 0.0406. At the 5% level that is evidence against the stated proportions.
R then changes the last two proportions to 0.19 and 0.01. The expected count in the last category drops to 1.86, and R warns that the approximation may be incorrect. χ² is 5.7947 and p = 0.2150. One of the five expected counts is below 5, which passes Cochran's rule but fails the stricter rule, and the calculator says so.
Expected counts instead of proportions
If you already have expected counts, choose "Expected counts". SciPy's documentation tests 16, 18, 16, 14, 12, 12 first against equal shares, giving χ² = 2.0000 and p = 0.8491, and then against expected counts 16, 16, 16, 16, 16, 8, giving χ² = 3.5000 and p = 0.6234 (SciPy chisquare). Expected counts that do not add to the observed total are rescaled with a note, so only their proportions matter.
Degrees of freedom when you estimate parameters
If you fit a model to the same data first, for example estimating a Poisson mean from the counts, each estimated parameter costs one degree of freedom. Enter the number of parameters in "Parameters estimated" and df becomes (categories − 1 − parameters). SciPy calls this ddof. R's chisq.test has no such argument, so the R code we generate recomputes p with the reduced df.
Two categories
With only two categories, such as heads and tails, the goodness-of-fit test is an approximation to the exact binomial test. The calculator suggests the binomial test in that case; for small samples it is the better choice.
Common questions
Can I enter percentages as observed values?
No. Observed values must be counts. Percentages are fine for the expected distribution.
What if my expected proportions add to 0.99?
Proportions that add to between 0.99 and 1.01 are rescaled to add to 1, with a note, as R does with rescale.p. Further off than that is treated as an error.
What does a large p-value mean here?
No evidence that the counts differ from the expected distribution. It does not prove the distribution is right.
Sources
- R reference example output, stats-Ex.Rout.save checked November 21, 2026
- SciPy documentation: scipy.stats.chisquare checked November 21, 2026