If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

# Chi-square statistic for hypothesis testing

AP.STATS:
DAT‑3 (EU)
,
DAT‑3.I (LO)
,
DAT‑3.I.1 (EK)
,
DAT‑3.J (LO)
,
DAT‑3.J.1 (EK)
,
DAT‑3.J.2 (EK)
,
VAR‑1 (EU)
,
VAR‑1.J (LO)
,
VAR‑1.J.1 (EK)
,
VAR‑8 (EU)
,
VAR‑8.A (LO)
,
VAR‑8.A.1 (EK)
,
VAR‑8.A.2 (EK)
,
VAR‑8.A.3 (EK)
,
VAR‑8.B (LO)
,
VAR‑8.B.1 (EK)
,
VAR‑8.C (LO)
,
VAR‑8.C.1 (EK)
,
VAR‑8.D (LO)
,
VAR‑8.D.1 (EK)
,
VAR‑8.F (LO)
,
VAR‑8.F.1 (EK)
,
VAR‑8.F.2 (EK)
,
VAR‑8.G (LO)
,
VAR‑8.G.1 (EK)

## Video transcript

let's say there's some type of standardized exam where every question on the test has four choices choice a choice B choice C and choice D and the test makers assure folks that over many years there's an equal probability that the correct answer for any one of the items is a B C or D essentially is a 25% chance of any of them now let's say you have a hunch that well maybe it is skewed towards one letter or another how could you test this well you could start with a null and alternative hypothesis and then we can actually do a hypothesis test so let's say that our null hypothesis is equal distribution equal distribution of correct choices correct choices or another way of thinking about it is a would be correct 25% of the time B would be correct 25% of the time C would be correct 25% of the time and D would be correct 25% of the time now what would be our alternative hypothesis where our alternative hypothesis would be not equal distribution not equal distribution now how are we going to actually test this well we've seen this show before at least the beginnings of the show you have the population of all of your potential items here and you could take a sample and so let's say we take a sample of 100 items so n is equal to 100 and let's write down the data that we get when we look at that sample so this is the correct choice correct choice and then this would be the expected number that you would expect and then this is the actual number and if this doesn't make sense yet we'll see it in a second so there's four different choices a B C D and a sample of 100 remember in any hypothesis test we start assuming that the null hypothesis is true so the expected number where a is a correct choice would be 25% of this hundred so you would expect 25 times the a to be the correct choice 25 times B to be the correct choice 20 five times C to be the correct choice and 25 times D to be the correct choice but let's say our actual results when we look at these hundred items we get that a is the correct choice 20 times B is the correct choice 20 times C is a correct choice 25 times and D is the correct choice 35 times so if you just look at this just like hey maybe there's a higher frequency of D but maybe you say well this is just a sample and just to random chance it might have just gotten more D's than not there's some probability of getting this result even assuming that the null hypothesis is true and that's the goal of these hypothesis test and say what's the probability of getting a result at least this extreme and if that probability is below some threshold then we tend to reject the null hypothesis and accept an alternative and those thresholds you have seen before we've seen these significance levels let's say we set a significance level of 5% 0.05 so if the probability of getting this result or something even more different than what's expected is less than the significance level then we'd reject the null hypothesis but this all leads to one really interesting question how do we calculate a probability of getting a result this extreme or more extreme how do we even measure that and this is where we're going to introduce a new statistic and also for many of you a new Greek letter and that is the capital Greek letter Chi which might look like an X to you but it's a little bit curvier and you could look up more on that you kind of curve that part of the X but it's a chi not an X and the statistic is called Chi squared and it's a way of taking the difference between the actual and the expected and translating that into a number and the chi-squared distribution is well I should really should say distributions are well studied and we can use that to figure out what is the probability of getting a result this extreme or more extreme and if that's lower than our significance level we reject the null hypothesis and it suggests the alternative but how do we calculate the chi-squared statistic here well it's reasonably intuitive what we do is for each of these categories in this case it's for each of these choices we look at the difference between the actual and the expected so for toy say we'd say 20 is the actual minus the expected and then we're going to square that and then we're going to divide by what was expected and then we're going to do that for choice B so we're going to say the actual was 20 expected is 25 so 20 minus 25 squared over the expected over 25 plus then we do that for choice C 25 minus 25 we know where that one will end up squared over the expected over 25 and then finally for choice D which is going to get us 35 minus 25 squared all of that over 25 and we are now let's see let's if we calculate this this is going to be negative 5 squared so that's going to be 25 this is going to be 25 this is going to be 0 35 minus 25 is 10 squared that is a hundred so this is one plus one plus 0 plus 4 so our chi-square statistic in this example came out nice and clean this won't always be the case at 6 so what do we make of this well what we can do is then look at a chi-squared distribution for the appropriate degrees of freedom and we'll talk about that in a second and say what is the probability of getting a chi-square statistic 6 or larger and to understand what a chi-squared distribution even looks like these are multiple chi-squared distributions for different values for the degrees of freedom and to calculate the degrees of freedom you look at the number of categories in this case we have 4 categories and you subtract 1 now that makes a lot of sense because if you knew how many a s B's and C's there are if you knew the proportions even the assumed proportions you can always calculate the fourth one that's why it is 4 minus 1 degrees of freedom so in this case our degrees of freedom are going to be equal to 3 over here sometimes you'll see it described as K so K is equal to 3 so if we look at that's that little light blue so we're looking at this chi-squared distribution where the degree of freedom is three and we want to figure out what is the probability of getting a chi-squared statistic that is six or greater so we would be looking at this area right over here and you could figure it out using a calculator or if you're taking some type of a test like an AP statistics exam for example you could use their tables they give you and so a table like this could be quite useful remember we're dealing with the situation where we have three degrees of freedom we had four categories so 4 minus 1 is 3 and we got a chi-squared value our chi-square statistic was 6 so this right over here tells us the probability of getting a 6 point 2 5 or greater for a chi-squared value is 10% if we go back to this chart we just learned that this probability from six point two five and up when we have three degrees of freedom that this right over here is 10% well that's 10% then the probability the probability of getting a chi-squared value greater than or equal to 6 is going to be greater than 10% greater than 10% and we could also view this as our p-value and so far probability assuming the null hypothesis is greater than 10% well it's definitely going to be greater than our significance level and because of that we will fail to reject fail to reject and so this is an example of even though in your sample you just happen to get more DS the probability of getting a result at least as Extreme as what you saw is going to be a little bit over 10%