Menu
Sign up Sign in

AI HL · 13.4

Hypothesis Testing

13.4.9

Goodness of fit when parameters are estimated

13.4.9

Goodness of fit when parameters are estimated

Target: I can estimate a Poisson mean, a binomial p or a normal standard deviation from data, including from grouped data using midpoints. (+4 more)

By the end of this section

Key points

Estimated parameters cost degrees of freedom

  • df = N − 1 − k, where N is the number of groups after combining and k is the number of parameters estimated from the data. If nothing is estimated, k = 0 and df = N − 1.
  • A parameter is known if it comes from outside the data: a claim, a theory, a ratio or a given model. It is estimated if you calculate it from the same data you are testing.
  • Poisson, mean estimated: k = 1. Binomial, p estimated (n is known): k = 1. Normal, only the standard deviation or only the mean estimated: k = 1. Normal, both estimated: k = 2.
  • The calculator does not know a parameter was estimated. In the chi-squared goodness of fit screen, type the df yourself.

The method

  • H0: the data follow the model. H1: they do not. An estimated parameter is not written in the hypotheses. A given one is, for example Po(3.2).
  • Expected frequency = N × probability. The last group takes the rest of the tail (X ≥ k). A normal model has open-ended first and last groups, so the frequencies add up to N.
  • Combine groups at the ends until every expected frequency is greater than 5, then count the groups. Use the combined list, not the original one.
  • Conclude in context. Do not claim the data are Poisson. Say there is insufficient evidence that they do not follow a Poisson distribution.

Estimating from the data

  • Poisson: \(\lambda\) is estimated by the sample mean \(\bar{x}\) of the frequency table. Binomial B(n, p): \(\hat{p}=\bar{x}\div n\).
  • Grouped data: use the class midpoints. The mean and standard deviation found are estimates.
  • Use the sample standard deviation (the n − 1 version) for the standard deviation, and its square for an unbiased estimate of the variance.
  • When the mean and the standard deviation both come from the same grouped data, two parameters are estimated: df = N − 1 − 2 = N − 3. Using N − 1 or N − 2 gives a p-value that is too large, and the conclusion can change.
  • A Poisson distribution has mean = variance. If the unbiased estimates are close, a Poisson model is plausible. If the variance is much larger, it is not.

Sample size and conditions

  • Multiply every frequency by 5 and \(\chi^2\) is multiplied by 5 while df stays the same. A larger sample rejects a small departure from the model that a smaller sample would not detect.
  • Very small expected frequencies make \(\dfrac{(O-E)^2}{E}\) too large. That is why groups are combined.
  • A ratio such as 9 : 3 : 3 : 1 gives probabilities 9/16, 3/16, 3/16 and 1/16. The ratio comes from a theory, so no parameter is estimated.
  • A questionnaire is valid if it measures what it claims to. Leading questions and unrepresentative samples make it invalid.

On the calculator

Mean and standard deviation from a frequency table

  • Enter the values (or class midpoints) in one list and the frequencies in another.
  • Run the one-variable statistics with the frequency list.
  • Read \(\bar{x}\) and the sample standard deviation s. Square s for the unbiased variance.

Screenshot and video to come

Expected frequencies

  • For an exact value, use the probability for X = k. For a group, use the cumulative probability.
  • For an open-ended last group, take 1 minus the cumulative probability.
  • Multiply each probability by N and store the list.

Screenshot and video to come

Chi-squared goodness of fit with a chosen df

  • Enter the observed list and the expected list, with the groups already combined.
  • Type the degrees of freedom yourself: groups − 1 − the number of estimated parameters.
  • Read \(\chi^2\) and the p-value.

Screenshot and video to come

Independence test on a combined table

  • Enter the combined observed table as a matrix and run the chi-squared test for independence.
  • Check the expected matrix: every value must be greater than 5.
  • Read \(\chi^2\), p and df.

Screenshot and video to come

Worked examples

Problems like the ones in class. Pick one, try it, then open the working.
Poisson fit with an estimated mean

A help desk records the number of calls received in each of 100 ten-minute periods. (a) Estimate the mean number of calls in a period. (b) Test, at the 5% significance level, whether the number of calls in a period can be modelled by a Poisson distribution.

