10.2 Goodness-of-Fit Test

Aligned outcomes:

SLO 4

Demonstrate an understanding of, and ability to use, basic ideas of statistical processes, including hypothesis tests and confidence interval estimation.

SLO 5

Identify appropriate statistical techniques and use technology-based statistical analysis to describe, interpret, and communicate results.

Learning Objectives

By the end of this section, you will be able to:

In this section, you will learn to:
  • state the null and alternative hypotheses for a goodness-of-fit test, in sentences or as a claim about a distribution;
  • compute the chi-square test statistic \(\sum_{k} \frac{(O - E)^{2}}{E}\) from a table of observed and expected counts;
  • find the degrees of freedom for a goodness-of-fit test and explain why it depends on the number of categories rather than the sample size;
  • check the expected-count condition and combine categories when it fails;
  • carry a goodness-of-fit test through to a decision and write the conclusion in context.

Section 10.1 gave you a curve with no job to do. This section gives it one. The question a goodness-of-fit test answers is a natural one to ask of almost any set of counts: the data fell into these categories in these amounts — is that what we should have expected? Faculty believe students miss class in a certain pattern. Employers believe absences are spread evenly across the week. A gambler believes two coins are fair. In each case there is a claimed distribution and a set of observed counts, and the test measures the distance between them. If that distance is small, the data fit the claim. If it is large, they do not.

10.2.1 What the Test Measures

In this type of hypothesis test you decide whether data "fit" a particular distribution. You might suspect your data follow a binomial distribution, or a uniform one, or the same distribution as some larger population. The test that decides is a chi-square test, which simply means the distribution used for the hypothesis test is the chi-square distribution you met in Section 10.1.

Definition 10.2.1: Goodness-of-Fit Test

A goodness-of-fit test compares a set of observed category counts against the counts a claimed distribution predicts, and decides whether the difference is larger than sampling variation alone would explain.

The hypotheses may be written as sentences or stated as equations or inequalities. Written as sentences they are as plain as they look:

Definition 10.2.1 — Goodness-of-Fit Test A grouped bar chart compares the observed number of defects in five production batches against the counts a claimed distribution predicts. For each batch (0–100 through 401–500 produced), a blue bar shows the expected count (5, 6, 7, 8, 10) and an orange bar beside it shows the observed count (5, 7, 8, 9, 11). To the right, two hypothesis panels state H0: the data fit the claimed distribution, and Ha: the data do not fit the claimed distribution. Goodness-of-Fit Test Observed category counts vs. what a claimed distribution predicts Expected (E) Observed (O) 5 5 0–100 6 7 101–200 7 8 201–300 8 9 301–400 10 11 401–500 Number defective, by number produced (Tables 10.2.1 – 10.2.2) H₀ the data fit the claimed distribution Hₐ the data do not fit the claimed distribution The test decides whether the gaps between O and E exceed sampling variation alone.

Definition 10.2.1 — Goodness-of-Fit Test: The test decides whether the gaps between O and E exceed sampling variation alone.

Definition 10.2.2: Chi-Square Test Statistic for Goodness of Fit

The test statistic for a goodness-of-fit test is

$$ \sum_{k} \frac{(O - E)^{2}}{E} $$

where

  • \(O\) = the observed values, meaning the data;
  • \(E\) = the expected values, meaning what theory predicts if \(H_{0}\) is true;
  • \(k\) = the number of different data cells or categories.
This is the sum of squares from Section 10.1, in disguise

Definition 10.1.3 built a chi-square variable by squaring independent standard normal variables and adding them up. Each \(\frac{(O - E)^{2}}{E}\) term is playing that role here: a difference, scaled by its own expected size, then squared. That is why the total follows a chi-square distribution, and why the two facts you already know still hold — the statistic can never be negative, and its curve is skewed to the right.

There are \(k\) terms of the form \(\frac{(O - E)^{2}}{E}\), one for every category, and the statistic is their sum.

Look at what a single term does. The numerator \((O - E)^{2}\) is the miss for that category, squared — squared so that overshooting by 5 and undershooting by 5 count the same, and so that the total can never be negative. Dividing by \(E\) is what makes the misses comparable. Being 6 off matters enormously in a category expected to hold 8 and hardly at all in one expected to hold 330. Every term is a miss measured against the size of the thing it missed.

