Topics
Testing whether observations fit predictions, and whether events are independent, using a χ² distribution.
Want a deeper conceptual understanding? Try our interactive lesson!
A χ² goodness of fit test compares actual frequencies to the frequencies that would be expected under the null hypothesis. The bigger the relative difference between actual and expected values, the smaller the p value it returns.
For example, imagine a 5 kilometer race where the number of racers finishing in certain time brackets is recorded, and compared to what is expected based on historical data:
Notice that the expected and observed frequencies both add up to 146. They must always be the same.
The null hypothesis for this test is that the observed frequencies do fit the expected distribution.
The alternative hypothesis is that the observed frequencies do not fit the expected distribution.
To perform a χ² goodness of fit test, you use your calculator:
Enter in L1 the observed frequencies
Enter in L2 the expected frequencies
Find the χ2 GOF-Test on your calculator, with
Observed: L1
Expected: L2
df: (n−1), where n is the number of categories. (2 in our case)
The calculator returns the following:
χ2≈9.24
p≈0.00986
The degrees of freedom in a dataset is the number of values that can change while keeping the total sum constant. If there are n values in a list, the number of degrees of freedom is n−1.
The degrees of freedom are important because with more values, there will naturally be more total variation between actual and expected values. The calculator needs to account for this.
The critical value for a χ² test is a threshold we are given, against which we compare the value of χ² for our data. If our χ² is larger than the critical value, we reject H0.
It's worth seeing what the χ2 distribution actually looks like.
Notice that as the degrees of freedom increase, the curve shifts down and to the right.
The p-values our calculator returns are really area under the curve:
A χ2 test can also be used to test whether categorical variables are related, for example, does favorite movie depend on gender? It works by comparing how far off the observed data is from what we would expect if the variables were not related (H0).
In a χ2 test for independence:
The null hypothesis H0 is that the categories are not independent (not related)
The alternative hypothesis H1 is that the categories are not independent (they are related).
On a calculator:
Enter the observed frequencies in a matrix (table)
Enter the expected frequencies in a separate matrix or leave them blank if they are not given.
Navigate to χ2-Test on your calculator, and enter the observed and expected matrices (select an empty matrix and your calculator will find the expected values itself) you just filled.
The calculator returns the χ2 value and the p value.
Nice work completing χ² tests, here's a quick recap of what we covered:
Exercises checked off
Testing whether observations fit predictions, and whether events are independent, using a χ² distribution.
Want a deeper conceptual understanding? Try our interactive lesson!
A χ² goodness of fit test compares actual frequencies to the frequencies that would be expected under the null hypothesis. The bigger the relative difference between actual and expected values, the smaller the p value it returns.
For example, imagine a 5 kilometer race where the number of racers finishing in certain time brackets is recorded, and compared to what is expected based on historical data:
Notice that the expected and observed frequencies both add up to 146. They must always be the same.
The null hypothesis for this test is that the observed frequencies do fit the expected distribution.
The alternative hypothesis is that the observed frequencies do not fit the expected distribution.
To perform a χ² goodness of fit test, you use your calculator:
Enter in L1 the observed frequencies
Enter in L2 the expected frequencies
Find the χ2 GOF-Test on your calculator, with
Observed: L1
Expected: L2
df: (n−1), where n is the number of categories. (2 in our case)
The calculator returns the following:
χ2≈9.24
p≈0.00986
The degrees of freedom in a dataset is the number of values that can change while keeping the total sum constant. If there are n values in a list, the number of degrees of freedom is n−1.
The degrees of freedom are important because with more values, there will naturally be more total variation between actual and expected values. The calculator needs to account for this.
The critical value for a χ² test is a threshold we are given, against which we compare the value of χ² for our data. If our χ² is larger than the critical value, we reject H0.
It's worth seeing what the χ2 distribution actually looks like.
Notice that as the degrees of freedom increase, the curve shifts down and to the right.
The p-values our calculator returns are really area under the curve:
A χ2 test can also be used to test whether categorical variables are related, for example, does favorite movie depend on gender? It works by comparing how far off the observed data is from what we would expect if the variables were not related (H0).
In a χ2 test for independence:
The null hypothesis H0 is that the categories are not independent (not related)
The alternative hypothesis H1 is that the categories are not independent (they are related).
On a calculator:
Enter the observed frequencies in a matrix (table)
Enter the expected frequencies in a separate matrix or leave them blank if they are not given.
Navigate to χ2-Test on your calculator, and enter the observed and expected matrices (select an empty matrix and your calculator will find the expected values itself) you just filled.
The calculator returns the χ2 value and the p value.
Nice work completing χ² tests, here's a quick recap of what we covered:
Exercises checked off