Skip to main content
Examonaut

Topic 6 · Lesson 1 of 3

Goodness of fit tests

The test statistic

For each class (cell), compare the observed frequency OO with the expected frequency EE predicted by the model. The statistic

X2=∑(O−E)2EX^2 = \sum\frac{(O - E)^2}{E}

is zero when the data match the model exactly and grows as they disagree. Dividing by EE scales each difference: being 5 out when you expected 10 matters more than being 5 out when you expected 100. A useful equivalent form for calculation is ∑O2E−N\sum\frac{O^2}{E} - N, where NN is the total frequency.

If the model is right, X2X^2 approximately follows a χ2\chi^2 distribution with ν\nu degrees of freedom. The χν2\chi^2_\nu distributions are skewed to the right, with mean ν\nu; the critical value χν2(α)\chi^2_\nu(\alpha) is the value exceeded with probability α\alpha. For example χ32(0.05)=7.815\chi^2_3(0.05) = 7.815 and χ42(0.05)=9.488\chi^2_4(0.05) = 9.488. The test is always one-tailed: only large values of X2X^2 are evidence against the model.

Degrees of freedom

ν=number of classes (after combining)−1−number of parameters estimated from the data\nu = \text{number of classes (after combining)} - 1 - \text{number of parameters estimated from the data}

The −1-1 is because the expected frequencies are made to add up to the observed total. Each parameter you estimate from the data (such as λ\lambda for a Poisson model, or pp for a binomial or geometric one) makes the model fit more closely and costs another degree of freedom. If the parameter is given in the question, nothing extra is subtracted.

Small expected frequencies

The χ2\chi^2 approximation is poor when expected frequencies are small. Combine any class with E<5E < 5 with a neighbouring class (usually the tail classes), add their observed frequencies too, and count the classes after combining.

The steps

  1. H0H_0: the model fits (name it, with parameters if given); H1H_1: it does not.
  2. If needed, estimate the parameter from the data.
  3. Find the expected frequencies: total ×\times probability. Make the last class "xx or more" so the expected frequencies add up to the total.
  4. Combine classes with E<5E < 5.
  5. Calculate X2X^2, find ν\nu and the critical value.
  6. If X2>X^2 > critical value, reject H0H_0; conclude in context.

Worked example

A fair dice

A dice is rolled 120 times, giving 14, 25, 19, 23, 17, 22 for the scores 1 to 6. If it is fair, every expected frequency is 20.

Show solution
X2=36+25+1+9+9+420=4.2X^2 = \frac{36 + 25 + 1 + 9 + 9 + 4}{20} = 4.2

There are 6 classes and no parameters estimated, so ν=5\nu = 5 and χ52(0.05)=11.070\chi^2_5(0.05) = 11.070. Since 4.2<11.0704.2 < 11.070, there is no evidence at the 5% level that the dice is unfair.

The same method tests any given ratio: a theory predicting the ratio 1:2:11 : 2 : 1 for 200 offspring gives expected frequencies 50, 100, 50.

Worked example

A Poisson model with estimated mean

The numbers of typing errors on 100 pages were 0 errors: 27 pages, 1: 43, 2: 19, 3: 6, 4: 4, 5: 1.

Show solution
  1. Mean =43+38+18+16+5100=1.2= \frac{43 + 38 + 18 + 16 + 5}{100} = 1.2, so try Po(1.2)\text{Po}(1.2).
  2. Expected frequencies: 100×0.3012=30.12100 \times 0.3012 = 30.12, 36.1436.14, 21.6921.69, and "3 or more" =100−30.12−36.14−21.69=12.05= 100 - 30.12 - 36.14 - 21.69 = 12.05. (Separately, 3 errors would be 8.67 and "4 or more" 3.38, which is below 5, so these are combined.)
Errors0123 or moreObserved27431911Expected30.1236.1421.6912.05
  1. X2=(27−30.12)230.12+(43−36.14)236.14+(19−21.69)221.69+(11−12.05)212.05=2.05X^2 = \frac{(27 - 30.12)^2}{30.12} + \frac{(43 - 36.14)^2}{36.14} + \frac{(19 - 21.69)^2}{21.69} + \frac{(11 - 12.05)^2}{12.05} = 2.05
  2. 4 classes, 1 parameter estimated: ν=4−1−1=2\nu = 4 - 1 - 1 = 2, and χ22(0.05)=5.991\chi^2_2(0.05) = 5.991.
  3. 2.05<5.9912.05 < 5.991: do not reject H0H_0. A Poisson distribution is a suitable model.

Other models

  • Binomial B(n,p)\text{B}(n, p): if pp is not given, estimate it by p^=xˉn\hat{p} = \frac{\bar{x}}{n}, and lose one degree of freedom.
  • Geometric Geo(p)\text{Geo}(p): estimate pp by 1xˉ\frac{1}{\bar{x}} if needed; the last class is "kk or more", with expected frequency N(1−p)k−1N(1 - p)^{k - 1}.
  • Continuous uniform on [a,b][a, b] with grouped data: the expected frequency of each group is proportional to its width. For 120 arrival times in a 60-minute period, grouped as 0–10, 10–30 and 30–60 minutes, the expected frequencies are 20, 40 and 60.

Try it: choose the χ² test mode, fit a model to data and carry out the goodness of fit test step by step.

Try it: simulation

Poisson, geometric and χ² tests

Loading the simulation…

Practise this topic

Both are part of Premium.