 This is the chi-square goodness of fit tests using Excel. I love M&Ms. A while back I read on the manufacturer's website that their theoretical distribution of colors in a typical bag is 24% blue, 13% brown, 16% green, 20% orange, 13 and 14 respectively. So being a statistician, I thought, I'm gonna check that. So I bought some boxes of M&Ms and I counted the colors. The chi-square test of course is a hypothesis test and we always must state our null and our alternative. Here the null is always that the distributions are the same. The theoretical, the plan distribution is the same as what I'm gonna measure. The alternative is that the distributions are different. Either one of those can be the claim. Let's go ahead and look at Excel. You can see I've done some preliminary work here to set this up, but I'll walk through step by step so you see how I did it. I just copied over the column A, which is the colors and added a total down here. These are the counts. When I investigated several bags, these are the average counts. The average was 55 in a bag and these were the actual distribution I found. Here is the plan copied over and we need to develop this column, which is the expected count if this plan were followed. And that cell, we have the formula there, is just C2, which was the percentage for blue multiplied times the total. And of course, we use the F4 key to get the double dollar signs and lock that cell down so I can drag it. And so that's all I do is just drag that formula down and that gives me my expected counts if this plan were followed. In this part of the spreadsheet, I've entered my alpha, my confidence significance level of 0.05. We needed the count of categories. Obviously, in this example with just six, you could just count them. But you can set it up to use the count function and put in the range and it will count that for you. Degrees of freedom is just the count minus one. The p-value, the probability of getting this actual, this observed distribution if the null is correct, that this is the plan is 0.03, which is less than our alpha. Therefore, we reject the null. But we get that using the chi-square-test function. Its arguments are the observations and the expected. I'm gonna click in that cell so you can see there's the function and you can get that by just typing in equal, start typing chi and it'll be offered a number of things. The actual range is this observed column there from B2 to B9, put a comma to separate those and then put in the expected range from D2 to D7 and close it with the parentheses. And that gives you the p-value. Once you get the p-value, you can get the test statistic down here using another chi-square function. This was the invert right tail. Remember for the chi-square test, we're always interested in the right tail probabilities. And you just enter into it the p-value that you just got and the degrees of freedom. And you can see there how that works. Start typing chi-square.inverse.rt and then enter the two arguments, probability and degrees of freedom. The critical value is another chi-square invert right tail but in this case, you put in the alpha value that you want which is the 0.05 and degrees of freedom. So you can see that in this case, the p-value says to reject the null and then the critical value is smaller than the test statistic and that's always what you look for when you're doing a chi-square. Therefore, both of those tell you to reject the null.