The chi-squared (c2) test is a measure of expected frequency versus observed frequency to determine how closely aligned they are; whether what is observed would be expected or whether it is different to what would be expected.
The default expectation is the null hypothesis which states that no difference exists between the things we are experimenting with, observing or comparing and their default, or control state.
The chi-squared value we obtain from the chi-squared test is put against a probability scale. The probability refers to the probability that for a given chi-squared value (which is defined by how different our observation is from what we would expect), what we observe really is different to what we expect to a significant extent that enables us to reject the null hypothesis.
For example, our expected values for the eye colour of 154 flies in a population would be:
Eye colour: 77 white and 77 red
The expected values cannot be below 1 for the chi-squared test.
Say our study reveals that in fact there are:
Eye colour: 98 white and 56 red
The way to carry out a chi-squared test is to take the difference between the observed (O) and expected (E) values, square it, and then divide by the expected number (E). This is done for both categories and then added together for the final chi-squared value. The extra 0.5 taken away is know as the Yates correction and is used if our comparison only has two groups.
(O-E-0.5)2 / E for white = (98-77-0.5)2 / 77
(O-E-0.5)2 / E for red = (56-77-0.5)2 / 77
We then add the two, 5.46 + 6.00 and get 11.46. The reference table for the chi-squared values looks something like this:
The most often used threshold for the significant probability value is 0.05, or 5%. This means as long as the probability of mistaking whether there is a difference between observed and expected is less than 5%, we will assume the difference is indeed real.
The degree of freedom refers to the number of groups being compared – 1. So in our white-red example we get 2 – 1 = 1. Our degree of freedom is 1.
The p value for 1 degree of freedom at 0.05 is 3.84. Our chi-squared value for eye colour is above this, so we can reject the null hypothesis and say that there is a significant difference between the observed and expected numbers of white and red eye colour.