Definition 10.2.2 — Chi-Square Test Statistic for Goodness of Fit The statistic is the sum over categories of (O minus E) squared divided by E. Using Tables 10.2.1 and 10.2.2, five production-range categories are shown side by side. Each column shows the observed-minus-expected miss (+0, +1, +1, +1, +1), a bar whose height is that category's contribution (O−E)²/E on a shared scale, its expected value E, and its term value (0.00, 0.17, 0.14, 0.13, 0.10). A bottom line sums the terms: chi-square equals about 0.54. χ2 = Σ k (O − E)2 E one term per category, then add them all up O = observed (the data)  ·  E = expected if H₀ is true  ·  k = number of categories +0 0–100 E = 5 0.00 +1 101–200 E = 6 0.17 +1 201–300 E = 7 0.14 +1 301–400 E = 8 0.13 +1 401–500 E = 10 0.10 bar height = (O − E)²/E χ2 = 0 + 0.17 + 0.14 + 0.13 + 0.10 ≈ 0.54

Definition 10.2.2 — Chi-Square Test Statistic for Goodness of Fit: Bar height = (O − E)²/E.

Definition 10.2.3: Degrees of Freedom for a Goodness-of-Fit Test

For a goodness-of-fit test, the degrees of freedom is

$$ df = (\text{number of categories}) - 1 $$

Notice what is not in that formula: the sample size. A survey of 600 families sorted into 5 categories has \(df = 4\), not \(df = 599\). This is the single most common error in the section, and it is worth saying out loud once — the degrees of freedom count the categories, not the people.

The goodness-of-fit test is almost always right-tailed. If the observed values and their expected values are not close to each other, the terms in the sum get large, the test statistic gets large, and it lands far out in the right tail of the chi-square curve. A poor fit can only push the statistic up, never down, so there is no left tail worth looking at.

Definition 10.2.3 — Degrees of Freedom for a Goodness-of-Fit Test Five category chips labelled 0–100 through 401–500 sit in a row. A curly brace beneath them reads “number of categories = 5”. Below, the formula df = 5 − 1 = 4 is shown, with the −1 highlighted as the single constraint that the counts must sum to the sample size. To the right, a greyed note shows “df = 599” marked wrong with an adjacent cross glyph and the label “sample size does NOT enter df”, contrasting df = 4 against the common error. Degrees of freedom count the categories, not the people 0–100 101–200 201–300 301–400 401–500 the 5 defect-count categories of Table 10.2.1 number of categories = 5 df = 5 − 1 = 4 one constraint: the counts must sum to n, so only 4 of the 5 cells are free to vary df = 599 600 families sorted into 5 categories gives df = 4. The sample size never enters. df = (number of categories) − 1 — here, 5 − 1 = 4

Definition 10.2.3 — Degrees of Freedom for a Goodness-of-Fit Test: Df = (number of categories) − 1 — here, 5 − 1 = 4.

10.2.2 The Condition on Expected Counts

One condition has to be checked before the test is legitimate.

The expected value for each cell needs to be at least five

Dividing by \(E\) is what makes the statistic work, and it is also what makes a tiny \(E\) dangerous — a category expected to hold 2 people can produce an enormous term from a miss of only a few. The fix is not to abandon the test but to merge that category into a neighboring one until every expected count reaches five. Merging costs you a category, and therefore one degree of freedom, so check the condition before computing \(df\), not after.

Try It Now 10.2.1

A factory manager needs to understand how many products are defective versus how many are produced. The number of expected defects is listed in Table 10.2.1, and a random sample gave the actual defect counts in Table 10.2.2. State the null and alternative hypotheses needed to conduct a goodness-of-fit test, and state the degrees of freedom.

Table 10.2.1 — Expected number of defects.
Number producedNumber defective
0–1005
101–2006
201–3007
301–4008
401–50010
Table 10.2.2 — Observed number of defects.
Number producedNumber defective
0–1005
101–2007
201–3008
301–4009
401–50011
Solution — hypotheses and degrees of freedom for the defect study

Step 1 — Say what is being claimed. The manager has an expected pattern of defects across five production ranges. The test asks whether the observed defects follow that pattern.

Step 2 — Write the null hypothesis. \(H_{0}\): the number of defects fits the expected distribution.

Step 3 — Write the alternative. The alternative is the opposite of the null. \(H_{a}\): the number of defects does not fit the expected distribution.

Step 4 — Check the expected counts. The expected values are 5, 6, 7, 8 and 10. Every one is at least five, so no categories need to be combined and all five are kept.

Step 5 — Count the degrees of freedom.

$$ df = (\text{number of categories}) - 1 = 5 - 1 = 4 $$

Answer: \(H_{0}\): the defects fit the expected distribution; \(H_{a}\): they do not; \(df = 4\).

