Transcript for:
Understanding Chi-Squared Goodness of Fit Test

I want to talk to you about the chi-squared goodness of fit test. Like there's some 87% of statistics I made up on the spot. First, I want to do a revision of what's chi-squared independence testing. It can all fit right here. Just to remind you, because we're going to use some of these things, okay? So the null hypothesis, if we were, sorry, if we were checking for chi-squared independence, we made a null hypothesis, which was called H0. And we would state that blah, blah, blah, whatever that is, whatever that thing is, and blah blah blah are independent. That was one of our first thing we would do in the chi-squared independence testing. Then we would find the degrees of freedom. It helps to memorize this one here, so row minus one times column minus one. We would put the stuff into a matrix. We would do the chi-squared two-way test on that matrix, and then we would have these conditions. We would reject H0 if and we would have if p-value is less than the significance, if you'll get with me saying sig level, or if chi-squared is greater than your critical value. These were the conditions. We would use this. And then we would decide then if this thing right here was correct or not. We would test this hypothesis. So the whole idea then was to sort of check if those two things, whatever this is and whatever this is, are independent. So this is what we mean by chi-squared independence testing. Just to remind you, here is what we did. This is this chi-squared independence testing. Well, now what? Now we're going to do another kind of chi-squared, except it's called goodness of fit. So let's talk about that. It's called GOF for short, so GOF. So what we do is we want to test if it's a uniform distribution, or I like to say it follows what it's supposed to be. So we're going to have something with degrees of freedom. This is worth memorizing. It just goes n minus 1, where n is like your, I mean, this could be like your number of entries. So we're going to have lists now. So maybe we're going to have like a big list of numbers here. It's not going to be a matrix anymore. It's going to be a list. So you're going to be given some sort of list, and the numbers are here, this are here. There are n entries here. So that's what I mean by this. So however many entries are on the list, that's n. So that's your degrees of freedom. This right here you should memorize, especially for goodness of fit. So there is a little bit to memorize here. All right, well now what do we do? We have a null hypothesis as well. So we're going to have this thing right here. We're going to say h0 again. h0 is going to be the null hypothesis, and the alternate hypothesis will be h1. And this right here will be the null hypothesis here. So I'll put it in like this. This is the most important part right here. So the null hypothesis H0 is that the data satisfies some kind of uniform distribution. But what does that mean, uniform distribution? I think that's really hard to understand. So the way I like to think about it is it's how it's supposed to be. So we're going to see examples where you're going to check, are these two things the same? And you say, yep, they're the same. Or if you're rolling a die, then you can say, OK, it's a fair die. Or if we're looking at manufacturers'things, OK, it follows the manufacturer's specifications. So that's the way to state it. This is a generic way. But we can be specific. We can say, oh, it follows, you know, it's as it should be. And of course, an H1 is the opposite. So it does not satisfy it. So it does not go according to the specifications. Let me explain to you then how to do it. So this is going to tell us not if they're independent or not. It's going to tell us if they follow a uniform distribution, these lists here. So let me show you how to do it. How to do a chi-squared goodness of fit test. First step, we put the data into observed and expected frequencies into a list. Do you notice it's a list, not a matrix? Notice that. So in other words, you're going to have a list. So you're going to have a list of like, I don't know what you want to call it, like whatever your x column is, whatever your y column is. You're going to have these two different lists. You're going to have them, you somehow have to get them into your calculator. So on the Inspire, you go Lists, and then you name your columns. On TID4, you go Stats, Edit, and you put in L1 and L2. You just put in the stuff you know. I'll explain how to do that in a second. Then you calculate your degrees of freedom. You'll actually need this. So in this case, you hear the degree of freedom is just df equals n minus 1. In this case, you hear like how many terms are there? There's like 1, 2, 3, 4, 5. Okay, then it's 5 minus 1, so that's 4. Then we do this chi-squared goodness of fit test. So once you put them in the lists, then we go menu, stats, stats test, chi-squared goodness of fit. And same thing with the TID4 stats test on this. Then we reject or not. So we're still going to use something similar. Watch, we're still going to say, this is the good news, this thing that I was showing you before here, look right here, reject if this were here, that is the same. Maybe I'll put it in a big square or something like that. So this one right here, you know how we were supposed to reject if this happened? That right there is what you're supposed to know. Good news, same exact thing here. So here we're going to say reject. I'll just write it down as nicely as I can. So reject H0 if, and again, if the p-value is less than the significance level, significance level. Or if the chi-squared statistic is greater than the critical value. So maybe you're told that. So those are the two different ways to do it. So this is going to be the key. And by the way, guess what? You should memorize this again, but good news, if it's already memorized from chi-squared, that's good because it's the same. This is good to know. So this one right here, really important. You should know this. Again, memorized. But good news, hopefully it's already memorized. Alright, let's do an example then. So I've got Lego and they sell a box of assorted bricks and they should have the following distribution. So Lego tells you hey white ones there should be 20% white ones, it should be 30% blue, 10% green, 10% yellow, 20% black and 10% red. That's what they tell you it should be. Okay, so now you open a box of 500 pieces. Do you notice that this is 500? And you actually see these, do you notice these are observed frequencies? So you actually see 82, 91, 40, 90, 120, 77, they should add up to 500. Okay, now what? Well, the first step is to complete the table of expected frequencies. What would you expect? Well, do you see how, if there's, let's just look at what in theory there should be. If there were 500, do you notice though, this is the key thing here, there were 500 pieces. And 500 times, for example, whatever percent here we have. Okay, so I'll say 500 times whatever percent. That's how we're going to figure out what number we're going to have here. So how are we going to do this? This one right here then for white is going to be 500 times what? Well, it's going to be times 0.2. Does that make sense? This here is 500 times 0.3. This is 500 times, let's see, green is 0.1. See what I'm doing here? This is just actually kind of easy to figure out once you know this trick. You just figure it out like this. This is 500 times 0.2, and this is 500 times 0.1. So let's go ahead and figure these out. So what is 500 times 0.2? I mean, you can do it on your calculator if you need to. That's a 500 times 0.2. That's 0.1. 20% of 500. Well, 10% is 50, so twice that should be 100. Yep, it's 100. So we've got 100 here. That's the 20%. Now, good news, because this one is also 20%, that should be the same. Do you notice I can sort of already use that one? By the way, I also know about 10%. What's 10%? Isn't it half of this? So this should be 50. It also should make sense because 10% of this, I move the decimal over. So this is 50, so is that, and so is that. And then, let's see, I want this one here, 50. Well, 30% is gonna be 50 times three, so that should be 150. I double-check, does this actually add up? Let's see, 100 plus 150 is 250. This makes 300, 350, 450, 500. Yay, it adds up. So you notice then, we're done. All right, now we want, I like this, hey girl, you must be P greater than.05 because I failed to reject you. Because look, we're looking at the P value being less than the significance level is actually a pretty good joke. Anyway, so you carry out a chi-squared goodness of fit test at the 10% significance level. What's the null hypothesis? Remember what we always do? We go H0, and we're going to say this time maybe the data follows, instead of saying uniform distribution, I'll say data follows manufacturer's specifications. I think in this case that will make sense. In other words, it should be 20%, you know, so specifications. So see what we're doing. We're going to try to see. Hey, does this data really follow this? In other words, how close is it to the specification? Remember this says it should be 20%, 10%, all that stuff that they just said? So basically our null hypothesis is, all right, let's assume it does follow it. What's the degrees of freedom? Remember how that goes, df is just n minus 1. Well, what's n? How many values are there? There's 1, 2, 3, 4, 5, there's 6 different values. So it's going to be... 6 minus 1, so the degrees of freedom equals 5. All right, do you see how this actually isn't so bad? You just got to learn a few little tricks. Once you know them, you're fine. P value, how do I do that? I got to do this test in my calculator, don't I? So now let's go ahead and put all this in my calculator. What do I need to do? Well, I need to first put everything into a list, don't I? That's what I said to do. So let me go to open up a new page. I'll do a list and I'll name it. I'll name it maybe... I know exp for expected and I'll call observe, oops, maybe I'm not allowed to put that. Okay, fine. I'll say expected. Does that work? Yeah. And I'll say observed. All right, so there we go. So I've got a column called expected, a column called observed. Let's go ahead and do expected. Expected should be, well, 100, 150, 50. Oh no, never mind. Hold on, hold on. What am I doing? You know what I'm doing here? I'm doing it totally wrong. Why is that? Because I'm supposed to go down the list, aren't I? 100, then 150, then it's 50, then it's 50. I'm supposed to go down the list. 150. There we go. That's the expected. The observed is, let's see now, what we actually get is slightly different, right? It's 82. That's not 100, is it? This here is 91. It's not 150, but it's bigger. This is 40, 90, 120, and 77. See what we're going to use this test to tell us is, are we close enough to this? So here's the whole question, because clearly, can we agree these numbers are not the same as these? The question is, though, how much different are they? Do you see what we're trying to do? We're kind of trying to find some tolerances. We're trying to find out, hey, Are they similar enough? So that's what we're actually testing. We're going to see, basically, yes, these are clearly different than these, but are they too different? So in other words, do they follow the specifications at 10%? This is sort of what we're looking at here. So what do I do now that I've done all this? I go to Menu, and I go to Statistics, and I can say, give me a stat test. Oops, didn't mean to do that. So Menu, Statistics, Stat Test, and now I choose which one? Chi-squared Goff. Now it says where's my observed list? You notice it's asking where's my list for observed ones? So I'll say open that one please. Now use the right arrow and I say expected please. In the TID4 you'll use like L1 and L2. Just keep track of which one's which. Degrees of freedom. You have to tell it. That's why I had you calculate it. It's 5. And just say go do it. So what did it tell me? It told me my chi-squared value was 79. Did I need the chi-squared value? I only need the chi-squared value. if I'm going to be looking at a critical value. I don't have that here. So I actually don't care about that. I'm going to care about the p-value. Now notice it is not 1.34. Watch very, very carefully. It's not 1.34. It's actually 1.34 times 10 to the minus 15. Can you see that? That's the important part. Can you see this? So it's actually really, really small. So p-value is 1.34 times 10 to the minus 15. Just watch out for that because otherwise you might think, oh, it's 1.34. Great. No, no, no. It's 1.34 times 10 to the minus 15. So I'll put that in there. So p is 1.34 times 10 to the minus 15. Is that a big number or a small number? It is crazy small. Okay, so now I'm almost done. What conclusions can I make? Well, remember what I should conclude. I always just write it down, right? So reject. It's a good idea just to always practice. Reject h0 if... If p-value is less than the significance level, or if chi-squared is greater than the critical value. Do you notice, hopefully I'm getting slightly annoying by always writing this down. That's because it's important. I want you to learn this. All right, so we reject if this happens. So let's just double check, did this, whoa, did this really happen? So let's double check that, right? So let's see if this happened. So do I know the critical value? I don't, so that's why I ignore that number, or else I could have. I could have used a chi-squared, but I'm going to reject if, let's see, is p is 1.34 times 10 to the minus 15. Is that smaller than the significance level of 0.1? That's my question, see? Is it smaller? And the question is, yes, it is. So what does that mean I do? I'm going to write this down, so I'll say so. Therefore, I reject h0. So what does that really mean? That means... Data does not, don't notice them, so data does not follow the manufacturer's, I guess that's the way to say it, manufacturer's specifications. Specifications. So this is a conclusion I could make then. Do you notice? So this basically tells you, no, these do not fall within 10%, you know, tolerance, so to speak. So do you see why this is important? Because now you can say, ah, if you're buying this, you'd say, this isn't okay, these don't fit this. Because see, otherwise someone goes, yeah, well, they kind of do, they're close, like it's not close enough. Do you see that? That's how we could have stated this. So within a 10% significance level, this is not the case.