Chi-Square Goodness of Fit Calculator
Type each category’s count and the share you expect for it, as percentages…
Type each category’s count and the share you expect for it, as percentages, ratios or counts, to test whether the data fit, with Mendel’s peas as the example.
| Category | Observed | Expected share |
|---|---|---|
exp 312.8 | ||
exp 104.3 | ||
exp 104.3 | ||
exp 34.8 |
Expected shares can be percentages, a ratio (9, 3, 3, 1) or counts; they are scaled to your total. Leave them all empty to test equal shares.
Paste a table from a spreadsheet
Copy cells from Excel, Google Sheets or a CSV file and paste them here; the grid above follows.
ExampleP-value
0.9254
The counts fit the expected shares about as well as chance allows. Not significant at the 5% level (p ≥ 0.05).
Type your own counts, or paste a table.
The chi-square distribution with 3 df, what χ² looks like when nothing is going on; the shaded tail beyond yours is the p-value.
- χ², df
- 0.47, 3
- Total counted
- 556
- Expected counts under 5
- None
How this works: 9 sources,
How this works
Method
A goodness of fit test asks whether counts in categories match the shares a theory predicts: a fair die, an equal split between options, the ratios of a genetic cross, the expected mix of customers. The example is Gregor Mendel’s cross of round yellow peas with wrinkled green ones: 556 seeds against his predicted 9 : 3 : 3 : 1. Full method
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.5.15 Chi-Square Goodness-of-Fit Test
- Wikipedia, Experiments on Plant Hybridization (Mendel, 1866)
- NIST/SEMATECH e-Handbook of Statistical Methods
- Abramowitz and Stegun, Handbook of Mathematical Functions, chapters 6, 7 and 26 (1964)
- SciPy 1.18 scipy.stats (reference values for the tests)
- statsmodels 0.15 (reference values for the A/B test and regression intervals)
- Welch, The generalization of Student’s problem when several different population variances are involved (Biometrika) (1947)
- Fleiss, Levin and Paik, Statistical Methods for Rates and Proportions, 3rd edition (sample size for two proportions) (2003)
- Hyndman and Fan, Sample quantiles in statistical packages (The American Statistician) (1996)
How it’s tested
2 worked examples for this page are checked by automated tests before every release: given the inputs, the tool must show the expected answer.
Privacy
On your device. Nothing you enter or open leaves this browser. About privacy labels
Changes
- First published: live curves with draggable cut-offs, and tests on pasted data (t-tests, ANOVA, chi-square, Fisher’s exact, correlation, regression, A/B), checked against SciPy.
How the chi-square goodness of fit test works
A goodness of fit test asks whether counts in categories match the shares a theory predicts: a fair die, an equal split between options, the ratios of a genetic cross, the expected mix of customers. The example is Gregor Mendel’s cross of round yellow peas with wrinkled green ones: 556 seeds against his predicted 9 : 3 : 3 : 1.
Turn the shares into expected counts by scaling them to the total (9/16 of 556 is 312.75), then add up (observed − expected)² ÷ expected over the categories. With k categories the statistic follows a chi-square distribution with k − 1 degrees of freedom when the theory is right. Mendel’s peas give χ² = 0.47 on 3 df, p = 0.93: an almost perfect fit.
A very high p-value is not proof the theory is right; it only means the data don’t contradict it. In fact Mendel’s results across his experiments fit so well that R. A. Fisher argued in 1936 they were better than chance would usually allow. If you estimate anything from the data to build the expected shares, take one more degree of freedom off for each.
Eᵢ = N × shareᵢ ÷ Σ shares · χ² = Σ (Oᵢ − Eᵢ)² ÷ Eᵢ, df = k − 1
- The chi-square goodness-of-fit test compares observed counts in k bins with the counts expected under a hypothesised distribution; the statistic has k − c degrees of freedom, where c is the number of estimated parameters plus 1. Source: NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.5.15 Chi-Square Goodness-of-Fit Test.
- In his 1866 paper Mendel reported the counts of his pea crosses, including 315 round yellow, 108 round green, 101 wrinkled yellow and 32 wrinkled green seeds from the dihybrid cross. Source: Wikipedia, Experiments on Plant Hybridization (Mendel, 1866).
Mendel’s 3 : 1 crosses tested
Mendel’s published counts for the second generation of his seven single-trait crosses, each tested against a 3 : 1 ratio (1 degree of freedom).
| Trait (dominant : recessive) | Counts | Ratio | χ² | p-value |
|---|---|---|---|---|
| Seed shape (round : wrinkled) | 5,474 : 1,850 | 2.96 : 1 | 0.263 | 0.608 |
| Seed colour (yellow : green) | 6,022 : 2,001 | 3.01 : 1 | 0.015 | 0.903 |
| Seed coat (grey : white) | 705 : 224 | 3.15 : 1 | 0.391 | 0.532 |
| Pod shape (inflated : constricted) | 882 : 299 | 2.95 : 1 | 0.064 | 0.801 |
| Pod colour (green : yellow) | 428 : 152 | 2.82 : 1 | 0.451 | 0.502 |
| Flower position (axial : terminal) | 651 : 207 | 3.14 : 1 | 0.35 | 0.554 |
| Stem length (long : short) | 787 : 277 | 2.84 : 1 | 0.607 | 0.436 |
Common questions
How do I test whether a die is fair?
Type the six faces as categories with how often each came up, and leave the expected shares empty: equal shares are the default. With 60 rolls each face is expected 10 times.
Can the expected shares be percentages?
Yes: percentages, a ratio such as 9, 3, 3, 1, or expected counts all work, because they are scaled to your total. They just need to be in the same proportions as the theory.
What if some categories are rare?
Expected counts under 5 make the chi-square approximation shaky, and the page warns about them. Combine rare categories with neighbours, or collect more data.