Calls012345Frequency1539261163
Working
  1. Mean

    From the calculator, with the values 0 to 5 and their frequencies: x̄ = 163 ÷ 100 = 1.63

    Use the frequency list. The mean of the 6 values (2.5) ignores how often each occurs.

  2. Hypotheses

    H0: the number of calls in a period follows a Poisson distribution. H1: it does not follow a Poisson distribution.

    The mean is not in the hypotheses. Nobody told us its value, so it is estimated from the data.

  3. Expected

    Expected frequencies (100 × P(X = k) for Po(1.63)): X = 0: 19.6; X = 1: 31.9; X = 2: 26.0; X = 3: 14.1; X = 4: 5.76; X ≥ 5: 2.54

    The last group takes the whole tail, so the frequencies add up to 100.

  4. Groups

    Expected frequencies of 5 or less: X ≥ 5 (2.54). Combine neighbouring groups until every expected frequency is greater than 5. The new groups are: X = 0, X = 1, X = 2, X = 3, X ≥ 4. Observed: 15, 39, 26, 11, 9. Expected: 19.6, 31.9, 26.0, 14.1, 8.30

    Each expected frequency must be greater than 5.

  5. Degrees of freedom

    df = 5 − 1 − 1 = 3 (1 parameter estimated from the data)

    Estimating the mean from the data removes one degree of freedom: df = groups − 1 − 1.

  6. Test

    From the calculator (χ² GOF, with df entered as 3): χ² = 3.40, p = 0.334

    The calculator does not know the mean was estimated. Type the df yourself.

  7. Conclude

    0.334 > 0.05, so do not reject H0. There is insufficient evidence, at the 5% significance level, that the data do not follow a Poisson distribution.

    Do not say the data are Poisson. Say there is no evidence that they are not.

Video walkthrough coming
Poisson fit with a known mean

An emergency unit says it receives a mean of 3.2 patients per hour. The number of patients arriving in each of 70 hours is recorded. Test, at the 5% significance level, whether a Poisson distribution with mean 3.2 is a suitable model. Combine groups where you need to.

Patients0123456789Frequency2681415117331
Working
  1. Hypotheses

    H0: the number of arrivals per hour follows Po(3.2). H1: it does not follow Po(3.2).

    The mean 3.2 is given by the unit, not found from this data, so it goes in the hypotheses.

  2. Expected

    Expected frequencies (N × probability): X = 0: 2.85; X = 1: 9.13; X = 2: 14.6; X = 3: 15.6; X = 4: 12.5; X = 5: 7.98; X = 6: 4.26; X = 7: 1.95; X = 8: 0.778; X ≥ 9: 0.400

    Use the Poisson probability for each value. The last group is X ≥ 9 so the total is 70.

  3. Groups

    Expected frequencies of 5 or less: X = 0 (2.85); X = 6 (4.26); X = 7 (1.95); X = 8 (0.778); X ≥ 9 (0.400). Combine neighbouring groups until every expected frequency is greater than 5. The new groups are: X ≤ 1, X = 2, X = 3, X = 4, X = 5, X ≥ 6. Observed: 8, 8, 14, 15, 11, 14. Expected: 12.0, 14.6, 15.6, 12.5, 7.98, 7.38

    Join groups at the ends where the expected frequency is small.

  4. Degrees of freedom

    df = 6 − 1 = 5 (no parameter estimated from the data)

    The mean was given, so no parameter was estimated: df = groups − 1.

  5. Test

    From the calculator (χ² GOF, with df entered as 5): χ² = 12.1, p = 0.0338

    Enter the observed list, the expected list and the df.

  6. Conclude

    0.0338 < 0.05, so reject H0. There is sufficient evidence, at the 5% significance level, that the data do not follow a Poisson distribution.

    A small p-value: the data are unlikely if the mean really is 3.2.

Video walkthrough coming
Binomial fit: given p, then estimated p

A nursery plants 5 seeds in each of 100 pots and counts how many seeds in each pot germinate. The seed packet says each seed germinates with probability 0.7. (a) Test, at the 5% significance level, whether B(5, 0.7) is a good model. (b) Estimate the probability that a seed germinates from the data. (c) Test whether a binomial distribution B(5, p), with p found in (b), is a good model.

Germinated012345Pots051840289
Working
  1. (a) Expected

    H0: the number germinating follows B(5, 0.7). H1: it does not. Expected (100 × P(X = k)): X = 0: 0.243; X = 1: 2.83; X = 2: 13.2; X = 3: 30.9; X = 4: 36.0; X = 5: 16.8

    p = 0.7 is given by the packet, so it is not estimated.

  2. (a) Test

    Combine: X ≤ 2, X = 3, X = 4, X = 5. df = 4 − 1 = 3. From the calculator: χ² = 10.9, p = 0.0125. 0.0125 < 0.05, so reject H0. There is sufficient evidence, at the 5% significance level, that the data do not follow B(5, 0.7).

    Known p: df = groups − 1.

  3. (b) Estimate p

    x̄ = 318 ÷ 100 = 3.18. p̂ = x̄ ÷ 5 = 0.636

    The mean of a binomial is np, so p is estimated by x̄ ÷ n.

  4. (c) Expected

    H0: the number germinating follows B(5, p). H1: it does not. Expected using p = 0.636: X = 0: 0.639; X = 1: 5.58; X = 2: 19.5; X = 3: 34.1; X = 4: 29.8; X = 5: 10.4

    This time p is not given. It comes from the same data.

  5. (c) Test

    Combine: X ≤ 1, X = 2, X = 3, X = 4, X = 5. df = 5 − 1 − 1 = 3. From the calculator: χ² = 1.68, p = 0.642. 0.642 > 0.05, so do not reject H0. There is insufficient evidence, at the 5% significance level, that the data do not follow a binomial distribution B(5, p).

    One parameter estimated, so df is one smaller. The fit is much better than with 0.7: the packet's probability was the problem, not the shape.