Example 10.2.1: Absenteeism and faculty perception

Absenteeism of college students from math classes is a major concern to math instructors, because missing class appears to increase the drop rate. A study was done to determine whether the actual student absenteeism rate follows faculty perception. The faculty expected that a group of 100 students would miss class as in Table 10.2.3, and a random survey across all mathematics courses produced the observed counts in Table 10.2.4.

Table 10.2.3 — Expected number of students, by absences per term.
Number of absences per termExpected number of students
0–250
3–530
6–812
9–116
12+2
Table 10.2.4 — Observed number of students, by absences per term.
Number of absences per termActual number of students
0–235
3–540
6–820
9–111
12+4

Determine the hypotheses, decide whether the tables can be used as they stand, and find the degrees of freedom.

Solution — why this table has to be repaired first

Step 1 — State the hypotheses.

\(H_{0}\): Student absenteeism fits faculty perception.

The alternative hypothesis is the opposite of the null hypothesis.

\(H_{a}\): Student absenteeism does not fit faculty perception.

Step 2 — Check the expected counts against the condition. The expected values are 50, 30, 12, 6 and 2. The last one fails: the expected number of students in the "12+" category is 2, which is less than five. The test cannot be run on the tables as they appear.

Step 3 — Combine categories until the condition holds. Merge the "12+" group with the "9–11" group to make a single "9+" category. Its expected count is \(6 + 2 = 8\) and its observed count is \(1 + 4 = 5\). Every expected count is now at least five, as shown in Table 10.2.5.

Table 10.2.5 — The repaired tables, after merging the last two categories.
Number of absences per termExpectedObserved
0–25035
3–53040
6–81220
9+85

Step 4 — Count the degrees of freedom from the repaired table. There are now four cells, not five.

$$ df = \text{number of cells} - 1 = 4 - 1 = 3 $$

Answer: \(H_{0}\): absenteeism fits faculty perception; \(H_{a}\): it does not. The original tables cannot be used because one expected count is 2; after merging "9–11" with "12+", four categories remain and \(df = 3\).

10.2.3 Running the Test End to End

The previous example stopped at the degrees of freedom. This one carries a test all the way to a written conclusion, computing the statistic by hand so you can see every term.

Try It Now 10.2.2

Teachers want to know which night each week their students do most of their homework. Most teachers think students spread homework equally throughout the week. A random sample of 56 students were asked on which night they did the majority of their homework, with the results in Table 10.2.6. For the population of students, do the nights occur with equal frequencies? What type of hypothesis test should you use, and what are the expected counts and degrees of freedom?

Table 10.2.6 — Night on which students did the most homework.
SundayMondayTuesdayWednesdayThursdayFridaySaturday
1181071055
Solution — setting up a uniform-distribution test

Step 1 — Identify the test. A claimed distribution is being compared against observed category counts, so this is a goodness-of-fit test using the chi-square distribution.

Step 2 — Write the hypotheses.

\(H_{0}\): The nights occur with equal frequencies; that is, they fit a uniform distribution.

\(H_{a}\): The nights occur with unequal frequencies; that is, they do not fit a uniform distribution.

Step 3 — Build the expected counts. "Equally throughout the week" spreads 56 students over 7 nights:

$$ E = \frac{56}{7} = 8 \text{ for every night} $$

Step 4 — Check the condition. Every expected count is 8, which is at least five, so no categories need combining.

Step 5 — Count the degrees of freedom.

$$ df = 7 - 1 = 6 $$

Answer: A chi-square goodness-of-fit test, with \(H_{0}\) that the nights fit a uniform distribution, an expected count of 8 on every night, and \(df = 6\).

Example 10.2.2: Which weekday do absences fall on?

Employers want to know which days of the week employees are absent in a five-day work week. Most employers would like to believe that employees are absent equally during the week. A random sample of 60 managers were asked on which day of the week they had the highest number of employee absences, with the results in Table 10.2.7. For the population of employees, do the days for the highest number of absences occur with equal frequencies during a five-day work week? Test at a 5% significance level.

Table 10.2.7 — Day of the week employees were most absent.
MondayTuesdayWednesdayThursdayFriday
Number of Absences15129915
Solution — a full test, computed by hand

Step 1 — State the hypotheses.

\(H_{0}\): The absent days occur with equal frequencies, that is, they fit a uniform distribution.

\(H_{a}\): The absent days occur with unequal frequencies, that is, they do not fit a uniform distribution.

