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.

## Statistics and probability

### Course: Statistics and probability>Unit 14

Lesson 1: Chi-square goodness-of-fit tests

# Pearson's chi square test (goodness of fit)

Sal uses the chi square test to the hypothesis that the owner's distribution is correct. Created by Sal Khan.

## Want to join the conversation?

• In the previous video introducing chi squared, you indicated that the curve for k = 3 corresponds to the distribution of the sum of three squared samples from the standard normal. In this video, you indicate that the curve corresponding to the sum of 6 squared samples is k = 5, because now we must consider "degrees of freedom." If this is the case, then a chi squared test based on two squared differences of samples (perhaps corresponding to customers coming in only on Friday and Saturday) would be based on the k = 1 curve, which seems wrong to me. Can you explain?
• To calculate the degrees of freedom (df) for a Chi-Squared Test can be done as follows;

For a two-way table
df = (m - 1)(n - 1) // where m = # of columns & n = # of rows

For a one way table
df = k - 1 // where k equals the number of groups

So in short, yes; in a one way table that deals with 2 groups will correspond to 1 degree(s) of freedom.

Hope this helps,
- Convenient Colleague
• A few things were unclear to me here. First, is chi squared always calculated as a difference between expected and observed divided by expected? Where is the derivation or explanation of this?

Secondly, in what scenarios should we use chi-squared vs. other statistics? Is there a limit on number of data points (or in other words, degrees of freedom) for this calculation? I think there should be more explanation on the use cases for this statistic and how its calculated.
• I understand that if the chi-square value exceeds the appropriate minimum value in the chi-square distribution table, taken into account the degrees of freedom, you can reject the null hypothesis. (And that the same is true of the reverse, if the chi-square value does not exceed the appropriate minimum value in the chi-square distribution you will accept the null hypothesis). Can some explain to me why this is? I do not understand the theory about the minimum chi-square value to understand why we reject a chi-square value that exceeds the value in the distribution table.
• The question you answer with the test can be rephrased like this: "if the shop owner's theory is right (i.e. what percentage of customers come each day), what is then the probability to see the given observations (30 on monday, 14 on Tuesday, etc) or something more unlikely?"
This is the question you answer with the test, and you can calculate that probability exactly (or you can use tables). In this case it is just below 5%.
So, if the hypothesis is right and you make observations for for a weak, then there is almost 5% chance that you see what you see or something even less likely.
The 5% significance criteria is a subjective choice. Some use 1%, some 5%, some 0.5%. If I generally trusted the shop owner, and new that he had kept track of customers for a long period, and was a clever guy, then I would still believe his hypothesis. I mean, after all, 5% corresponds to about 1/20 - it is not a veeery rare observation. On the other hand, if I knew the shop owner was sloppy with numbers, and had a tendency to lie, etc., then I would be more likely to reject the hypothesis on basis of my observations. However, before I confronted him, I think I would observe another week to get more certain knowledge.

A lot of talking, sorry! My point here: you get the probability from the test. That is your result! What significance level to chose depends on the situation. Sometimes it might be life changing - if it was a test for some disease, I would never be satisfied with a 5% risk. Say, the docter tells me: there is only a 5% chance that you have that life threatening disease, given the test result, so you can go home. Then I would ask for another test! But if I was in the line for a super discount offer on black friday, and a clever person had calculated that there were only 5% chance that I would get the item before it was sold out, then I would step out of the line immediately. It depends on consequences, risk, what I already know and many other things!

• Had we counted legs of visitors instead of visitors, and assuming each has two, our chi-squared would be twice bigger for the same effective statistical question. It is thus incorrect to count legs. They indeed do not get odd values. It also seems that values which are not discrete, such as ammoung of food eaten each day, will result differently depending on the physical units of mass. It is thus also incorrect to use continbuous random variables for chi-statistics?
• This is an intersting question. I don't really know.
But I want to say, that if, say John has two legs, if his two legs has independent random choices( say one leg accatully comes to the resturant at Monday, the other at Friday ), not always making the same decision, then it will make sense to count legs. If not, I don't think you can count legs, Jo.
• How the formula we get, Chi-square = Sum of all (Observed frequency-Expected frequency)2 / Expected frequency
• Can someone introduce me a Statistics book that is written in plain English, in a way that a novice like me can understand and apply in real, practical situtation. Also if it can give me some insights and intuative feelings why statistics tests are the ways they are. It's even better. Thanks a lot!
• I've never read through it myself, but I've heard a lot of people say great things about "The Cartoon Guide to Statistics", by Gonick and Smith. I don't think it has any actual examples, but it is so strong on the plain English and intuition that you might be able to make better sense of your statistic textbook afterwards.
• what is a brain fitness test?
• Would I be correct in assuming that there is a software program which is able to do all this math for us? Here we just have a few data points. How could a human mind do all the calculations for data points which number in the 1,000s or even billions?
• (This is Spencer's mother) Julius, there are several software programs that can do statistical analysis and MS Excel is probably the one that most students would have access to quickly. "R" is a free program as is PSPP (a variant of SPSS) and there are a few others (STATA/SAS) but these require writing code. (SPSS will allow drag and drop) but I think the most efficient way to learn this would be in excel. You would need to use the 'add-in' for data analysis, but Excel can do lots of statistical analysis (and by the way, provides the critical value at which the null is rejected) in the the descriptive statistics. You should try it! There are lots of free data sets available in CSV format that you can download and play with!
• Are the charts mentioned at the marker something that is given or would I have to fill it in myself while solving the problem. If so, how would i go about doing that?