Video walkthrough coming
Normal fit: mean given, SD estimated

A swimming club says its swimmers take a mean of 62 s for 50 m. The times of 120 swimmers are grouped as shown (in seconds). The standard deviation is not known. (a) Use the class midpoints to estimate the standard deviation. (b) Test, at the 5% significance level, whether the times follow a normal distribution with mean 62 s. Treat the first and last classes as open-ended.

Time (s)40 to under 4646 to under 5252 to under 5858 to under 6464 to under 7070 to under 7676 to under 82Frequency06324225114
Working
  1. Midpoints

    Midpoints: 43, 49, 55, 61, 67, 73, 79

    Each class is replaced by its midpoint. This is an estimate.

  2. Standard deviation

    From the calculator (midpoints with frequencies): sample standard deviation s = 6.94

    Use the sample standard deviation (the n − 1 version), because it estimates the population value.

  3. Hypotheses

    H0: the times follow N(62, σ²). H1: they do not. σ estimated as 6.94

    The mean 62 is the club's claim, so it is known. Only σ is estimated.

  4. Expected

    Expected frequencies (120 × probability, using normal cdf with open ends): x < 46 s: 1.27; 46 ≤ x < 52 s: 7.71; 52 ≤ x < 58 s: 24.9; 58 ≤ x < 64 s: 39.7; 64 ≤ x < 70 s: 31.5; 70 ≤ x < 76 s: 12.3; x ≥ 76 s: 2.62

    The first class starts at −∞ and the last ends at +∞, so the frequencies add to 120.

  5. Groups

    Expected frequencies of 5 or less: x < 46 s (1.27); x ≥ 76 s (2.62). Combine neighbouring groups until every expected frequency is greater than 5. The new groups are: x < 52 s, 52 ≤ x < 58 s, 58 ≤ x < 64 s, 64 ≤ x < 70 s, x ≥ 70 s. Observed: 6, 32, 42, 25, 15. Expected: 8.98, 24.9, 39.7, 31.5, 14.9

    Combine the end groups with their neighbours.

  6. Degrees of freedom

    df = 5 − 1 − 1 = 3 (1 parameter estimated from the data)

    One parameter (σ) estimated: df = groups − 1 − 1.

  7. Test

    From the calculator (χ² GOF, with df entered as 3): χ² = 4.47, p = 0.215

    Type the df yourself.

  8. Conclude

    0.215 > 0.05, so do not reject H0. There is insufficient evidence, at the 5% significance level, that the data do not follow a normal distribution with mean 62 s.

    Answer in context.

Video walkthrough coming
Normal fit: mean and SD both estimated

A greengrocer weighs 150 avocados. The masses are grouped as shown (in grams). The greengrocer thinks the masses follow a normal distribution, but has no values for the mean or the standard deviation. (a) Use the class midpoints to estimate the mean and the standard deviation. (b) Test, at the 5% significance level, whether the masses follow a normal distribution. Treat the first and last classes as open-ended.

Mass (g)100 to under 120120 to under 140140 to under 160160 to under 180180 to under 200200 to under 220220 to under 240Frequency221424023166
Working
  1. Estimates

    Midpoints: 110, 130, 150, 170, 190, 210, 230. From the calculator (midpoints with frequencies): x̄ = 167.73…, sample standard deviation s = 27.57…

    Both are estimates from the same data. Keep the full values in the calculator for the next step.

  2. Hypotheses

    H0: the masses follow a normal distribution. H1: they do not follow a normal distribution.

    Neither the mean nor σ was given, so neither goes in the hypotheses.

  3. Expected frequencies

    Expected frequencies (150 × probability, normal cdf with the estimated mean and σ, open ends): x < 120 g: 6.25; 120 ≤ x < 140 g: 17.3; 140 ≤ x < 160 g: 34.9; 160 ≤ x < 180 g: 42.3; 180 ≤ x < 200 g: 31.1; 200 ≤ x < 220 g: 13.8; x ≥ 220 g: 4.35

    The first class starts at −∞ and the last ends at +∞, so the frequencies add to 150.

  4. Combine and count

    Expected frequencies of 5 or less: x ≥ 220 g (4.35). Combine it with its neighbour. The new groups are: x < 120 g, 120 ≤ x < 140 g, 140 ≤ x < 160 g, 160 ≤ x < 180 g, 180 ≤ x < 200 g, x ≥ 200 g. Observed: 2, 21, 42, 40, 23, 22. Expected: 6.25, 17.3, 34.9, 42.3, 31.1, 18.1. df = 6 − 1 − 2 = 3

    Two parameters were estimated from the data, so df = groups − 1 − 2.

  5. Calculator

    From the calculator (χ² GOF, with df entered as 3): χ² = 8.19, p = 0.0422

    The calculator does not know the mean and σ were estimated. Type the df yourself.

  6. Conclusion

    0.0422 < 0.05, so reject H0. There is sufficient evidence, at the 5% significance level, that the masses do not follow a normal distribution.

    With df = 4 the p-value would be 0.0847 and H0 would not be rejected. Taking off both parameters matters.