Step 2 — Find the expected values. If the absent days occur with equal frequencies then, out of 60 absent days (the total in the sample, \(15 + 12 + 9 + 9 + 15 = 60\)), there would be 12 absences on each of the five days. Those numbers are the expected \((E)\) values; the values in the table are the observed \((O)\) values.

Step 3 — Check the condition. Every expected count is 12, comfortably at least five.

Step 4 — Build the table of terms. Compute \((O - E)\), then \((O - E)^{2}\), then \(\frac{(O - E)^{2}}{E}\) for each day.

Table 10.2.8 — Computing the test statistic one category at a time.
Day\(E\)\(O\)\(O - E\)\((O-E)^{2}\)\(\frac{(O-E)^{2}}{E}\)
Monday1215390.75
Tuesday1212000
Wednesday129−390.75
Thursday129−390.75
Friday1215390.75

Step 5 — Sum the last column. The sum is 3. This is the \(\chi^{2}\) test statistic.

Step 6 — Find the degrees of freedom. \(df = \text{number of cells} - 1 = 5 - 1 = 4\).

Step 7 — Find the p-value. The test is right-tailed, so the p-value is \(P(\chi^{2} > 3)\) with \(df = 4\). Using a calculator, the p-value is 0.5578.

Step 8 — Compare and decide. The significance level is \(\alpha = 0.05\) and the p-value is 0.5578, so \(\alpha <\) p-value. The decision is not to reject the null hypothesis.

Answer: \(\chi^{2} = 3\) with \(df = 4\) and a p-value of 0.5578. At a 5% level of significance, from the sample data, there is not sufficient evidence to conclude that the absent days do not occur with equal frequencies.

Using the TI-83, 83+, 84, 84+ Calculator

To get the p-value in Example 10.2.2, press 2nd DISTR, arrow down to χ²cdf, and press ENTER. Enter (3, 1099, 4) — the test statistic, an effectively infinite upper bound, and the degrees of freedom. Rounded to four decimal places you should see 0.5578.

Read that conclusion twice

It ends in a double negative — "not sufficient evidence to conclude that the days do not occur with equal frequencies" — and the awkwardness is deliberate. The test did not show that absences are spread evenly. It failed to show that they are uneven. Those are different claims, and only the second one is what a p-value of 0.5578 supports.

TI-83+ and some TI-84 calculators do not have a dedicated program for the goodness-of-fit test statistic, so the sum has to be built by hand as in Example 10.2.3. Newer TI-84 calculators have Chi2 GOF under STAT TESTS. To run it, put the observed values into one list and the expected values into a second list, press STAT TESTS and Chi2 GOF, enter the two list names and the degrees of freedom, then press calculate or draw. Clear any lists before you start: go into STAT EDIT, arrow up to the list name, press CLEAR and arrow down. Alternatively press STAT and then 4 for ClrList, enter the list name, and press ENTER.

10.2.4 When the Expected Counts Come from Percentages

In both examples so far the expected counts arrived as counts. More often a claimed distribution is published as percentages, and the expected counts have to be built from them before the test can start.

Try It Now 10.2.3

The expected percentage of the number of pets students have in their homes is distributed as in Table 10.2.9 — this is the given distribution for the student population of the United States. A random sample of 1,000 students from the Eastern United States resulted in the data in Table 10.2.10. At the 1% significance level, does it appear that the "number of pets" distribution of students in the Eastern United States is different from the distribution for the United States student population as a whole?

Table 10.2.9 — Claimed distribution of number of pets (percent).
Number of PetsPercent
018
125
230
318
4+9
Table 10.2.10 — Observed counts from 1,000 Eastern students.
Number of PetsFrequency
0210
1240
2320
3140
4+90
Solution — turning percentages into expected counts

Step 1 — State the hypotheses.

\(H_{0}\): The "number of pets" distribution of Eastern United States students is the same as that of the United States student population.

\(H_{a}\): The "number of pets" distribution of Eastern United States students is different from that of the United States student population.

Step 2 — Convert each percentage into an expected count. Multiply each percent by the sample size of 1,000:

$$ E = (0.18)(1000),\ (0.25)(1000),\ (0.30)(1000),\ (0.18)(1000),\ (0.09)(1000) $$

giving expected counts of 180, 250, 300, 180 and 90.

Step 3 — Check the condition. Every expected count is far above five.

Step 4 — Compute each term.

$$ \frac{(210-180)^{2}}{180} = 5.00 \qquad \frac{(240-250)^{2}}{250} = 0.40 \qquad \frac{(320-300)^{2}}{300} \approx 1.33 $$ $$ \frac{(140-180)^{2}}{180} \approx 8.89 \qquad \frac{(90-90)^{2}}{90} = 0 $$

