The Chi-Squared Goodness of Fit Test

Do the counts match the model you claimed?

Counts against a claim

A die is rolled 60 times, and the number of times each face comes up is counted. Faces 1 to 6 come up 8, 13, 9, 12, 7 and 11 times.

The claim being tested is H₀: the die is fair, so every face has probability 1/6. The alternative is H₁: the die is not fair. A goodness of fit test asks whether the counts fit the model that H₀ describes.

02468101212345610.0

The observed count for each face. The dashed line across the bars is at 10, the count a fair die expects for every face.

What the claim predicts

If the die is fair, each face is expected 60 × 1/6 = 10 times. The expected frequencies are 10, 10, 10, 10, 10 and 10, and like the observed ones they add up to 60.

Even a fair die almost never gives exactly 10 of each in 60 rolls. The test asks whether the counts are further from 10 than chance would usually make them.

The same statistic

The statistic is the one used for a two-way table: χ² = Σ (O − E)²/E, added over every category. The gaps O − E are 8 − 10 = −2, 13 − 10 = 3, −1, 2, −3 and 1. They add up to 0.

Their squares are 4, 9, 1, 4, 9 and 1, which total 28. Every expected count is 10, so χ² = 28 ÷ 10 = 2.8.

Degrees of freedom

The six counts must add up to 60. Once five of them are known, the sixth is fixed: if faces 1 to 5 came up 8, 13, 9, 12 and 7 times, face 6 must have come up 60 − 49 = 11 times. So 5 counts are free, and there are 6 − 1 = 5 degrees of freedom.

For a goodness of fit test, the degrees of freedom are the number of categories minus one. One more is lost for each number in the model that is estimated from the data, such as a mean worked out from the same counts. Here the model, 1/6 for each face, was given in full, so nothing is estimated.

χ²2.811.07

The gold curve is the chi-squared distribution with 5 degrees of freedom, highest at 3. The shaded tail from 11.07 holds 5 percent of the area. The observed total, 2.8, is far to the left of it.

The verdict

With 5 degrees of freedom, P(χ² ≥ 11.07) = 0.05, so the critical region at the 5 percent level is χ² ≥ 11.07.

2.8 < 11.07, so do not reject H₀. The p-value is P(χ² ≥ 2.8) = 0.731: a fair die gives counts at least this uneven about 73 times in 100. Stated about the die: there is no evidence that it is unfair.

That does not prove the die fair. A slight bias could be there, too small for 60 rolls to show.

A model that is not uniform

The claimed probabilities need not be equal. A spinner is claimed to land on red with probability 1/2 and on blue and green with probability 1/4 each. In 80 spins it lands on red 32 times, blue 28 times and green 20 times.

The expected counts are 80 × 1/2 = 40, 80 × 1/4 = 20 and 20. The gaps are −8, 8 and 0, so χ² = 64/40 + 64/20 + 0/20 = 1.6 + 3.2 + 0 = 4.8.

There are 3 − 1 = 2 degrees of freedom, and the 5 percent critical value is 5.991. 4.8 < 5.991, so do not reject H₀: there is no evidence at the 5 percent level against the claimed probabilities. The p-value is P(χ² ≥ 4.8) = 0.0907.

Expected counts of at least 5

As for a two-way table, every expected count should be at least 5. When a category expects fewer, it is combined with a neighboring one before χ² is worked out, and the degrees of freedom are counted from the categories that remain.

The usual mistakes

Expecting the wrong count. A fair die rolled 60 times expects 60 ÷ 6 = 10 of each face, not 60 and not 6.

Using 6 degrees of freedom. The total of 60 fixes the last count, so there are 5.

Taking a parameter as lost when none was estimated. With the model given in full, the degrees of freedom are the categories minus one.

Saying the die is certainly fair. Not rejecting H₀ leaves the claim standing; it does not prove it.

A games club’s suspect die

