10.1: The Goodness-of-Fit Test
Learning Objectives
- Understand the difference between the chi-square distribution and Student’s -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 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 grade students prefer a certain type of lunch?
Using a sample of 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 , 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, , we use the following formula:
where:
is the chi-square test statistic.
is the observed frequency value for each event.
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, .
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 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
(There is no statistically significant difference between observed and expected frequencies.)
Alternative Hypothesis
(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 | |
---|---|---|---|
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 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, . To calculate the chi-square statistic, we use the following formula:
where:
is the chi-square test statistic.
is the observed frequency value for each event.
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.
Multimedia Links
For a discussion on -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).
Follow this link to a table of chi-square values: http://tinyurl.com/3ypvj2h
Review Questions
- What is the name of the statistical test used to analyze the patterns between two categorical variables?
- Student’s -test
- the ANOVA test
- the chi-square test
- the -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?
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.
Image Attributions
To add resources, you must be the owner of the section. Click Customize to make your own copy.