01
Goodness of fit formula
χ² = Σ (observed − expected)² ÷ expected
degrees of freedom = number of categories − 1
Expected counts are the expected proportions multiplied by the total number of observations. If you estimate a parameter from the data to get the expected values, subtract one more degree of freedom for each; the calculator does this when you set “Parameters estimated from the data”. Fitting a Poisson distribution with its mean taken from the sample is one estimated parameter.
02
Worked example: a 9:3:3:1 ratio
Mendel's dihybrid pea cross gave 315, 108, 101 and 32 seeds in the four classes, 556 in total.
| Class | Observed | Expected (9:3:3:1) | (O − E)² ÷ E |
|---|---|---|---|
| Round yellow | 315 | 312.75 | 0.016 |
| Round green | 108 | 104.25 | 0.135 |
| Wrinkled yellow | 101 | 104.25 | 0.101 |
| Wrinkled green | 32 | 34.75 | 0.218 |
χ² = 0.470, df = 3, p = 0.925
The counts fit the 9:3:3:1 ratio very closely.
03
Worked example: is a die fair?
Sixty rolls give 8, 12, 9, 11, 14 and 6. With a fair die each face is expected 10 times. χ² = 4.2 with 5 degrees of freedom, p = 0.521: there is no evidence the die is unfair.
04
Common mistakes with the goodness of fit test
- Using percentages instead of counts. Mendel’s four classes as percentages (56.7, 19.4, 18.2, 5.8) give χ² = 0.074 instead of 0.470: the test then thinks about 100 seeds were counted, not 556.
- Forgetting estimated parameters. A χ² of 7.0 with four categories has p = .072 on 3 degrees of freedom, but p = .030 on 2, the right number if one parameter came from the data.
- Typing the ratio in the wrong order. Mendel’s counts against 1:3:3:9 instead of 9:3:3:1 give χ² = 2,512. Check that each ratio sits next to its class.
Trust
How this page is checked
- The calculation runs on code with automated tests against worked reference values. Every number in the examples on this page was produced by that same code, not typed by hand.
- The formulas and conventions used are stated on the page, so you can reproduce the result yourself or compare it with your own software.
- Last reviewed by the Sciloom team, Zebra Nine Studio Inc. It is a tool for research and teaching, not a substitute for a statistician, a validated lab method or medical advice.
Cite this page
Sciloom. (2026). Chi-square goodness of fit calculator. Zebra Nine Studio Inc. https://sciloom.si/chi-square-goodness-of-fit-calculator
Frequently asked questions
What is the difference between goodness of fit and the test of independence?
Goodness of fit compares one categorical variable with a distribution you specify in advance. The test of independence asks whether two categorical variables are related, and takes its expected counts from the table margins.
Can I enter percentages instead of counts?
Observed values must be counts: the test depends on the sample size. Expected values can be percentages, proportions or a ratio.
How large must the expected counts be?
The usual guide is at least 5 in every category. Below that, combine categories or use an exact multinomial test.
What does a high p value mean here?
That the data give no reason to reject the expected distribution. It does not prove the distribution is correct, especially with a small sample.