10.1: The Goodness-of-Fit Test
Learning Objectives
- Understand the difference between the Chi-Square distribution and the Student’s t-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 an 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. For example:
- 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; and
- We use regression analysis to examine the relationship between two or more continuous variables.
But what test do we run if we are trying to examine patterns between distinct categories such as gender, political candidates, locations or preferences? To analyze patterns like these we use the Chi-Square test.
The Chi-Square test is a statistical test used to examine patterns in distinct or categorical variables, which we learned about in the earlier chapter entitled Planning and Conducting an Experiment or Study. This test is used in:
- 1. Estimating how closely a sample matches the expected distribution (also known as the Goodness-of-Fit test) and
- 2. Estimating if two random variables are independent of one another (also known as the Test of Independence - see Chapter 9).
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 Goodness-of-Fit test is used to compare the observed values of a categorical variable with the expected values of that same variable. For example, we would use this test to analyze surveys that contained categorical variables (for example, gender, city of origin, or locations that people preferred to visit on vacation) to determine if there are in fact relationships between certain items.
Example: We would use the Chi-Square Goodness-of-Fit test to evaluate if there was a preference in the types 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 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 | ||
Sub Sandwich | ||
Daily Special | ||
Brought Own Lunch |
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 as if school lunch preferences were distributed equally, we divide the number of observations by the number of categories. Since there are observations and categories, the expected frequency of each category is or .
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. Or, if the difference between the two frequencies is big, then we expect the Chi-Square statistic to be large.
To calculate the Chi-Square statistic , we use the formula:
where:
Chi-Square statistical value
observed frequency value for each event
expected frequency value for each event
Once calculated, we take this Chi-Square value along with the degrees of freedom (this will be discussed later) and look up the Chi-Square value on a standard Chi-Square distribution table. The Chi-Square distribution allows us to determine the probability that a sample fits an expected pattern. In contrast, the t-distribution tests how likely it is that the means of two different samples will differ. Please see the table below for more details.
Type of Distribution | Tells Us | Every Day Example | Data Needed to Determine Value |
---|---|---|---|
Chi-Square | The relationship between two or more categorical variables. | Analyzing survey data with categorical variables. | Observed and expected frequencies for categorical variables, degrees of freedom. |
Student’s t-Test | The differences between the means of two groups with respect to a continuous variable. | Determining if there is a difference in the mean of the SAT scores between schools. | The mean values for samples from two populations, degrees of freedom. |
Features of the Goodness-of-Fit Test
As mentioned, the Goodness-of-Fit test is used to determine patterns of distinct or categorical variables. As we learned in Lesson 6, a categorical variable is one that is not continuous and has observations in separate categories. Examples of categorical variables include:
-gender (male or female)
-preferences (agreed, neutral or disagreed)
-behaviors (got sent to the office or didn’t get sent to the office)
-physical traits (straight, wavy or curly hair)
Categorical variables are not the same as measurement or continuous variables. The following are normally not categorical variables:
It is important to note that most of these continuous variables could in fact be converted to a categorical variable. For example, you could create a categorical variable with two values such as ¨Less that ¨ and ¨Greater than .¨
In addition to categorical variables, a Goodness-of-Fit test also requires:
-data obtained through a random sample
-a calculation of the Chi-Square statistic using the formula explained in the last section
-the calculation of the Degrees of Freedom. For a Chi-Square test, the Degrees of Freedom are equal to the number of categories minus one or
Using our example about the preferences of types of school lunches, we calculate the .
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 and 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 the game may not be fair.
Evaluating Hypothesis 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 states “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)
Using an alpha level of , we look under the column for and the row for Degrees of Freedom (remember the Degrees of Freedom = Number of categories ). Using the standard Chi-Square distribution table, we see that the critical value for Chi-Square is . Therefore we would reject the null hypothesis if the Chi-Square statistic is greater than .
Reject if
Using the table from above, we can calculate the Chi-Square statistic with relative ease.
Type of Lunch | Observed Frequency | Expected Frequency | |
---|---|---|---|
Salad | |||
Sub Sandwich | |||
Daily Special | |||
Brought Own Lunch | |||
Total (chi-square) |
Since our Chi-Square statistic of is greater than , 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.
As review, we follow the following steps to formulate and evaluate hypothesis:
- State the null and alternative hypothesis for the research question.
- Select the significance level and use the Chi-Square distribution table to write a rule for rejecting the null hypothesis.
- Calculate the value of the Chi-Square statistic.
- Determine whether to reject or fail to reject the null hypothesis and write a summary statement based on the results.
Lesson Summary
1. We use the Chi-Square test to examine patterns between categorical variables such as gender, political candidates, locations or preferences.
2. 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.
3. 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.
4. To test the null hypothesis it is necessary to calculate the Chi-Square statistic. To calculate the Chi-Square statistic , we use the formula:
where:
Chi-Square statistical value
observed frequency value
expected frequency value
5.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.
Supplemental Links
Distribution Tables (including the Student’s t-distribution and Chi-Square distribution)
http://www.statsoft.com/textbook/stathome.html?sttable.html&1
Review Questions
- What is the name of the statistical test used analyze the patterns between two categorical variables?
- the Student’s t-test
- the ANOVA test
- the Chi-Square test
- the z-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 observations in a data set and uniformly distributed categories that were being measured, the expected frequency for each category would be:
- What is the formula for calculating the Chi-Square statistic? The principal is planning a field trip. She samples a group of 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 | |
Play | |
Science Museum |
- What is the observed frequency value for the Science Museum category?
- What is the expected frequency value for the Sporting Event category?
- What would be the null hypothesis for the situation above?
- There is no preference between the types of field trips that students prefer
- There is a preference between the types of field trips that students prefer
- What would be the Chi-Square statistic for the research question above?
- If the estimated Chi-Square level of significance was , would you reject or fail to reject the null hypothesis?
Review Answers
- C
- A
- B
- A
- A
- (see table below)
Type of Field Trip | Observed Frequency | Expected Frequency | Chi-Square |
---|---|---|---|
Sporting Event | |||
Play | |||
Science Museum | |||
Chi-Square Total |
- Reject the Null Hypothesis