Goodness of fit tests and contingency tables
Studying this course? Keep your progress in one place.
Key facts
- : the model fits (or the variables are independent). The test statistic is , approximately , and the test is always upper-tailed.
- Every expected frequency must be at least : combine neighbouring cells otherwise, adding both and .
- , counting cells after combining.
- Contingency tables: and .
- Reject if the critical value, and conclude in context.
Hypotheses and test statistic
says the model fits; the statistic is large when the data are far from it.
A goodness of fit test checks whether observed frequencies are consistent with a proposed model.
State the hypotheses in words: the model fits (for example the die is fair, or the data follow ); the model does not fit. They must be about the model or population, not the sample.
are the observed frequencies and the expected frequencies if is true. is approximately ; a large value means the data are far from the model, so the test is always upper-tailed.
- Observed
- Expected
- Test statistic
Observed 18, expected 15 in a cell. What does this cell contribute to ?
Expected frequencies and combining
Each is the total times the model probability; combine neighbouring cells until every .
Find each as total probability: for a discrete uniform model with outcomes; from or .
For a Poisson model the last cell is " or more", so the probabilities sum to 1.
The approximation is only reliable if every . If not, combine cells with a neighbour, adding both and , and count the combined cell as one. Combining only the observed or only the expected frequencies is a common mistake.
- 1
Find E
total × model probability for each cell
- 2
Check
is every E at least 5?
- 3
Combine
merge with a neighbour, adding O and E
- 4
Count
the merged cell counts as one
Worked example
The expected frequencies are . Combine cells so that every .
- 1
The last two cells ( and ) are below , and even together they total only .
- 2
Combine them with the cell before: .
- 3
Add the observed frequencies of the same three cells in the same way, and count the combined cell as one cell.
Expected frequencies are . How many cells remain after combining so that every ?
Degrees of freedom
Count the cells after combining, subtract 1, and subtract one more for each parameter estimated from the data.
The degrees of freedom are . The "" is because the total is fixed.
If a parameter is given in the question (a fair die, , ) nothing more is subtracted. If it is estimated from the sample, subtract one for each estimate: for a binomial, for a Poisson.
Always count the cells after combining, not before.
- 1
Count the cells
After combining any cells with a small expected frequency
- 2
Subtract 1
The total is fixed
- 3
Subtract estimated parameters
One for each parameter estimated from the data; none if given
- 4
Result
This is ν
- Degrees of freedom cells − 1 − estimated
| Fair die | B(4, p), p estimated | |
|---|---|---|
| Cells | 6 | 3 |
| Estimated parameters | 0 | 1 |
| Degrees of freedom | 5 | 1 |
Fair die
- Cells:
- 6
- Estimated parameters:
- 0
- Degrees of freedom:
- 5
B(4, p), p estimated
- Cells:
- 3
- Estimated parameters:
- 1
- Degrees of freedom:
- 1
A Poisson model with estimated from the data has 5 cells after combining. What is ?
Uniform, binomial and Poisson models
Only the expected frequencies and the degrees of freedom change.
The method is the same for each model. Only the expected frequencies and the degrees of freedom change.
When a last cell like "4 or more" is used, you need the total of the observations in that cell to find .
For a discrete uniform model nothing is estimated. For a binomial model, may be given or estimated from the sample mean. For a Poisson model, is estimated by unless given.
| Discrete uniform | Binomial, p given | Binomial, p estimated | Poisson, λ estimated | |
|---|---|---|---|---|
| Expected frequency | use | use | ||
| Degrees of freedom | k − 1 | cells − 1 | cells − 2 | cells − 2 |
Discrete uniform
- Expected frequency:
- Degrees of freedom:
- k − 1
Binomial, p given
- Expected frequency:
- Degrees of freedom:
- cells − 1
Binomial, p estimated
- Expected frequency:
- use
- Degrees of freedom:
- cells − 2
Poisson, λ estimated
- Expected frequency:
- use
- Degrees of freedom:
- cells − 2
A model has estimated from the sample mean and cells. What is ?
Contingency tables
Find each expected frequency from the totals, and use .
A contingency table classifies each observation by two variables. The test asks whether they show independence.
- : there is no association between the variables.
- : there is an association.
Under , , and for rows and columns. No parameters are estimated separately. Combine cells with by merging rows or columns, and recalculate from the new table.
- Expected frequency
- Degrees of freedom
Worked example
In a table the row totals are and , the column totals are and the grand total is . Find the expected frequency for row , column , and .
- 1
.
- 2
and , so .
A contingency table has rows and columns. What is ?
Reaching a conclusion
Compare with the critical value, or the p-value with the significance level.
Compare with the critical value from the table at the given significance level. If the critical value, reject .
Alternatively, a calculator gives the p-value . Reject if it is below the significance level.
A small is not proof the model is right, only that there is no evidence against it. Always write the conclusion in context.
Worked example
A die is rolled times. Each face has and . Test at the level whether the die is fair.
- 1
: the die is fair. : the die is not fair.
- 2
There are cells and no parameters estimated, so .
- 3
The critical value is . Compare: , so do not reject .
and at the level. What is the conclusion?
Try an exam question
A die is rolled times with these frequencies for faces to : . Test, at the significance level, whether the die is fair. The critical value of at the level is .
[5 marks]
- [1]: the die is fair; : the die is not fair.
- [1]Expected frequency for each face.
- [1].
- [1], so the critical value is .
- [1], so do not reject : there is no evidence, at the level, that the die is unfair.
That's the notes covered.
Carry on to the next subtopic.
Try a question
Find the expected frequency of each face if the die is fair.
1 mark, marked against the mark scheme
Find the expected frequency of each face if the die is fair.
1 mark, marked against the mark scheme