Step 5 — Sum the terms. \(5.00 + 0.40 + 1.33 + 8.89 + 0 \approx 15.62\), so \(\chi^{2} \approx 15.62\).

Step 6 — Find the degrees of freedom. There are five categories, so \(df = 5 - 1 = 4\). Note that \(df \neq 1000 - 1\).

Step 7 — Find the p-value and decide. The test is right-tailed, and \(P(\chi^{2} > 15.62)\) with \(df = 4\) is about 0.0036. Since \(\alpha = 0.01 >\) p-value, reject \(H_{0}\).

Answer: \(\chi^{2} \approx 15.62\) with \(df = 4\) and a p-value of about 0.0036. At the 1% significance level there is sufficient evidence to conclude that the Eastern United States distribution differs from the national one.

Example 10.2.3: Streaming services in the far western United States

One study indicates that the number of streaming services American families have is distributed as in Table 10.2.11 — this is the given distribution for the American population, and the table contains expected \((E)\) percents. A random sample of 600 families in the far western United States resulted in the observed \((O)\) frequencies in Table 10.2.12. At the 1% significance level, does it appear that the "number of streaming services" distribution of far western United States families is different from the distribution for the American population as a whole?

Table 10.2.11 — Claimed national distribution (percent).
Number of Streaming ServicesPercent
010
116
255
311
4+8
Table 10.2.12 — Observed counts from 600 far western families.
Number of Streaming ServicesFrequency
066
1119
2340
360
4+15
Total600
Solution — a test that rejects, and why one category drives it

Step 1 — Recognize the question. This asks whether the far western families' distribution fits the distribution of American families. The test is always right-tailed.

Step 2 — Convert the percentages into expected frequencies. Multiply each percentage by 600.

Table 10.2.13 — Expected frequencies from the claimed percentages.
Number of Streaming ServicesPercentExpected Frequency
010(0.10)(600) = 60
116(0.16)(600) = 96
255(0.55)(600) = 330
311(0.11)(600) = 66
over 38(0.08)(600) = 48

The expected frequencies are 60, 96, 330, 66 and 48, all above five.

Step 3 — State the hypotheses.

\(H_{0}\): The "number of streaming services" distribution of far western United States families is the same as the "number of streaming services" distribution of the American population.

\(H_{a}\): The "number of streaming services" distribution of far western United States families is different from the "number of streaming services" distribution of the American population.

Step 4 — Name the distribution for the test. \(\chi_{4}^{2}\), where \(df = (\text{the number of cells}) - 1 = 5 - 1 = 4\). Note that \(df \neq 600 - 1\).

Step 5 — Calculate the test statistic.

$$ \chi^{2} = \frac{(66-60)^{2}}{60} + \frac{(119-96)^{2}}{96} + \frac{(340-330)^{2}}{330} + \frac{(60-66)^{2}}{66} + \frac{(15-48)^{2}}{48} = 29.65 $$

Step 6 — Find the p-value. \(p\text{-value} = P(\chi^{2} > 29.65) = 0.000006\).

Step 7 — Compare \(\alpha\) and the p-value. With \(\alpha = 0.01\) and a p-value of 0.000006, \(\alpha >\) p-value.

Step 8 — Make a decision. Since \(\alpha >\) p-value, reject \(H_{0}\). This means you reject the belief that the distribution for the far western states is the same as that of the American population as a whole.

Answer: \(\chi^{2} = 29.65\) with \(df = 4\) and a p-value of 0.000006. At the 1% significance level, from the data, there is sufficient evidence to conclude that the "number of streaming services" distribution for the far western United States is different from that for the American population as a whole.

Using the TI-83, 83+, 84, 84+ Calculator

For Example 10.2.3, press STAT and ENTER. Clear lists L1, L2 and L3 if they hold data. Into L1 put the observed frequencies 66, 119, 340, 60, 15. Into L2 put the expected frequencies as arithmetic — .10*600, .16*600, .55*600, .11*600, .08*600 — and let the calculator do the multiplication. Arrow over to L3, up to the name area, enter (L1-L2)2/L2 and press ENTER. Press 2nd QUIT, then 2nd LIST, arrow to MATH, and press 5 for sum. Enter L3. Rounded to two decimal places you should see 29.65.

One category did almost all of the work

In Example 10.2.3 the five terms are 0.60, 5.51, 0.30, 0.55 and 22.69. The last one — 15 families observed where 48 were expected — contributes more than three quarters of the total of 29.65. The test statistic tells you the distributions differ; it does not tell you where. Scanning the individual terms does, and it is worth doing every time you reject, because "far western families are much less likely to hold four or more services" is a finding, while "the distributions differ" is only a verdict.

