In this Concept, you will learn how to understand the difference between the chisquare distribution and Student’s tdistribution. You will also learn how to evaluate a hypothesis using the goodnessoffit test.
Watch This
For a discussion on \begin{align*}P\end{align*} value and an example of a chisquare goodness of fit test (7.0)(14.0)(18.0)(19.0) , see APUS07, Example of a ChiSquare GoodnessofFit Test (8:45).
Guidance
To analyze patterns between distinct categories, such as genders, political candidates, locations, or preferences, we use the chisquare goodnessoffit test.
This test is used when estimating how closely a sample matches the expected distribution (also known as the goodnessoffit 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 goodnessoffit test and how to create and evaluate hypotheses using this test.
The ChiSquare Distribution
The chisquare distribution can be used to perform the goodnessoffit test , which compares the observed values of a categorical variable with the expected values of that same variable.
Example A
We would use the chisquare goodnessoffit 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 ChiSquare Statistic
The value that indicates the comparison between the observed and expected frequency is called the chisquare statistic . The idea is that if the observed frequency is close to the expected frequency, then the chisquare statistic will be small. On the other hand, if there is a substantial difference between the two frequencies, then we would expect the chisquare statistic to be large.
To calculate the chisquare 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 chisquare 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 chisquare value to determine the probability that a sample fits an expected pattern.
Features of the GoodnessofFit Test
As mentioned, the goodnessoffit 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 chisquare test is equal to the number of categories minus one. That is, \begin{align*}df=c1\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 &= 41\end{align*}
There are many situations that use the goodnessoffit test, including surveys, taste tests, and analysis of behaviors. Interestingly, goodnessoffit 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 goodnessoffit test to determine the likelihood that the player may be cheating or that the game may not be fair.
Evaluating Hypotheses Using the GoodnessofFit Test
Example B
Let’s use our original example to create and test a hypothesis using the goodnessoffit chisquare 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 chisquare 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 chisquare distribution table, we see that the critical value for chisquare is 7.815. Therefore, we would reject the null hypothesis if the chisquare statistic is greater than 7.815.
Note that we can calculate the chisquare statistic with relative ease.
Type of Lunch  Observed Frequency  Expected Frequency  \begin{align*}\frac{(OE)^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 (chisquare)  10.96 
Since our chisquare 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.
On the Web
http://tinyurl.com/3ypvj2h Follow this link to a table of chisquare values.
Example C
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.
b. Determine if the dice are fair (Use a chisquare goodness of fit test).
Solution:
a. 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)^{3k}\end{align*}
\begin{align*} & k && 0 && 1 && 2 &&3\\ & P(k) &&0.58 &&0.345 &&0.07 &&0.005 \end{align*}
b. 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 chisquare goodness of fit test is \begin{align*}\Sigma \frac{(OE)^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_1L_2)^2}{L_2}\right)\end{align*} .
Number of Fives  Observed Number of rolls  Expected Number of rolls  \begin{align*}\frac{(OE)^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 chisquare 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 chisquared 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.
Vocabulary
We use the chisquare test to examine patterns between categorical variables, such as genders, political candidates, locations, or preferences.
There are two types of chisquare tests: the goodnessoffit test and the test for independence . We use the goodnessoffit 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 chisquare 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 chisquare statistic , \begin{align*}\chi ^2\end{align*} . To calculate the chisquare statistic, 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 chisquare 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 chisquare 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.
Guided Practice
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, 1824 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 
Solution:
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{(OE)^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 chisquare statistic is 238.63 + 30.77 + 33.43 + 16.51 = 319.34 with 3 degrees of freedom. The pvalue is 0.00. The decision, at the 0.05 and 0.01 levels of significance, is to reject the null hypothesis. With a goodnessoffit 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.
Practice

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 chisquare test
 the \begin{align*}z\end{align*} score

There are two types of chisquare tests. Which type of chisquare test estimates how closely a sample matches an expected distribution?
 the goodnessoffit 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 chisquare 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 chisquare statistic for the research question above?
(e) If the estimated chisquare 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 chisquare statistic when the underlying population from which you are sampling does not follow a normal distribution.
 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 pvalue for the given chisquare 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 chisquare goodness of fit test.
 The chisquare statistic is negative.
 The chisquare statistic is 0.
 A 6sided 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 chisquare 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 chisquare distribution with 17 degrees of freedom, the probability that a value is greater than 20 is 0.7248.
 True or False: (if false rewrite so it is true). In a goodness of fit test, if the pvalue is 0.0113,

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 pvalue of the study is not small enough to reject the null hypothesis. Write this conclusion in the context of the situation.
 Now suppose the pvalue 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 1lb bags of M&Ms. Are the observed results statistically significant from the claim of the manufacturer.
Keywords
Chisquare distribution
Chisquare statistic
Contingency table
Degrees of freedom
Goodnessoffit test