### The Chi-Square Distribution

To analyze patterns between distinct categories, such as genders, political candidates, locations, or preferences, we use the chi-square goodness-of-fit test.

This test is used when estimating how closely a sample matches the expected distribution (also known as the goodness-of-fit test) and when estimating if two random variables are independent of one another (also known as the test of independence).

In this lesson, we will learn more about the goodness-of-fit test and how to create and evaluate hypotheses using this test.

The **chi-square distribution** can be used to perform the **goodness-of-fit test**, which compares the observed values of a categorical variable with the expected values of that same variable.

#### Constructing a Contingency Table

We would use the chi-square goodness-of-fit test to evaluate if there was a preference in the type of lunch that \begin{align*}11^{\text{th}}\end{align*} grade students bought in the cafeteria. For this type of comparison, it helps to make a table to visualize the problem. We could construct the following table, known as a **contingency table**, to compare the observed and expected values.

Research Question: Do \begin{align*}11^{\text{th}}\end{align*} grade students prefer a certain type of lunch?

Using a sample of 100 \begin{align*}11^{\text{th}}\end{align*} grade students, we recorded the following information:

Type of Lunch |
Observed Frequency |
Expected Frequency |
---|---|---|

Salad | 21 | 25 |

Sub Sandwich | 29 | 25 |

Daily Special | 14 | 25 |

Brought Own Lunch | 36 | 25 |

If there is no difference in which type of lunch is preferred, we would expect the students to prefer each type of lunch equally. To calculate the expected frequency of each category when assuming school lunch preferences are distributed equally, we divide the number of observations by the number of categories. Since there are 100 observations and 4 categories, the expected frequency of each category is \begin{align*}\frac{100}{4}\end{align*}, or 25.

**The Chi-Square Statistic**

The value that indicates the comparison between the observed and expected frequency is called the **chi-square statistic**. The idea is that if the observed frequency is close to the expected frequency, then the chi-square statistic will be small. On the other hand, if there is a substantial difference between the two frequencies, then we would expect the chi-square statistic to be large.

To calculate the chi-square statistic, \begin{align*}\chi^2\end{align*}, we use the following formula:

\begin{align*}\chi^2=\sum_{} \frac{(O_{}-E_{})^2}{E_{}}\end{align*}

where:

\begin{align*}\chi^2\end{align*} is the chi-square test statistic.

\begin{align*}O_{}\end{align*} is the observed frequency value for each event.

\begin{align*}E_{}\end{align*} is the expected frequency value for each event.

We compare the value of the test statistic to a tabled chi-square value to determine the probability that a sample fits an expected pattern.

**Features of the** Goodness-of-Fit **Test**

As mentioned, the goodness-of-fit test is used to determine patterns of distinct categorical variables. The test requires that the data are obtained through a random sample. The number of **degrees of freedom** associated with a particular chi-square test is equal to the number of categories minus one. That is, \begin{align*}df=c-1\end{align*}.

Using our example about the preferences for types of school lunches, we calculate the degrees of freedom as follows:

\begin{align*}df &= \text{number of categories}-1\\ 3 &= 4-1\end{align*}

There are many situations that use the goodness-of-fit test, including surveys, taste tests, and analysis of behaviors. Interestingly, goodness-of-fit tests are also used in casinos to determine if there is cheating in games of chance, such as cards or dice. For example, if a certain card or number on a die shows up more than expected (a high observed frequency compared to the expected frequency), officials use the goodness-of-fit test to determine the likelihood that the player may be cheating or that the game may not be fair.

**Testing Hypotheses **

Let’s use our original example to create and test a hypothesis using the goodness-of-fit chi-square test. First, we will need to state the null and alternative hypotheses for our research question. Since our research question asks, “Do \begin{align*}11^{\text{th}}\end{align*} grade students prefer a certain type of lunch?” our null hypothesis for the chi-square test would state that there is no difference between the observed and the expected frequencies. Therefore, our alternative hypothesis would state that there is a significant difference between the observed and expected frequencies.

Null Hypothesis

\begin{align*}H_0: O=E\end{align*} (There is no statistically significant difference between observed and expected frequencies.)

Alternative Hypothesis

\begin{align*}H_a:O \neq E\end{align*} (There is a statistically significant difference between observed and expected frequencies.)

Also, the number of degrees of freedom for this test is 3.

Using an alpha level of 0.05, we look under the column for 0.05 and the row for degrees of freedom, which, again, is 3. According to the standard chi-square distribution table, we see that the critical value for chi-square is 7.815. Therefore, we would reject the null hypothesis if the chi-square statistic is greater than 7.815.

Note that we can calculate the chi-square statistic with relative ease.

Type of Lunch |
Observed Frequency |
Expected Frequency |
\begin{align*}\frac{(O-E)^2}{E}\end{align*} |
---|---|---|---|

