Menu
Sign up Sign in

AI HL · 13.4

Hypothesis Testing

13.4.2

Chi-squared goodness of fit

13.4.2

Chi-squared goodness of fit

Target: I can write H0 and H1 for a goodness of fit test against given proportions or a uniform distribution. (+4 more)

By the end of this section

Key points

What the test does

  • A goodness of fit test asks whether data fit a stated model, such as a fair die or a set of proportions.
  • \(H_0\): the data fit the model (for example, the die is fair). \(H_1\): the data do not fit the model.
  • Observed frequencies O come from the data. Expected frequencies E assume \(H_0\) is true: E = probability × sample size.
  • For equal probabilities, E = sample size ÷ number of groups.
  • \(\chi^2 = \sum \frac{(O-E)^2}{E}\). The further the data are from the model, the larger \(\chi^2\) is.

Degrees of freedom and the decision

  • Degrees of freedom: df = number of groups − 1. Here no value in the model is estimated from the data.
  • Every expected frequency should be at least 5. The data in this lesson already meet this.
  • If \(p < \alpha\), reject \(H_0\). Equivalent: if \(\chi^2\) is bigger than the critical value, reject \(H_0\).
  • Otherwise there is insufficient evidence to reject \(H_0\). Do not say \(H_0\) is proved.
  • Write the conclusion in the words of the context.

Reading the result

  • Before testing, compare the observed and expected frequencies. Counts close to E suggest a good fit.
  • A very small p-value means the data are very unlikely under \(H_0\). Look for a reason in the context.
  • A p-value very close to 1 means the data fit almost perfectly. That can also be suspicious, for example made-up data.

On the calculator

The χ² goodness of fit test

  • Enter the observed frequencies in one list and the expected frequencies in another.
  • Choose the χ² goodness of fit test. Enter the degrees of freedom: groups − 1.
  • Read χ² and the p-value.
  • Compare p with the significance level, or χ² with the critical value.

Screenshot and video to come

Expected frequencies in a list

  • Put the probabilities in a list. Multiply the list by the sample size n to get the expected frequencies.
  • Check that the expected frequencies add up to n.

Screenshot and video to come

Explore: does the data fit the model?

Compare the observed counts with the counts the model expects. Drag the orange point on top of a bar, or type a count, and see what χ² and the conclusion say.

ObservedProportionExpectedAdds to χ²

Press a name in the table to see its expected count worked out. Bars are the observed counts, teal lines the expected counts.

χ² (add the contributions)
Degrees of freedom
p-value

Drag a bar to start.

  1. In "A die", the 6 is far above its expected count. Lower it a little at a time. How low must it go before H₀ is no longer rejected?
  2. In "Days of the week", the result changes between the 5% and the 10% levels. What is the p-value, and why does the level matter?
  3. Make every observed count equal to its expected count. What are χ² and the p-value? What if the counts fit almost perfectly?
  4. Why are the degrees of freedom one less than the number of groups?

Worked examples

Problems like the ones in class. Pick one, try it, then open the working.
Expected frequencies from proportions

A café says that 40% of its drinks sold are tea, 30% coffee, 20% juice and 10% water. A sample of 150 drinks is recorded. Write \(H_0\) and \(H_1\) for a goodness of fit test and find the expected frequency of coffee, assuming \(H_0\) is true.

Working
  1. Hypotheses

    \(H_0\): sales are in the proportions 40%, 30%, 20%, 10%. \(H_1\): they are not.

    H0 says the data fit the café's claim.

  2. Expected

    E = 0.4 × 150, 0.3 × 150, 0.2 × 150, 0.1 × 150 = 60, 45, 30, 15

    Probability times sample size, for each drink. Coffee: 0.30 × 150 = 45.

  3. Check

    60 + 45 + 30 + 15 = 150

    The expected frequencies add up to the sample size. All are at least 5.

Video walkthrough coming
A full test: the café

