Chi-Square Goodness of Fit

The Chi-Square Goodness of Fit test is a statistical procedure that lets you determine whether a set of observed data matches a proposed theoretical distribution. In everyday language, it answers the question: 'Does what we see in our sample fit what we would expect if a particular model were true?' For example, a candy company claims that 20% of its candies are red, 20% blue, 20% green, 20% yellow, and 20% orange. You buy a bag and count the colors — the goodness of fit test tells you whether any differences between your counts and the claimed proportions are due to random chance or evidence of a real discrepancy. The test works by computing a single number called the chi-square statistic, written χ², which measures the total discrepancy between observed counts and expected counts across all categories. The larger the χ² value, the more the data deviates from the expected model. By comparing this statistic to a chi-square distribution with the appropriate degrees of freedom, you calculate a p-value that guides your decision about whether to reject the null hypothesis. Chi-Square Goodness of Fit is widely used in genetics, quality control, survey analysis, and any field where categorical data must be compared against a theoretical model. It is one of the most important non-parametric tests in statistics, meaning it does not require assumptions about population means or standard deviations — only that you have counts of items falling into distinct categories.

Key takeaways
  • State the Hypotheses
  • Check Conditions
  • Calculate Expected Counts
  • Compute the Chi-Square Statistic
  • Find the P-Value and Degrees of Freedom
  • Make a Conclusion

State the Hypotheses

The null hypothesis H₀ states that the population proportions match the claimed distribution (e.g., each color has exactly 20%). The alternative hypothesis Hₐ states that at least one proportion differs from the claimed value. This is always a one-tailed test in the sense that the chi-square statistic only measures deviation in one direction — away from perfect fit.

Check Conditions

Three conditions must be met before proceeding. (1) Random sample: the data must come from a random sample or randomized experiment. (2) Independence: if sampling without replacement, the sample size n must be no more than 10% of the population. (3) Large counts: every expected count must be at least 5. The expected count for category i is Eᵢ = n · pᵢ, where n is the total sample size and pᵢ is the claimed proportion for that category.

Calculate Expected Counts

For each category, compute the expected count: Eᵢ = n · pᵢ. For instance, if n = 200 and you claim 30% should fall in a category, then E = 200 × 0.30 = 60. Expected counts do not need to be whole numbers — they represent theoretical averages, not actual counts.

Compute the Chi-Square Statistic

The test statistic is χ² = Σ [(Oᵢ − Eᵢ)² / Eᵢ], summed over all k categories, where Oᵢ is the observed count and Eᵢ is the expected count for category i. Each term measures how far off one category is from its expected value, scaled by the expected value so that categories with larger expected counts do not dominate unfairly.

Find the P-Value and Degrees of Freedom

The degrees of freedom for a goodness of fit test is df = k − 1, where k is the number of categories. Using a chi-square distribution table or calculator, find the p-value: the probability of getting a χ² statistic at least as large as yours if H₀ were true. A small p-value (typically p < 0.05) provides evidence against H₀.

Make a Conclusion

If p < α (the significance level, usually 0.05), reject H₀ and conclude that the data do not fit the proposed distribution. If p ≥ α, fail to reject H₀ — you do not have sufficient evidence to say the distribution is wrong. Always state your conclusion in context: 'We reject H₀ and conclude that the distribution of candy colors is not as claimed.'

The Key Equation

χ2=∑i=1k(Oi−Ei)2Ei\chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}
  • \chi^2 — Chi-square statistic (dimensionless): The test statistic that measures total deviation of observed counts from expected counts.
  • O_i — Observed count (count): The actual number of data values falling in category i, collected from the sample.
  • E_i — Expected count (count): The theoretical number of data values expected in category i, calculated as n · pᵢ.
  • k — Number of categories (dimensionless): The total number of distinct categories in the distribution being tested.

Worked Example

Problem. A die manufacturer claims their six-sided die is fair. A statistician rolls it 120 times and records: 1→18, 2→25, 3→17, 4→22, 5→14, 6→24. At α = 0.05, test whether the die is fair.

χ2=4.70,  df=5,  p≈0.45>0.05⇒Fail to reject H0\chi^2 = 4.70,\; df = 5,\; p \approx 0.45 > 0.05 \Rightarrow \text{Fail to reject } H_0

Answer. Fail to reject H₀; the data are consistent with a fair die (χ² = 4.70, df = 5, p ≈ 0.45).

Figure
Diagram
Chi-Square Distribution (df = 5)χ² valueDensity11.07α=0.054.70χ²=4.70χ² distribution, df=5Rejection region (α=0.05)03691215
Origins · 1 minKarl Pearson and how this was discovered
KP
Karl Pearson
1857–1936 · British

Karl Pearson introduced the chi-square goodness of fit test in his landmark 1900 paper 'On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling.' He developed the mathematical framework connecting the χ² statistic to the chi-square distribution, making it possible to calculate p-values and draw formal statistical conclusions. This was one of the first modern hypothesis tests ever devised. Pearson was so passionate about statistics that he founded the world's first university statistics department at University College London in 1911 and launched the influential journal Biometrika, which he edited for over 35 years.

  • Chi-Square Test for Independence — Both tests use the same χ² = Σ(O−E)²/E statistic, but the test for independence applies to two-way tables to determine whether two categorical variables are related.
  • Hypothesis Testing — Goodness of fit is a specific application of hypothesis testing; understanding null and alternative hypotheses, p-values, and significance levels is essential before learning the chi-square test.
  • P-Values and Statistical Significance — The chi-square test produces a p-value which is the basis for the final conclusion; understanding how to interpret p-values is a prerequisite skill.
  • Categorical Data and Proportions — Chi-square goodness of fit is specifically designed for categorical data; knowing how to summarize and visualize counts and proportions provides critical context.