Salad | 21 | 25 | 0.64 |

Sub Sandwich | 29 | 25 | 0.64 |

Daily Special | 14 | 25 | 4.84 |

Brought Own Lunch | 36 | 25 | 4.84 |

Total (chi-square) | 10.96 |

Since our chi-square statistic of 10.96 is greater than 7.815, we reject the null hypotheses and accept the alternative hypothesis. Therefore, we can conclude that there is a significant difference between the types of lunches that \begin{align*}11^{\text{th}}\end{align*} grade students prefer.

#### Using the Chi-Square Goodness of Fit Test

A game involves rolling 3 dice. The winnings are directly proportional to the number of fives rolled. Suppose someone plays the game 100 times with the following observed counts:

Number of Fives |
Observed Number of rolls |
---|---|

0 | 48 |

1 | 35 |

2 | 15 |

3 | 2 |

Someone becomes suspicious and wants to determine whether the dice are fair.

If the dice are fair the probability of rolling a 5 is 1/6. If we roll 3 dice, independently then the number fives in three rolls is distributed as a Binomial (3,1/6).

a. Determine the probability of 0, 1, 2 and 3 fives under this distribution.

Since we have a binomial distribution with 3 independent trials and probability of success 1/6 on each trial, we can compute the probabilities using either the TI Calculator binompdf(3,1/6, k) where k represents the particular value in which we are interested or we can use the formula

\begin{align*}P(k){3 \choose k}\left(\frac{1}{6}\right)^k \left(\frac{5}{6}\right)^{3-k}\end{align*}

\begin{align*} & k && 0 && 1 && 2 &&3\\ & P(k) &&0.58 &&0.345 &&0.07 &&0.005 \end{align*}

b. Determine if the dice are fair (Use a chi-square goodness of fit test).

First you must find the expected number of rolls for each category. To do this, multiply the probability of each category by 100. For example, the expected number of rolls where you observe zero 5's is \begin{align*}0.5787\cdot 100 = 57.87\end{align*}. The formula for the chi-square goodness of fit test is \begin{align*}\Sigma \frac{(O-E)^2}{E}\end{align*} where \begin{align*}O\end{align*} represents the observed and E represents the expected. You can do this calculation on the TI Calculator by putting the observed values in List 1, the Expected values in List 2, and in List 3 put \begin{align*}\left(\frac{(L_1-L_2)^2}{L_2}\right)\end{align*}.

Number of Fives |
Observed Number of rolls |
Expected Number of rolls |
\begin{align*}\frac{(O-E)^2}{E}\end{align*} |
---|---|---|---|

0 | 48 | 58 | 1.72 |

1 | 35 | 34.5 | 0.007 |

2 | 15 | 7 | 9.14 |

3 | 2 | 0.5 | 4.5 |

You then sum the values in List 3. This will be the value of your chi-square statistic:

\begin{align*}\chi^2=1.72+0.007+9.14+4.5=15.367\end{align*}

In the previous example, we saw that the critical value for a chi-squared statistic at the 0.05 level of significance is 7.815. Since \begin{align*}\chi^2=15.367>7.815\end{align*}, at the .05 level of significance, we can reject the null hypothesis and conclude that the dice are not fair.

### Example

#### Example 1

The marital status distribution of the U.S. Female population, age 18 and older, is as shown below.

Marital Status |
Proportion |
---|---|

Never married | 0.227 |

Married | 0.557 |

Widowed | 0.98 |

Divorced/separated | 0.117 |

(Source: US Census Bureau, “America’s Families and Living Arrangements, 2008)

Suppose a random sample of 400 US young adult females, 18-24 years old, yielded the following frequency distribution. Does this age group of females fit the distribution of the US adult population?

Marital Status |
Frequency |
---|---|

Never married | 238 |

Married | 140 |

Widowed | 3 |

Divorced/separated | 19 |

In this problem you determine the expect number for each category by multiplying the proportion by 400, the total number of people in the study.

Marital Status |
Observed |
Expected |
\begin{align*}\frac{(O-E)^2}{E}\end{align*} |
---|---|---|---|

Never married | 238 | 90.8 | 238.63 |

Married | 140 | 222.8 | 30.77 |

Widowed | 3 | 39.2 | 33.43 |

Divorced/separated | 19 | 46.8 | 16.51 |

The chi-square statistic is 238.63 + 30.77 + 33.43 + 16.51 = 319.34 with 3 degrees of freedom. The p-value is 0.00. The decision, at the 0.05 and 0.01 levels of significance, is to reject the null hypothesis. With a goodness-of-fit test, the null hypothesis is always that the two data sets have the same distribution. Since we are rejecting the null hypothesis, this means that this age group of young adult females does not fit the distribution of the US adult population.