For the p-value, press 2nd DISTR, press 7 or arrow down to 7:χ²cdf, press ENTER, and enter (29.65, 1E99, 4). Rounded to four places you should see 5.77E-6, which is 0.000006 rounded to six decimal places.

10.2.5 Recognizing a Goodness-of-Fit Question in Disguise

Not every goodness-of-fit problem announces itself with a table of percentages. Sometimes the claimed distribution has to be worked out from the setup before there is anything to test.

Try It Now 10.2.4

Students in a social studies class hypothesize that the literacy rates across the world for every region are 82%. Table 10.2.14 shows the actual adult literacy rates by region. What are the test statistic and the degrees of freedom?

Table 10.2.14 — Adult literacy rate by MDG region (percent).
MDG RegionAdult Literacy Rate (%)
Developed Regions99.0
Commonwealth of Independent States99.5
Northern Africa67.3
Sub-Saharan Africa62.5
Latin America and the Caribbean91.0
Eastern Asia93.8
Southern Asia61.9
South-Eastern Asia91.9
Western Asia84.5
Oceania66.4
Solution — a single claimed rate across every category

Step 1 — Identify the claimed distribution. The students claim every region has a literacy rate of 82%, so the expected value in each of the ten categories is 82.

Step 2 — Count the categories. There are ten regions listed, so \(k = 10\).

Step 3 — Compute each term. For every region, form \(\frac{(O - 82)^{2}}{82}\):

$$ \frac{(99.0-82)^{2}}{82} \approx 3.524 \qquad \frac{(99.5-82)^{2}}{82} \approx 3.735 \qquad \frac{(67.3-82)^{2}}{82} \approx 2.635 $$ $$ \frac{(62.5-82)^{2}}{82} \approx 4.637 \qquad \frac{(91.0-82)^{2}}{82} \approx 0.988 \qquad \frac{(93.8-82)^{2}}{82} \approx 1.698 $$ $$ \frac{(61.9-82)^{2}}{82} \approx 4.926 \qquad \frac{(91.9-82)^{2}}{82} \approx 1.195 \qquad \frac{(84.5-82)^{2}}{82} \approx 0.076 $$ $$ \frac{(66.4-82)^{2}}{82} \approx 2.968 $$

Step 4 — Sum the terms. The total is approximately 26.38, so \(\chi^{2} \approx 26.38\).

Step 5 — Find the degrees of freedom. \(df = 10 - 1 = 9\).

Answer: \(\chi^{2} \approx 26.38\) with \(df = 9\).

Example 10.2.4: Are the coins fair?

Suppose you flip two coins 100 times. The results are 20 HH, 27 HT, 30 TH, and 23 TT. Are the coins fair? Test at a 5% significance level.

Solution — building the claimed distribution from the sample space

Step 1 — Recognize the shape of the problem. This can be set up as a goodness-of-fit problem. The sample space for flipping two fair coins is \(\{HH, HT, TH, TT\}\). Out of 100 flips you would expect 25 of each. That is the expected distribution, and the question "are the coins fair?" is the same as asking whether the observed distribution fits it.

Step 2 — Define the random variable and the categories. Let \(X\) = the number of heads in one flip of the two coins, so \(X\) takes the values 0, 1 and 2. The number of cells is therefore three, not four — HT and TH both give one head and collapse into a single category.

Step 3 — Collect the observed and expected frequencies. The observed frequencies are 20 (two heads), \(27 + 30 = 57\) (one head), and 23 (zero heads). The expected frequencies are 25 (two heads), 50 (one head), and 25 (zero heads). This test is right-tailed.

Step 4 — State the hypotheses.

\(H_{0}\): The coins are fair.

\(H_{a}\): The coins are not fair.

Step 5 — Name the distribution for the test. \(\chi_{2}^{2}\), where \(df = 3 - 1 = 2\).

Step 6 — Calculate the test statistic.

$$ \chi^{2} = \frac{(20-25)^{2}}{25} + \frac{(57-50)^{2}}{50} + \frac{(23-25)^{2}}{25} = 1 + 0.98 + 0.16 = 2.14 $$

Step 7 — Find the p-value. \(p\text{-value} = P(\chi^{2} > 2.14) = 0.3430\).

Step 8 — Compare and decide. With \(\alpha = 0.05\) and a p-value of 0.3430, \(\alpha <\) p-value, so do not reject \(H_{0}\).

