Understanding the chi-square goodness-of-fit test — concept and principle
The chi-square goodness-of-fit test asks whether the counts you observed in several categories are consistent with a distribution you specified in advance. Examples: is a die fair, are customers spread evenly across weekdays, do genetic offspring follow a 3 : 1 ratio. Enter the observed counts and, optionally, the expected counts or proportions; leave expected blank to test for equal frequencies.
How it is calculated
- Expected values are scaled so that they add up to the observed total: E_i = (your expected value_i ÷ sum of expected values) × N. With a blank field, every E_i = N ÷ k.
- χ² = Σ (O_i − E_i)² ÷ E_i over all k categories.
- df = k − 1, because once the total is fixed only k − 1 counts are free.
- The p-value is the upper-tail probability of the chi-square distribution with k − 1 df.
Because of the scaling step you may type expected values as counts, percentages or ratios such as 3, 1.
The principle
Each term (O − E)² ÷ E measures how far one category strays from its expected count, relative to the size of that count. Under the null hypothesis the counts behave roughly like independent Poisson-type variation around E, so each standardised gap is approximately a squared standard normal value; adding them gives a chi-square variable. One degree of freedom is lost because the counts must sum to N. If you estimated parameters of the expected distribution from the same data, subtract one more df for each parameter; this calculator does not do that automatically.
Worked example
- Observed: 18, 22, 20, 25, 15, so N = 100 and k = 5.
- Expected is blank, so each E = 100 ÷ 5 = 20.
- Squared gaps: 4, 4, 0, 25, 25, total 58.
- χ² = 58 ÷ 20 = 2.9.
- df = 5 − 1 = 4.
- Upper tail of χ² with 4 df beyond 2.9: p ≈ 0.5747.
How to read the result
A large p-value, as here, means the deviations are well within what chance alone produces, so there is no evidence against the equal-frequency model. It does not prove the model is true. A p-value below your significance level (often 0.05) suggests the data do not fit. For reference, the 5% critical value is 3.84 for 1 df, 5.99 for 2 df and 9.49 for 4 df. Compare the individual (O − E)² ÷ E terms to see where a misfit comes from.
Common mistakes
- Entering percentages as observed values; observed must be raw counts.
- Using the test with tiny expected counts.
- Combining categories after looking at the data to obtain a desired result.
Frequently asked questions
Can I test unequal expected proportions?
Yes. Type them in the expected field in the same category order, for example 3, 1 for a 3 : 1 ratio; they are rescaled to your total.
Why does a bigger sample make small differences significant?
χ² grows roughly in proportion to N for the same percentage gaps, so with very large samples even trivial deviations give small p-values.
Sources: Pearson, K. (1900). Philosophical Magazine, 50(302), 157–175. · Agresti, A. An Introduction to Categorical Data Analysis (Wiley).