### Review

- What is the name of the statistical test used to analyze the patterns between two categorical variables?
- Student’s \begin{align*}t\end{align*}-test
- the ANOVA test
- the chi-square test
- the \begin{align*}z\end{align*}-score

- There are two types of chi-square tests. Which type of chi-square test estimates how closely a sample matches an expected distribution?
- the goodness-of-fit test
- the test for independence

- Which of the following is considered a categorical variable?
- income
- gender
- height
- weight

- If there were 250 observations in a data set and 2 uniformly distributed categories that were being measured, the expected frequency for each category would be:
- 125
- 500
- 250
- 5

- What is the formula for calculating the chi-square statistic?
- A principal is planning a field trip. She samples a group of 100 students to see if they prefer a sporting event, a play at the local college, or a science museum. She records the following results:

Type of Field Trip |
Number Preferring |
---|---|

Sporting Event | 53 |

Play | 18 |

Science Museum | 29 |

(a) What is the observed frequency value for the Science Museum category?

(b) What is the expected frequency value for the Sporting Event category?

(c) What would be the null hypothesis for the situation above?

(i) There is no preference between the types of field trips that students prefer.

(ii) There is a preference between the types of field trips that students prefer.

(d) What would be the chi-square statistic for the research question above?

(e) If the estimated chi-square level of significance was 5.99, would you reject or fail to reject the null hypothesis?

- In 1982 in Western Australia, 1317 males and 854 females died of heart disease, 1119 males and 828 females died of cancer, 371 males and 460 females died of cerebral vascular disease and 346 males and 147 females died of accidents. (source: www.statsci.org/data/z/deathwa.html) Put this information into a contingency table.
- For each of the following situations, give the p-value for the given chi-square statistic.
- \begin{align*}\chi^2=3.84, df=1\end{align*}
- \begin{align*}\chi^2=6.7\end{align*} for a table with 3 rows and 3 columns
- \begin{align*}\chi^2=26.23\end{align*} for a table with 2 rows and 3 columns

- Determine the critical value in each of the following situations.
- Level of significance is 05, degrees of freedom = 1
- Level of significance is 0.01; table has 3 rows and 4 columns
- Level of significance is 0.05, degrees of freedom = 8

- For each of the following situations determine if the result is statistically significant at the 0.5 level.
- \begin{align*}\chi^2=2.89, df=1\end{align*}
- \begin{align*}\chi^2=23.60, df=4\end{align*}

- Are the situations in problem 10 statistically significant at the .01 level?
- In the following situations, give the expected count for each of the k categories:
- \begin{align*}k=3, H_0:p_1=p_2=p_3=1/3, n=300\end{align*}
- \begin{align*}k=3, H_0:p_1=1/4, p_2=1/4, p_3=1/2, n=1000\end{align*}

- Explain whether each of these is possible in a chi-square goodness of fit test.
- The chi-square statistic is negative.
- The chi-square statistic is 0.

- A 6-sided die is rolled 120 times. Conduct a hypothesis test to determine if the die is fair. The data below are the result of the 120 rolls.

Face Value |
Frequency |
---|---|

1 | 29 |

2 | 15 |

3 | 15 |

4 | 16 |

5 | 15 |

6 | 30 |

- True or False: (if false rewrite so it is true). As the degrees of freedom increase, the graph of the chi-square distribution looks more and more symmetrical.
- True or False: (if false rewrite so it is true). In a goodness of fit test the expected values are the values we would expect if the null hypothesis were true.
- True or False: (if false rewrite so it is true). Use a goodness of fit test to determine if high school principals believe that students are absent equally during the week or not.
- True or False: (if false rewrite so it is true). For a chi-square distribution with 17 degrees of freedom, the probability that a value is greater than 20 is 0.7248.
- Suppose an investigator conducts a study of the relationship between gender (male or female) and book preference (fiction or nonfiction) of children 12 years old.
- Suppose the p-value of the study is not small enough to reject the null hypothesis. Write this conclusion in the context of the situation.
- Now suppose the p-value of the study is small enough to reject the null hypothesis. In the context of the situation, express the conclusion in two different ways.

- Suppose a car dealer offers cars in three different colors: silver, black and white. In a sample of 111 buyers, 59 chose black, 25 chose silver and the remainder chose white. Is there sufficient evidence to conclude that the colors are not equally preferred? Carry out a significance test and be sure to state the null hypothesis and the population to which your conclusion applies.
- The manufacturer of M&Ms states, on the website, the color distribution of M&Ms. Access the website to discover the claim of the manufacturer. Purchase and combine a number of 1-lb bags of M&Ms. Are the observed results statistically significant from the claim of the manufacturer.

### Review (Answers)

To view the Review answers, open this PDF file and look for section 10.1.