Mathwords logoMathwords

Goodness-of-Fit — Definition, Formula & Example

Goodness-of-fit describes how closely the counts you actually observe match the counts a model predicts. In AP Statistics, the chi-square goodness-of-fit test checks whether one categorical variable follows a claimed distribution.

The chi-square goodness-of-fit test evaluates H0H_0: the population proportions equal specified values p1,p2,…,pkp_1, p_2, \dots, p_k, against HaH_a: at least one pip_i differs. The test statistic χ2=∑(O−E)2E\chi^2 = \sum \frac{(O-E)^2}{E} has an approximate chi-square distribution with k−1k-1 degrees of freedom when H0H_0 is true. The approximation requires a random sample and all expected counts Ei=npi≥5E_i = np_i \ge 5. The tests for homogeneity and independence use the same statistic with two-way tables.

Key Formula

χ2=∑i=1k(Oi−Ei)2Ei,Ei=npi,df=k−1\chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}, \qquad E_i = n p_i, \qquad df = k - 1
Where:
  • OiO_i = observed count in category i
  • EiE_i = expected count in category i if the null hypothesis is true
  • nn = total sample size
  • pip_i = hypothesized proportion for category i
  • kk = number of categories

Worked Example

Problem: A spinner has 4 equal sections: A, B, C, D. You spin it 100 times and get A = 30, B = 20, C = 28, D = 22. At the α=0.05\alpha = 0.05 level, is there convincing evidence that the spinner is unfair?
Step 1: State the hypotheses. H0H_0: each section has probability 14\tfrac{1}{4}. HaH_a: at least one probability differs from 14\tfrac{1}{4}. Under H0H_0, each expected count is 25, which is at least 5, so the condition holds.
Ei=100⋅14=25E_i = 100 \cdot \tfrac{1}{4} = 25
Step 2: Compute each category's contribution and add them.
χ2=(30−25)225+(20−25)225+(28−25)225+(22−25)225=1+1+0.36+0.36=2.72\chi^2 = \frac{(30-25)^2}{25} + \frac{(20-25)^2}{25} + \frac{(28-25)^2}{25} + \frac{(22-25)^2}{25} = 1 + 1 + 0.36 + 0.36 = 2.72
Step 3: Use df=4−1=3df = 4 - 1 = 3. The P-value is the area to the right of 2.72 under the chi-square curve with 3 degrees of freedom.
P(χ32≥2.72)≈0.44P(\chi^2_3 \ge 2.72) \approx 0.44
Answer: Because the P-value of about 0.44 is greater than 0.05, you fail to reject H0H_0. There is not convincing evidence that the spinner is unfair.

Why It Matters

Goodness-of-fit tests appear on the AP Statistics exam in the inference unit on categorical data. Geneticists use them to check whether offspring ratios match Mendelian predictions such as 9:3:3:1. Auditors use them to test whether reported digits follow Benford's law.

Common Mistakes

Mistake: Using n−1n - 1 (sample size minus 1) for the degrees of freedom.
Correction: For goodness-of-fit, use df=k−1df = k - 1, where kk is the number of categories. In the spinner example, df=3df = 3, not 99.

Related Terms