The café's sample of 150 drinks contained 52, 58, 24, 16 of tea, coffee, juice and water. Test at the 5% significance level whether the sales fit the café's proportions.

TeaCoffeeJuiceWaterObserved52582416Expected60453015
Working
  1. Hypotheses

    \(H_0\): sales fit the proportions 40%, 30%, 20%, 10%. \(H_1\): they do not.

    Always state both before the calculation.

  2. Degrees of freedom

    df = 4 − 1 = 3

    Four groups, so three degrees of freedom.

  3. Calculator

    From the calculator: χ² = 6.09, p = 0.107

    Observed list and expected list, df = 3.

  4. Compare

    p = 0.107 > 0.05

    p is larger than the significance level.

  5. Conclude

    Do not reject \(H_0\). There is insufficient evidence, at the 5% level, that the café's drink sales differ from its stated proportions.

    Say it in context. Do not write that the café's claim is proved.

Video walkthrough coming
Equal probabilities

A spinner has five equal sectors numbered 1 to 5. It is spun 200 times and lands on 1 to 5 31, 52, 38, 45 and 34 times. Find the expected frequency for each number if the spinner is fair.

Working
  1. Equal probabilities

    P(each number) = 1/5

    A fair spinner gives each number the same chance.

  2. Expected

    E = 200 ÷ 5 = 40

    The same expected frequency for every group. Check: 5 × 40 = 200.

  3. Test it

    From the calculator: χ² = 7.25, p = 0.123, df = 4

    p = 0.123 is larger than 0.05, so there is insufficient evidence that the spinner is unfair.

Video walkthrough coming
Using a critical value

A canteen offers four hot meals. The manager thinks pupils choose each meal equally often. One day 240 pupils choose 82, 44, 58 and 56 of the four meals. Test the manager's idea. The critical value of \(\chi^2\) with df = 3 at the 5% level is 7.815.

Working
  1. Hypotheses

    \(H_0\): the four meals are equally popular. \(H_1\): they are not.

    Equal popularity means probability 1/4 each.

  2. Expected and df

    E = 240 ÷ 4 = 60; df = 3

    Same expected frequency for each meal.

  3. Calculator

    From the calculator: χ² = 12.7, p = 0.00542

    Use the calculator for χ².

  4. Compare

    12.7 > 7.815

    χ² is larger than the critical value. This agrees with p being below 0.05.

  5. Conclude

    Reject \(H_0\). There is sufficient evidence, at the 5% level, that the four meals are not equally popular.

    A large χ² means the data are far from equal.

Video walkthrough coming
Does a die look fair?

A die is rolled 90 times. The bar chart shows the number of times each face came up. The dashed line is the expected frequency for a fair die. Before testing, do the results look consistent with a fair die?

12345671020FaceFrequency
Working
  1. Expected

    E = 90 ÷ 6 = 15

    This is the dashed line.

  2. Compare

    Differences from 15: −1, +2, −2, +1, 0, 0

    Every bar is within 2 of the line.

  3. Judge

    Consistent with a fair die

    No bar is far from the line. A test is unlikely to reject \(H_0\). Run it to be sure.

Video walkthrough coming
What a very small p-value says

A hospital records the 700 births in one town over 7 days of the week, from Monday to Sunday. If births were equally likely on every day, the expected frequency is 100 for each day. Find \(\chi^2\) and the p-value. What does the result say, and what could explain it?

MonTueWedThuFriSatSunBirths1201181161141106557
Working
  1. Calculator

    From the calculator: χ² = 43.5, p = 9.29 × 10⁻⁸, df = 6

    Seven groups, so df = 6.

  2. Meaning

    p is far below 0.05: reject \(H_0\)

    Births are very unlikely to be equally spread over the week by chance.

  3. Where

    Saturday 65 and Sunday 57 are far below 100

    These two bars give most of the χ².

  4. A reason

    Many births are planned (induced or caesarean) and planned births are booked on weekdays.

    A statistical test shows that the pattern is not chance. The reason comes from the context.

Video walkthrough coming