In the application below, a die is thrown 120 times. A fair die expects 20 of each score, and the same six gaps, squares and degrees of freedom decide whether the club has evidence against it.

Worked example: A Games Club's Suspect Die Thrown 120 Times and Tested for Fairness

Question A games club suspects that one of its dice is not fair. It is thrown 120 times, and the scores 1 to 6 come up 14, 22, 18, 26, 17 and 23 times. (a) Find the expected frequencies if the die is fair, and the value of χ2. (b) Test at the 5% level whether the die is fair, and state the conclusion in context.

  1. 1.H0: the die is fair, so each score has probability 16. H1: the die is not fair. The expected frequency of each score is 120 × 16 = 20.

    141222183264175236fair die: 20 of each scoreE = 120 × 1/6 = 20 for each score
    141222183264175236fair die: 20 of each scoreE = 120 × 1/6 = 20 for each score
    The bars are the observed frequencies; the dashed line is the expected frequency of 20 for a fair die.
  2. 2.The differences O − E are −6, 2, −2, 6, −3 and 3, which add up to 0 as they must. Their squares are 36, 4, 4, 36, 9 and 9, a total of 98.

    14−6122+2218−2326+6417−3523+36fair die: 20 of each scoreO − E: −6, 2, −2, 6, −3, 3squares: 36 + 4 + 4 + 36 + 9 + 9 = 98
    14−6122+2218−2326+6417−3523+36fair die: 20 of each scoreO − E: −6, 2, −2, 6, −3, 3squares: 36 + 4 + 4 + 36 + 9 + 9 = 98
    Each bar's distance from the line is O − E; the distances add up to 0 and their squares to 98.
  3. 3.(a) Every expected frequency is 20, so χ2 = 9820 = 4.9.

    14−6122+2218−2326+6417−3523+36fair die: 20 of each scorechi-sq = 98/20 = 4.9
    14−6122+2218−2326+6417−3523+36fair die: 20 of each scorechi-sq = 98/20 = 4.9
    (a) All six expected frequencies are 20, so χ2 = 9820 = 4.9.
  4. 4.There are 6 classes and one constraint, that the frequencies add up to 120, so there are 6 − 1 = 5 degrees of freedom. The critical value of χ2(5) at the 5% level is 11.070.

    11.0700chi-sq = 4.9chi-sq(5) if H0 is true6 − 1 = 5 degrees of freedomchi-sq(5) at 5%: 11.070
    11.0700chi-sq = 4.9chi-sq(5) if H0 is true6 − 1 = 5 degrees of freedomchi-sq(5) at 5%: 11.070
    Six classes and one constraint leave 5 degrees of freedom; 5% of χ2(5) lies beyond 11.070.
  5. 5.(b) 4.9 < 11.070, so do not reject H0. There is not enough evidence at the 5% level that the die is unfair: differences as large as these often happen with a fair die in 120 throws. Had the statistic been above 11.070, the club would have had evidence that the die is biased.

    11.0700chi-sq = 4.9chi-sq(5) if H0 is true4.9 < 11.070: do not reject H0no clear evidence the die is unfair
    11.0700chi-sq = 4.9chi-sq(5) if H0 is true4.9 < 11.070: do not reject H0no clear evidence the die is unfair
    (b) 4.9 is well outside the critical region, so do not reject H0: there is not enough evidence that the die is unfair.

Answer: (a) each expected frequency is 20, and χ2 = 4.9; (b) 4.9 < 11.070 on 5 degrees of freedom, so do not reject H0: there is not enough evidence that the die is unfair

Common mistakes

  • Using 6 degrees of freedom, one for each score. The six expected frequencies must add up to 120, which fixes the last one, so there are 5.
  • Concluding that the test has proved the die is fair. Not rejecting H0 only means that 120 throws give no clear evidence against fairness; a small bias could still be there.

More statistical inference problems, worked step by step →

Practice The Chi-Squared Goodness of Fit Test in the app