Chi-square goodness-of-fit test
Is a die fair? Do customers choose the four menus equally often? Do your genotype counts match 1 : 2 : 1? Enter the observed counts and, if they are not all equal, the expected counts or proportions to get Pearson's χ² statistic, the p-value and the contribution of each category.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Enter the observed count of each category, for example
18, 22, 16, 25, 12, 27 for 120 rolls of a die.
- Leave the expected box empty for equal chances, or enter the expected counts or proportions in the same order.
- Read χ², the p-value and the decision; the table shows which categories contribute most.
How it works
The expected values are scaled to the observed total n: Eᵢ = n · eᵢ / Σe. Then
χ² = Σ (Oᵢ − Eᵢ)²/Eᵢ, df = k − 1 − m
with k categories and m estimated parameters. The p-value is P(χ²_df ≥ χ²), the upper tail of the chi-square distribution, and the critical value is the χ² that leaves α in that tail.
Worked example
A die rolled 120 times shows 18, 22, 16, 25, 12 and 27. If it is fair, each face is expected 20 times. The contributions are 0.2, 0.2, 0.8, 1.25, 3.2 and 2.45, so χ² = 8.1 with df = 5. The p-value is 0.1508, above 0.05 (the critical value is 11.0705), so the data give no evidence that the die is unfair. The effect size w is 0.259808.
Tips and common mistakes
- Use counts, not percentages, for the observed values: the test depends on the sample size.
- Every observation must fall into exactly one category, and observations must be independent.
- Expected counts below 5 make the p-value unreliable; combine neighbouring categories if you can.
Frequently asked questions
What is the formula of the chi-square goodness-of-fit test?
χ² = Σ (O − E)²/E over all categories, where O is the observed and E the expected count. Under the null hypothesis it follows a chi-square distribution with k − 1 degrees of freedom (k categories), minus one more for each parameter estimated from the data.
Can I enter percentages as the expected values?
Yes. The expected values are rescaled so they add up to the observed total, so 25, 50, 25 and 0.25, 0.5, 0.25 and 1, 2, 1 all mean the same thing.
What does a significant result mean?
That counts this far from the expected ones would be unlikely if the expected distribution were true. Look at the category contributions to see where the misfit comes from.
How is it different from the chi-square test of independence?
The goodness-of-fit test compares one categorical variable with a given distribution. The test of independence compares two variables in a contingency table; use the chi-square calculator for that.