+

# Chi-Square Test for Goodness-of-Fit ##### Rating:
(7)
• (3)
• (3)
• (0)
• (0)
• (1)
Author: Ryan Backman
##### Description:

Calculate a chi-square test statistic for a chi-square test of goodness-of-fit.

(more)
Tutorial

## Video Transcription

Download PDF

Hi. This tutorial covers the chi-square test for goodness-of-fit. All right, so let's start by defining it. So a chi-square test for goodness of fit is a method of testing the fit of three or more category proportions to a specified distribution. So let's take a look at the four-step procedure for this type of test.

OK, step 1 is to formulate the null and alternative hypotheses and choose the significance level. The null hypothesis is that the population distribution matches a specified distribution, and the alternative hypothesis is that it does not. So a lot of times when we write our alternate hypothesis, we'll just simply say that the null is not true.

Step 2, like always, check the conditions of the test. Three conditions here. Data comes from a random sample. All expected counts are at least 5. And the individual observations are independent. Step 3 is where we actually calculate the test statistic-- in this case, it's chi-squared-- and we find the p-value. And the fourth step is to decide whether to reject or not the null hypothesis and draw a conclusion.

So let's take a look at an example and then go ahead, go back, and do the four steps. So there are four flavors of candy in a bag, cherry, lemon, orange, and strawberry. The candy company claims the flavors are equally distributed in each bag. I have reason to disagree.

After opening a bag of candy and sorting the flavors, the following counts were produced. So we got 11 cherry, 15 lemon, 12 orange, and 12 strawberry. It always seems like there's the most lemon. That's my least favorite, so I kind of want to check to see if I have evidence to show that they're not equally distributed.

So let's take a look at the four steps. So let's start with writing hypotheses and choosing a significance level. So just like always, I'm going to have a null hypothesis and an alternative hypothesis. So what I want to do is I want to show that my null hypothesis is that the specified distribution is going to be a distribution where all the flavor proportions are the same.

So I have four flavors, so I'm going to have four proportions, and I want all four of those proportions to be equal. If these proportions are equal, then I know that the flavors are equally distributed. And my alternative hypothesis is simply that the null hypothesis is false. And I also need to choose a significance level. I'm going to use a 5% significance level, so alpha equals 0.05. That means that my likelihood of making a type I error is only 5%.

I'm now going to check my conditions. One, data comes from a random sample. I can probably assume that the bag of candy was filled randomly, so I'm going to assume that that first condition is met. All expected counts are at least 5. So this is where I need to actually calculate my expected counts. So my expected counts are always going to be what the frequencies would be if my null hypothesis were true.

So basically, if all my flavor proportions are equal, I need to figure out then how many I would expect to be in each category. So I'm going to just write down my observed frequencies and then I'm going to calculate my expected frequencies. So my observed counts were 11, 15, 15, and 12. So in order to calculate my expected counts, I need to add up these four values. And if I add those up, I'm going to get 50.

Now, if I'm assuming that all of these four flavors are equally distributed, that means I'd need to just take this 50 and divide it up evenly among the four categories. If I did so, I would have 12.5 in each category. So even though it's not possible to have 12 and 1/2 candies in a bag, this is still a meaningful number.

So remember what I was trying to do is look to see that all expected counts were at least 5. They certainly are. I had 12 and 1/2 for each, so that's check. And individual observations are independent. So me counting up those candies-- the flavor of one candy does not have an influence on the flavor of the next candy, so this one is also good . So my conditions are met, so I can go ahead and continue with my test.

The next one is to calculate the test statistic, chi-squared, and find the p-value. Remember that the formula for chi-squared was the sum of your observed counts minus your expected counts-- that quantity squared-- divided by the expected counts. So I need to calculate this for each category and then I'm going to take the sum of each.

And I'm going to just do that in my calculator. So ahead of time, I typed in my observed counts and my expected counts. I'm going to go over to this new list and I'm going to type in a formula for this list.

So I want my observed minus my expected. My observed values are in my first list, so I'm going to go my first list. My expected counts are in my second list, so I'm going to do L2 minus L1-- List 1 minus List 2. Now I'm going to close my parentheses and square it, and then I'm going to divide by my expected counts, which again, are in the list 2.

And that's going to give me the values that will contribute to chi-squared. Now what I need to do is find a sum, so I'm going to do that on the calculator, also. I'm going to go ahead and pick my sum function. So I'm going to do the sum. And now the values that contribute to chi-squared were all in L3. So I'm going to do the sum of all three, hit Enter, and I get 0.72. So that is what my chi-squared value Is So chi-squared is 0.72.

Now to interpret that value, it's important to calculate a p-value that corresponds to my chi-squared value, because remember, chi-squared is already a test statistic, so no need to further convert it. Now I can use that to find a p-value. Again, I'll use my calculator. I'm going to use a function called chi-squared CDF, which is here. I'm going to hit Enter there.

I'm going to type in my chi-squared value. Chi-squared tests are always upper-tailed tests, so I'm going to do my large positive value there to represent positive infinity. And then my third argument here is my degrees of freedom. In a goodness-of-fit test, your degrees of freedom is always the number of categories minus 1. So my third argument I'm going to put in there is a 3.

OK. I'll hit Enter, and I end up with a p-value of 0.868, which we know is very high. And if we compare that to that level of alpha we picked before, our p-value is certainly much greater than our alpha value of 0.05.

So now let's go ahead and make our final decision whether to reject or fail to reject and then draw up a conclusion. So what I'm going to say is that since p-value was greater than alpha, fail to reject the null And what that means is that there is not significant evidence to conclude that the flavors are not equally distributed.

So again, since the p-value is greater than 0-- or sorry, greater than alpha, fail to reject the null. So there is not significant evidence to conclude that the flavors are not equally distributed. So we have no evidence against the company's claim that they are equally distributed.

That has been the tutorial on the chi-squared test of goodness-of-fit. Thanks for watching.

Terms to Know
Chi-Square Test for Goodness-of-Fit

A hypothesis test where we test whether or not our sample distribution of frequencies across categories fits with hypothesized probabilities for each category.

Formulas to Know
Chi-Square Statistic Rating Header