This tutorial will cover chi-square test for goodness of fit. You’ll learn about:
The chi-square distribution is a good place to start.
The chi-square distribution is a skewed to the right distribution that measures, generally, discrepancy from what a sample of categorical data would look like if you had an idea of what the population should look like in those categories.
The p-value is always the area in the chi-square distribution to the left of your particular chi-square statistic that we end up calculating. The values on the left (low values of chi-square) are likely to happen by chance, and high values of chi-square are unlikely to happen by chance.
The degrees of freedom for the chi-square distribution is the number of categories minus 1. Just like the T distribution, the chi-square distribution is actually a family of curves. The shape changes a little bit, based on the degrees of freedom, but it's always skewed to the right.
The conditions for using that chi-square distribution are:
So how large is considered a large sample? In this case, all the expected counts have to be at least 5.
When should you perform a Chi-Square Goodness-Of-Fit Test?
It's easiest to practice in an example.
In the book Outliers, Malcolm Gladwell outlines a trend that he finds in professional hockey, related to birth month.
Here is a distribution of the number of hockey players born in a particular month.
Is this this what you would expect, given the general population?
It certainly appears that the earlier months of the year have larger numbers of NHL players born in them, which is not very consistent with the nearly uniform distribution of the population. What you would have expected is that, of those 512 professional hockey players, 8% of them would have been born in January, 7% of them would have been born in February, and etc.
So it looks like this:
You would have expected 9% of the players to have been born in each of July, August, September, October, and December. And so all of those expected values are 46.08. However, apparently just 30 were born in December. The same as the distribution for everyone who was born in, in that case, Canada, because it's Canadian hockey players.
Choose a significance level of 5%. If you get a p-value below 0.05, we'll reject the null hypothesis. Take a look at the conditions:
So what you're going to do is to calculate your chi-square statistic. The chi-square statistic is going to be the observed minus the expected for each month squared, divided by the expected for each month.
When you add all of those components together, you get the chi-square value of 34.21. In this case, it's also a good idea to state that the degrees of freedom was 11 degrees of freedom.
There were 512 hockey players, but there were 12 categories. The degrees of freedom is the number of categories minus 1.
The p-value obtained from technology -- most of the time we calculate the p-values and the test statistic using technology -- is 0.00033. That's a low p-value, less than 0.05. Since your p-value is low, you can't attribute the difference to chance.
This means that you must reject the null hypothesis in favor of the alternative and conclude that the distribution of birth months for professional hockey players differs significantly from the birth month distribution for the general populace.
The chi-square statistic is a measure of discrepancy across categories from what we would have expected in our categorical data. The expected values might not be whole numbers, since each expected value is a long term average. The chi-square distribution is a skewed right distribution, and chi-square statistics near zero are more common if the null hypothesis is true. The Goodness-Of-Fit Test is used to see if the distribution across categories for data fit a hypothesized distribution across categories.
Thank you and good luck!
Source: THIS WORK IS ADAPTED FROM SOPHIA AUTHOR JONATHAN OSTERS
A hypothesis test where we test whether or not our sample distribution of frequencies across categories fits with hypothesized probabilities for each category.