Answer: \(\chi^{2} = 2.14\) with \(df = 2\) and a p-value of 0.3430. There is insufficient evidence to conclude that the coins are not fair.

Using the TI-83, 83+, 84, 84+ Calculator

For Example 10.2.4, press STAT and ENTER, clearing L1, L2 and L3 first. Into L1 put the observed frequencies 20, 57, 23. Into L2 put the expected frequencies 25, 50, 25. Arrow to L3, up to the name area, enter (L1-L2)2/L2 and press ENTER. Press 2nd QUIT, 2nd LIST, arrow to MATH, press 5 for sum, and enter L3. Rounded to two decimal places you should see 2.14. Then press 2nd DISTR, arrow to 7:χ²cdf, press ENTER, and enter (2.14, 1E99, 2). Rounded to four places you should see 0.3430, the p-value.

Why three categories and not four

Step 2 is the step students skip. The four outcomes HH, HT, TH, TT are the sample space, but the random variable counts heads, and two of those outcomes give the same count. Choosing the random variable is what fixes the number of categories, and the number of categories is what fixes the degrees of freedom. Get \(X\) wrong and \(df\) is wrong, and every number after it inherits the error.

Problem Set 10.2

Problem 1. State the null and alternative hypotheses for a goodness-of-fit test in words.

Solution

Step 1 — Recall what the hypotheses say in words: The null hypothesis is always the claim that the data fit.

Step 2 — Write \(H_{0}\): \(H_{0}\): The observed data fit the claimed distribution.

Step 3 — Write \(H_{a}\): The alternative is simply the opposite of the null. \(H_{a}\): The observed data do not fit the claimed distribution.

Answer: \(H_{0}\): the data fit the claimed distribution; \(H_{a}\): the data do not fit the claimed distribution.

Problem 2. Write the formula for the chi-square goodness-of-fit test statistic and say what \(O\), \(E\) and \(k\) stand for.

Solution

Step 1 — State the formula: The test statistic is

$$ \sum_{k} \frac{(O - E)^{2}}{E} $$

Step 2 — Define each symbol: \(O\) stands for the observed values — the counts actually recorded in the data. \(E\) stands for the expected values — the counts theory predicts if \(H_{0}\) is true. \(k\) is the number of different data cells or categories.

Answer: \(\chi^{2} = \sum_{k} \frac{(O - E)^{2}}{E}\), where \(O\) = observed values, \(E\) = expected values, and \(k\) = number of categories.

Problem 3. A goodness-of-fit test uses six categories. What is the number of degrees of freedom?

Solution

Step 1 — Apply the degrees-of-freedom formula: For a goodness-of-fit test, \(df = (\text{number of categories}) - 1\). This depends only on how many cells the data are sorted into, not on the sample size.

Step 2 — Compute: With six categories,

$$ df = 6 - 1 = 5 $$

Answer: \(df = 5\).

Problem 4. A survey of 400 people is sorted into 5 categories. A student reports \(df = 399\). Explain the error.

Solution

Step 1 — Identify the error: The student used the sample size instead of the number of categories. Degrees of freedom count the categories, not the people — a survey of 400 people sorted into 5 categories has only 5 cells to work with.

Step 2 — Compute the correct value:

$$ df = (\text{number of categories}) - 1 = 5 - 1 = 4 $$

The sample size of 400 does not appear anywhere in the formula.

Answer: The student confused sample size with category count. The correct degrees of freedom is \(df = 4\), not 399.

Problem 5. An expected-count table reads 22, 14, 9, 3. Explain why the test cannot be run as it stands, and describe what to do about it.

Solution

Step 1 — Check the expected-count condition: Every expected value must be at least five. Here the expected counts are 22, 14, 9 and 3, and the last one fails: an expected count of 3 is less than five.

Step 2 — Explain why it matters: Dividing by a tiny \(E\) makes a small miss produce an enormous term, so the test statistic becomes unreliable when any expected count is too small.

Step 3 — Describe the fix: Combine the failing category with a neighboring category until every expected count reaches five. Merging costs one category, and therefore one degree of freedom, so this must be done before computing \(df\).

Answer: The test cannot be run because one expected count (3) is below five. Merge that category into a neighboring one so all expected counts are at least five, then run the test on the reduced set of categories.

Problem 6. A die is rolled 120 times and each face appears the number of times shown: 18, 23, 16, 21, 22, 20. State the expected count for each face and the degrees of freedom.

Solution

Step 1 — Find the expected count per face: If the die is fair, each of the six faces should come up equally often. Out of 120 rolls:

$$ E = \frac{120}{6} = 20 \text{ per face} $$

Step 2 — Check the condition: An expected count of 20 is at least five, so no categories need combining.

Step 3 — Count the degrees of freedom: There are six categories (faces).

$$ df = 6 - 1 = 5 $$

Answer: Expected count = 20 for each face; \(df = 5\).

Problem 7. For the die in 10.2.6, compute the chi-square test statistic.

Solution

Step 1 — Set up the terms: From 10.2.6, the expected count is 20 for every face, and the observed counts are 18, 23, 16, 21, 22, 20. Compute \(\frac{(O-E)^{2}}{E}\) for each face.

Step 2 — Compute each term:

$$ \frac{(18-20)^{2}}{20} = \frac{4}{20} = 0.20 \qquad \frac{(23-20)^{2}}{20} = \frac{9}{20} = 0.45 \qquad \frac{(16-20)^{2}}{20} = \frac{16}{20} = 0.80 $$ $$ \frac{(21-20)^{2}}{20} = \frac{1}{20} = 0.05 \qquad \frac{(22-20)^{2}}{20} = \frac{4}{20} = 0.20 \qquad \frac{(20-20)^{2}}{20} = 0 $$

Step 3 — Sum the terms:

$$ \chi^{2} = 0.20 + 0.45 + 0.80 + 0.05 + 0.20 + 0 = 1.70 $$

Answer: \(\chi^{2} = 1.70\).

Problem 8. A claimed distribution is 20%, 35%, 30% and 15%, and a sample of 200 is drawn. Find the four expected counts.

Solution

Step 1 — Convert each percentage to a count: Multiply each claimed percentage by the sample size of 200, since the expected count is the share of the sample the claim predicts for that category.

Step 2 — Compute each expected count:

$$ E_{1} = (0.20)(200) = 40 \qquad E_{2} = (0.35)(200) = 70 $$ $$ E_{3} = (0.30)(200) = 60 \qquad E_{4} = (0.15)(200) = 30 $$

Step 3 — Check the condition: All four expected counts are well above five, so no categories need combining. As a check, they sum to \(40 + 70 + 60 + 30 = 200\), matching the sample size.

Answer: The expected counts are 40, 70, 60 and 30.

Problem 9. Explain why the goodness-of-fit test is almost always right-tailed.

Solution

Step 1 — Look at what the statistic can do: Each term \(\frac{(O-E)^{2}}{E}\) is a squared miss divided by its expected size, so every term is zero or positive. A poor fit can only push the total up, never down.

Step 2 — Connect this to the tails: Large values of the statistic mean the data do not fit the claimed distribution; small values mean they do. Since only large values count as evidence against \(H_{0}\), the rejection region sits entirely in the right tail of the chi-square curve, and there is no left tail worth looking at.

Answer: Because every term in the sum is nonnegative, a bad fit can only inflate the statistic. Evidence against \(H_{0}\) appears only as large values, so the test is almost always right-tailed.

Problem 10. A goodness-of-fit test gives \(\chi^{2} = 12.4\) with \(df = 3\) and a p-value of 0.0061. At the 5% significance level, state the decision and write the conclusion in context for a claim that a distribution of blood types fits a published national distribution.

Solution

Step 1 — Compare the p-value to \(\alpha\): The significance level is \(\alpha = 0.05\) and the p-value is 0.0061. Since \(\alpha >\) p-value, the decision is to reject \(H_{0}\).

Step 2 — Translate the decision into context: Rejecting \(H_{0}\) means the data do not fit the claimed national blood-type distribution.

Answer: Reject \(H_{0}\). At the 5% significance level, there is sufficient evidence to conclude that the distribution of blood types does not fit the published national distribution.

Key Terms

goodness-of-fit test — a chi-square test that compares observed category counts with the counts a claimed distribution predicts, to decide whether the data fit that distribution.

observed values (\(O\)) — the counts actually recorded in each category; the data.

expected values (\(E\)) — the counts each category would hold if the null hypothesis were true; computed from the claimed distribution, often by multiplying a claimed percentage by the sample size.

number of cells (\(k\)) — the number of categories the data are sorted into; it fixes the degrees of freedom, which is \(k - 1\).

expected-count condition — the requirement that every expected value be at least five; when a category fails it, combine it with a neighboring category, which also reduces the number of cells by one.

right-tailed test — a test in which only large values of the statistic count as evidence against \(H_{0}\); the goodness-of-fit test is almost always right-tailed because a poor fit can only inflate the statistic.