Video walkthrough coming
A model given by a formula

A café sells 5 cup sizes, numbered 1 (smallest) to 5. The owner says the size X chosen has probability function \(P(X=x)=\dfrac{6-x}{15}\) for \(x=1,2,3,4,5\). The sizes chosen by 60 customers are recorded. Test, at the 5% significance level, whether the owner's model is suitable.

Size12345Customers17191392
Working
  1. Check the model

    Probabilities: P(X = 1) = 5/15, P(X = 2) = 4/15, P(X = 3) = 3/15, P(X = 4) = 2/15, P(X = 5) = 1/15. They add to 1.

    A probability function must add to 1. This one does.

  2. Expected

    H0: the sizes follow \(P(X=x)=\frac{6-x}{15}\). H1: they do not. Expected (60 × probability): X = 1: 20.0; X = 2: 16.0; X = 3: 12.0; X = 4: 8.00; X = 5: 4.00

    Multiply each probability by 60.

  3. Groups

    X = 5 has expected frequency 4.00, which is 5 or less. Combine X = 4 and X = 5: expected 20.0, 16.0, 12.0, 12.0; observed 17, 19, 13, 11

    Join the small group to its neighbour.

  4. Degrees of freedom

    df = 4 − 1 = 3

    The probabilities were given, so no parameter was estimated.

  5. Test

    From the calculator: χ² = 1.18, p = 0.758

    Observed list, expected list, df.

  6. Conclude

    0.758 > 0.05, so do not reject H0. There is insufficient evidence, at the 5% significance level, that the data do not follow the owner's model.

    The model is consistent with the data.

Video walkthrough coming
Testing a ratio

In a breeding experiment with sweet peas, the theory predicts that the four types of plant appear in the ratio 9 : 3 : 3 : 1. Of 320 plants, 157 are purple and round, 79 purple and long, 61 red and round and 23 red and long. Test, at the 5% significance level, whether the data agree with the theory.

Typepurple, roundpurple, longred, roundred, longPlants157796123
Working
  1. Probabilities

    Ratio 9 : 3 : 3 : 1 has 16 parts: probabilities 9/16, 3/16, 3/16, 1/16

    Add the ratio parts to get the total, then divide.

  2. Expected

    H0: the types appear in the ratio 9 : 3 : 3 : 1. H1: they do not. Expected (320 × probability): purple, round: 180; purple, long: 60.0; red, round: 60.0; red, long: 20.0

    All are greater than 5, so nothing is combined.

  3. Degrees of freedom

    df = 4 − 1 = 3

    The ratio comes from the theory, not from the data. No parameter is estimated.

  4. Test

    From the calculator: χ² = 9.42, p = 0.0242

    Observed and expected lists.

  5. Conclude

    0.0242 < 0.05, so reject H0. There is sufficient evidence, at the 5% significance level, that the data do not follow the ratio 9 : 3 : 3 : 1.

    The data differ from the theory by more than chance would usually allow.

Video walkthrough coming
Does the mean match the variance?

The number of typing errors on each of 100 pages is recorded. (a) Find unbiased estimates of the mean and the variance. (b) Say whether a Poisson distribution is a plausible model.

Errors0123456Pages102823161652
Working
  1. Mean

    From the calculator: x̄ = 2.23

    The sample mean is an unbiased estimate of the population mean.

  2. Variance

    From the calculator: s = 1.49, so unbiased variance s² = 2.22

    Use the sample standard deviation (n − 1) and square it. Dividing by N instead gives a biased estimate.

  3. Compare

    Mean 2.23, variance 2.22: close together

    For a Poisson distribution the mean equals the variance. These are close, so the model is plausible.

  4. Conclude

    A Poisson model is plausible. A goodness of fit test would be the next check.

    This is a quick check, not a test. The test gives the p-value.

Video walkthrough coming