Chi-squared goodness of fit tests

Chi-squared goodness of fit tests

Spec 4.1–2 · Edexcel International A Level Further Maths: Revision notes

Studying this course? Keep your progress in one place.

Key facts

  • H0H_0: the model fits. H1H_1: it does not. The test is always one-tailed.
  • X2=∑(Oi−Ei)2EiX^2=\sum\frac{(O_i-E_i)^2}{E_i}; reject H0H_0 only if it exceeds the critical value.
  • Every expected frequency must be at least 55: combine cells otherwise.
  • ν=k−1−m\nu=k-1-m, with kk cells after combining and mm parameters estimated.

The hypotheses

Whether the data could reasonably come from the stated model.

A goodness of fit test asks whether observed data could reasonably have come from a stated model, such as a uniform, binomial, Poisson or Normal distribution.

H0H_0 says the model fits; H1H_1 says it does not. The test is always one-tailed: only a large test statistic is evidence against the model. Write the hypotheses about the whole distribution, not a single parameter.

H0H_0

  • The model fits the data
  • "The breakdowns follow a Poisson distribution"

H1H_1

  • The model does not fit
  • About the whole distribution

The hypotheses for a goodness of fit test are about:

The test statistic

Compare each observed frequency with the expected frequency from the model.

For each cell, compare the observed frequency OiO_i with the expected frequency EiE_i given by the model. If H0H_0 is true, X2X^2 is approximately χ2\chi^2 distributed. A small value means the data are close to the model.

Under the model Ei=n×P(cell i)E_i=n\times P(\text{cell }i), and the expected frequencies must add to the total nn. Yates' correction is not required.

  • Test statisticX2=∑(Oi−Ei)2EiX^2=\sum\dfrac{(O_i-E_i)^2}{E_i}
0510152025123456FaceFrequency
  • Observed
  • Expected
Observed and expected frequencies for 120 throws of a die.

Worked example

A die is thrown 120 times, giving 14, 25, 17, 22, 24, 18. Test whether it is fair at 5%5\%.

Observed 12 and expected 10 in a cell. What does that cell add to X2X^2?

Expected frequencies

Multiply the total by the model's probability for each cell.

Discrete uniform (fair die): Ei=n6E_i=\frac n6. Continuous uniform on [a,b][a,b]: a class of width ww has probability wb−a\frac{w}{b-a}. Binomial or Poisson: Ei=N×P(X=i)E_i=N\times P(X=i), estimating pp or λ\lambda from the sample mean if not given; make the last cell "rr or more". Normal: standardise class boundaries, with end classes extending to ±∞\pm\infty.

Discrete uniform

  • Ei=n6E_i=\frac{n}{6} for a die

Continuous uniform

  • Class probability wb−a\frac{w}{b-a}

Binomial or Poisson

  • Ei=N×P(X=i)E_i=N\times P(X=i)
  • Estimate p or λ if not given

Normal

  • Standardise class boundaries
  • End classes go to ±∞

Waiting times are uniform on 0 to 20 minutes. What is the probability for a class of width 5?

Combining cells

If any expected frequency is below 55, combine it with a neighbour.

The χ2\chi^2 approximation is only reliable if every expected frequency is at least 5. If any Ei<5E_i<5, combine it with a neighbouring cell, adding both the expected and the observed frequencies, and repeat until every Ei≥5E_i\ge5.

For a Poisson model the small cells are usually in the tail, so combine into "rr or more". The number of cells kk in the degrees of freedom is the number after combining.

  • Every expected frequencyat least 5

Expected frequencies are 3.45 and 1.17 for two adjacent cells. What next?

Degrees of freedom

ν=k−1−m\nu=k-1-m: one is lost for the fixed total, and one for each parameter estimated.

ν=k−1−m\nu=k-1-m, where kk is the number of cells after combining and mm is the number of parameters estimated from the data. One degree of freedom is lost because the total of the expected frequencies is fixed.

Write ν=k−1−m\nu=k-1-m with the actual numbers; method marks are given for showing what kk and mm were. These are the degrees of freedom.

  • No parameters estimatedν=k−1\nu=k-1
  • p or λ estimatedν=k−2\nu=k-2
  • Normal μ and σ² estimatedν=k−3\nu=k-3

Poisson fit with λ\lambda estimated from the data, 6 cells after combining. Degrees of freedom?

Carrying out the test

Find expected frequencies, combine, calculate X2X^2, and compare with the critical value.

Reject H0H_0 if X2X^2 is greater than the critical value; otherwise there is insufficient evidence to reject it. Conclude in context.

For the die: E=20E=20, X2=9420=4.7X^2=\frac{94}{20}=4.7, ν=5\nu=5, and the 5%5\% critical value is 11.07011.070. Since 4.7<11.074.7<11.07 there is no evidence the die is unfair. The same statistic is used for contingency tables.

  1. 1

    State H₀ and H₁

    About the model

  2. 2

    Expected frequencies

    Combine where E is below 5

  3. 3

    Calculate X²

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

  4. 4

    Find ν and the critical value

    From the tables

  5. 5

    Conclude

    In context

A chi-squared test

When do you reject H0H_0 in a goodness of fit test?

Try an exam question

A four-sector spinner is spun 8080 times, giving 1515, 2525, 2222 and 1818 for the four sectors. Test, at the 5%5\% level, whether the spinner is fair. The critical value of χ32\chi^2_3 at 5%5\% is 7.8157.815.

[5 marks]

That's the notes covered.

Carry on to the next subtopic.

Try a question

Find the expected frequency for each face if the die is fair.

1 mark, marked against the mark scheme

Revision notes