<img src="https://d5nxst8fruw4z.cloudfront.net/atrk.gif?account=iA1Pi1a8Dy00ym" style="display:none" height="1" width="1" alt="" />

# 10.1: The Goodness-of-Fit Test

Difficulty Level: At Grade Created by: CK-12

## Learning Objectives

• Understand the difference between the chi-square distribution and Student’s \begin{align*}t\end{align*}-distribution.
• Identify the conditions which must be satisfied when using the chi-square test.
• Understand the features of experiments that allow goodness-of-fit tests to be used.
• Evaluate a hypothesis using the goodness-of-fit test.

## Introduction

In previous lessons, we learned that there are several different tests that we can use to analyze data and test hypotheses. The type of test that we choose depends on the data available and what question we are trying to answer. We analyze simple descriptive statistics, such as the mean, median, mode, and standard deviation to give us an idea of the distribution and to remove outliers, if necessary. We calculate probabilities to determine the likelihood of something happening. Finally, we use regression analysis to examine the relationship between two or more continuous variables.

However, there is another test that we have yet to cover. To analyze patterns between distinct categories, such as genders, political candidates, locations, or preferences, we use the chi-square 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

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.

Example: 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 \begin{align*}11^{\text{th}}\end{align*} grade students, we recorded the following information:

Frequency of Type of School Lunch Chosen by Students
Type of Lunch Observed Frequency Expected Frequency
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 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*}.

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

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.

### Evaluating Hypotheses Using the Goodness-of-Fit Test

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.

Frequency Which Student Select Type of School Lunch
Type of Lunch Observed Frequency Expected Frequency \begin{align*}\frac{(O-E)^2}{E}\end{align*}
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.

## Lesson Summary

We use the chi-square test to examine patterns between categorical variables, such as genders, political candidates, locations, or preferences.

There are two types of chi-square tests: the goodness-of-fit test and the test for independence. We use the goodness-of-fit test to estimate how closely a sample matches the expected distribution.

To test for significance, it helps to make a table detailing the observed and expected frequencies of the data sample. Using the standard chi-square distribution table, we are able to create criteria for accepting the null or alternative hypotheses for our research questions.

To test the null hypothesis, it is necessary to calculate the chi-square statistic, \begin{align*}\chi ^2\end{align*}. To calculate the chi-square statistic, we use the following formula:

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.

Using the chi-square statistic and the level of significance, we are able to determine whether to reject or fail to reject the null hypothesis and write a summary statement based on these results.

For a discussion on \begin{align*}P\end{align*}-value and an example of a chi-square goodness of fit test (7.0)(14.0)(18.0)(19.0), see APUS07, Example of a Chi-Square Goodness-of-Fit Test (8:45).

## Review Questions

1. What is the name of the statistical test used to analyze the patterns between two categorical variables?
1. Student’s \begin{align*}t\end{align*}-test
2. the ANOVA test
3. the chi-square test
4. the \begin{align*}z\end{align*}-score
2. There are two types of chi-square tests. Which type of chi-square test estimates how closely a sample matches an expected distribution?
1. the goodness-of-fit test
2. the test for independence
3. Which of the following is considered a categorical variable?
1. income
2. gender
3. height
4. weight
4. 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:
1. 125
2. 500
3. 250
4. 5
5. What is the formula for calculating the chi-square statistic?
6. 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?

On the Web

http://onlinestatbook.com/stat_sim/chisq_theor/index.html Explore what happens when you are using the chi-square statistic when the underlying population from which you are sampling does not follow a normal distribution.

## Date Created:

Feb 23, 2012

Aug 11, 2015
You can only attach files to section which belong to you
If you would like to associate files with this section, please make a copy first.