Chi-Square
Goodness of Fit Test
Learn how to determine whether observed data matches an expected distribution using the \(\chi^2\) statistic and p-values.
What Is a Goodness of Fit Test?
A chi-square goodness of fit test asks a simple question: does the distribution of observed counts match what we expected? It compares a single categorical variable's observed frequencies against a hypothesized (expected) distribution.
Setting Up the Hypotheses
Observed vs. Expected: A Visual
The \(\chi^2\) Test Statistic
Each category contributes \(\frac{(O - E)^2}{E}\) to the total. Categories with large deviations from expected contribute more.
Degrees of Freedom
Where \(k\) is the number of categories. For example, if a die has 6 faces, \(df = 6 - 1 = 5\).
Conditions for the \(\chi^2\) Test
GOF vs. Other \(\chi^2\) Tests
| Goodness of Fit | Independence / Homogeneity | |
|---|---|---|
| Variables | One categorical variable | Two categorical variables |
| Compares | Observed vs. claimed distribution | Observed vs. independence model |
| Degrees of Freedom | \(k - 1\) | \((r - 1)(c - 1)\) |
| Data Layout | One-way table | Two-way table |
| Example | Is this die fair? | Is gender related to preference? |
The \(\chi^2\) Distribution
How to Carry Out the Test
Example 1: Fair Die?
A student rolls a die 60 times and records the results. She wants to test whether the die is fair at \(\alpha = 0.05\).
| Face | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Observed | 8 | 12 | 14 | 7 | 9 | 10 |
| Expected | 10 | 10 | 10 | 10 | 10 | 10 |
Example 1: Computation
Example 2: Candy Colors
A candy company claims its bags contain colors in these proportions: Red 30%, Blue 25%, Green 20%, Yellow 15%, Orange 10%. A student samples 200 candies.
| Color | Red | Blue | Green | Yellow | Orange |
|---|---|---|---|---|---|
| Observed (\(O\)) | 75 | 42 | 30 | 38 | 15 |
| Expected (\(E\)) | 60 | 50 | 40 | 30 | 20 |
Example 2: Solution
Common Mistakes
Summary Checklist
Worked Example: M&M Color Distribution
A statistics student suspects that the color distribution of M&M's in a large bag does not match the company's published percentages. The company claims the following distribution: 24% blue, 20% orange, 16% green, 14% yellow, 13% red, and 13% brown. The student takes a random sample of 200 M&M's and records the following observed counts: Blue = 53, Orange = 38, Green = 35, Yellow = 27, Red = 22, Brown = 25. Carry out a chi-square goodness-of-fit test at the α = 0.05 significance level. (Assume the hypotheses have been stated and conditions verified.) Chi-Square Goodness-of-Fit Test: M&M Color Distribution Step 1 — Compute Expected Counts Multiply the total sample size n = 200 by each hypothesized proportion: E(Blue) = 200 × 0.24 = 48, E(Orange) = 200 × 0.20 = 40, E(Green) = 200 × 0.16 = 32, E(Yellow) = 200 × 0.14 = 28, E(Red) = 200 × 0.13 = 26, E(Brown) = 200 × 0.13 = 26. Verify: 48 + 40 + 32 + 28 + 26 + 26 = 200 ✓. All expected counts are ≥ 5, confirming the conditions are met. Expected counts: 48, 40, 32, 28, 26, 26 Step 2 — Compute Each Component of χ² For each category, compute (O − E)²/E. Blue: (53 − 48)²/48 = 25/48 ≈ 0.5208. Orange: (38 − 40)²/40 = 4/40 = 0.1000. Green: (35 − 32)²/32 = 9/32 ≈ 0.2813. Yellow: (27 − 28)²/28 = 1/28 ≈ 0.0357. Red: (22 − 26)²/26 = 16/26 ≈ 0.6154. Brown: (25 − 26)²/26 = 1/26 ≈ 0.0385. Components: 0.521, 0.100, 0.281, 0.036, 0.615, 0.038 Step 3 — Sum to Get the Test Statistic χ² = 0.5208 + 0.1000 + 0.2813 + 0.0357 + 0.6154 + 0.0385 = 1.5917. Rounding appropriately, χ² ≈ 1.592. χ² = 1.592 Step 4 — Determine Degrees of Freedom and P-Value There are k = 6 categories, so df = 6 − 1 = 5. Using a TI-84 calculator: χ²cdf(1.592, 1E99, 5) ≈ 0.902. Alternatively, looking at a chi-square table, the critical value for α = 0.05 with df = 5 is 11.07; since 1.592 is far below 11.07, the p-value is clearly much larger than 0.05. p-value ≈ 0.902, df = 5 Step 5 — State the Conclusion in Context Because the p-value (0.902) is greater than α = 0.05, we fail to reject H₀. There is not convincing evidence that the distribution of M&M colors in this bag differs from the company's published color distribution. The observed deviations from the claimed percentages are small enough to be plausibly attributed to random sampling variability. Fail to reject H₀. No convincing evidence of a difference. Five-category, 150-candy illustration. This does not replace the separate six-category, 200-candy worked example.

Question 1 of 5
A researcher claims that four types of cereal are equally popular. She surveys 120 people. What are the expected counts for each cereal type under \(H_0\)?
Question 2 of 5
A chi-square goodness of fit test has 6 categories. What are the degrees of freedom?
Question 3 of 5
In a \(\chi^2\) GOF test, the Large Counts condition requires:
Question 4 of 5
A \(\chi^2\) GOF test yields \(\chi^2 = 15.3\) with \(df = 3\). The p-value is 0.0016. At \(\alpha = 0.05\), what is the correct conclusion?
Question 5 of 5
A single category in a GOF test has \(O = 18\) and \(E = 12\). What is this category's contribution to the \(\chi^2\) statistic?