Hello I’m Lindsey Leach and in this series of two videos we are going to be talking about
two common uses of the Chi square test. In this video, part I, I will show you how
to use the chi square goodness of fit test. You can use this test to see whether your
data for a single categorical variable follows a hypothesised distribution.
In part II, I will show you the chi square test for independence or the contingency chi
square test. You can use this test to see whether there is a relationship between two
categorical variables. Imagine I breed Labradors and you are coming
to see me to choose yourself a new member of the family – a beautiful Labrador pup.
You find that some of the pups are black, some are chocolate and some are yellow. They’re
all adorable – but still – it’s a tough decision.
So what’s the relevance of all this to the chi square test?
Well this is an example of a common situation where the variable of interest – in this
case Labrador coat colour – is categorical – it falls into one of several possible
groups. Now I tell you that I have 80 pups that I have raised by breeding together my
best black dogs. Most of them are black, but there are chocolate and yellow pups too. I
have a theory that coat colour is controlled by just two genes.
If this is true, I would expect to see a ratio of 9 black dogs to every 3 chocolate dogs
to every 4 yellow dogs. Don’t worry if you don’t know anything about genetics – just
take my word for it that if you know enough about the genes, you can work out what proportion
of the pups are expected to be black, chocolate or yellow. If my theory is right, the different
coloured pups in my collection should occur in the predicted ratio. In other words, my
null hypothesis is that there is no difference between the expected and observed frequencies
of colours. So, how do I test this hypothesis? I will start by laying out the data in a table
like this: Each pup colour is shown in a different column. In the first row, I have set out what
I expect to see if my null hypothesis is true. If there were 16 pups, I would expect to see
9 black, 3 chocolate, and 4 yellow. Scaling this up, then if there are 80 pups, then I
expect 45 black, 15 chocolate, and 20 yellow. In the second row, I have set out my how many
pups of each colour I have observed. You can see I have observed more black pups than I
expected. The question is whether this difference is small enough that I can ignore it and say
it was probably down to chance, or is this difference so big that it can be deemed statistically
significant? We first assess the difference between the
observed values and the expected values in a particular way. For each pup colour, I calculate
the square of the difference between the Expected and Observed values, and then scale that number
by the Expected value. For example, for black pups, we get 225/45, which is equal to 5.
So, if I want to know how much difference there is between Observed and Expected across
my whole dataset, then I can add the three numbers up to give 5 + 1 2/3 +5, which is
equal to 11 2/3. This is my chi square value. So what we have done there is simply to apply
the chi square formula, which is usually written out like this.
Now to reach a conclusion, I need to know if my chi square value of 11 2/3 is so large
that it is unlikely to have arisen by chance. To know that, I first need to know the degrees
of freedom, which is calculated as the number of categories minus 1. In this case, three
minus one is equal to two. Then I can go to the probability table for
the chi square distribution, which lists out the chi square values, called Critical Values,
for different probability levels shown in columns, and for various degrees of freedom
shown in the rows here. For example, at a probability level of 0.05, the critical value
is equal to 5.99, while at a probability value of 0.01, the critical value is equal to 9.21.
Then I can use the simple rule that if my chi square value is greater than the critical
value shown in the table, then I can reject the null hypothesis, otherwise I must accept
my null hypothesis. My value of 11 2/3 is greater than the value in the table of 9.21,
so there’s a less than 1% chance that I would see the value of 11 2/3 or higher if
my null hypothesis is true. Or, I could have used my computer to work out an exact p value
from the chi square value, which comes out as p equals 0.0029.
In other words, my hypothesis of a 9:3:4 ratio does not give a good fit to the data, so my
theory about the genetics must be wrong and it’s back to the drawing board for me...