The Chi-Square Test

What it’s for:

The chi-square test (pronounced kye-square) looks for differences between two or more distributions. Data are in the form of raw counts of nominal variables (e.g. number of males). It is commonly used in two situations: 1) To see how well a set of observations fit a theoretical distribution (Goodness of Fit); and 2) to see if the distribution of two variables (measured simultaneously) are independent (Independence of Two Variables).

Goodness of Fit:
The Goodness of Fit test compares how well a set of observations fit our expectations from some theoretical distribution (the theoretical distribution always comes from the null hypothesis). Let’s say we want to know if both sexes use the University of Lethbridge pool in equal numbers. We don’t measure “maleness” or “femaleness,” we just count the number of pool visitors in each of these nominal categories. We then compare the number we did see (observed values) to the number we would expect to see if our null hypothesis were true (expected values). A reasonable null hypothesis here would be no difference in number between the two sexes, but we can test our observations against any distribution we wish. If our observations are very different from the expected values, we can confidently reject the null hypothesis.

Independence of Two Variables:
Sometimes we may count two types of nominal data simultaneously. For example, we might measure both hair colour and eye colour for a group of students. We could then ask if the distribution of eye colours is independent from the distribution of hair colours. Typically data of this type are presented in tables (formally called contingency tables) with one variable in rows, and the other in columns. (It doesn’t make any difference if you reverse rows and columns.) If we have two categories of each variable we will have a 2×2 table, but in many cases, such as the example above, we will have more than two rows and columns.

Assumptions/Cautions:

Use only on raw counts, never on data converted to proportions, percents or means.
The Chi-square test becomes inaccurate when sample sizes are small. A commonly quoted rule of thumb is that for two categories, no expected value may be less than 5, and for more than two categories, no more than 20% of expected values may be less than 5 (e.g. Ambrose and Ambrose 1995).
How to use it:

Goodness of fit:
1) Build a table of observed and expected values. Remember that expected values will be derived from your null hypothesis. Typically, calculation of expected values requires converting an expected proportion or percentage into an expected number. For the example above, the null hypothesis is no difference in gym attendance between males and females. Since we would expect 50% of pool users to be male and 50% female, we would expect half of all people counted to be of each sex (0.5 x total). If we counted 100 people, we would expect 50 males (0.5 x 100) and 50 females (0.5 x 100).

2) Calculate a chi-square value using the formula shown in the box at right.

3) Calculate degrees of freedom (df) by taking the number of categories and subtracting 1. For our example the df would be 2-1 = 1.

4) Estimate a probability value (p-value) for the calculated chi-square and df, using a computer program or a table of critical values.

5) Draw a conclusion, based on the p-value from 4). See also Types of Error.

Independence of Two Variables:
1) Put your observed values in a table. Calculate the total count for each row and column, as well as the grand total. Expected values are calculated for each cell in the table by row total x column total / grand total.

2) Calculate the chi-square value using the formula in the box above.

3) Calculate df as (number of rows-1) x (number of columns -1).

4) Estimate the p-value using a computer program or a table of critical values.

5) Draw a conclusion based on the p-value from 4). See also Types of Error.

MS Excel Tips:

Using Microsoft Excel (or any other spreadsheet), it is simple to set your observed values in one column, your expected values in the next column, and then calculate the square of observed minus expected in a third column. The sum of the third column will be your chi-square value. Using the built-in CHIDIST function for your chi-square value and df will return the p-value. Excel has a built in CHITEST function which allows you to directly input your observed and expected values, but it outputs only a p-value, and you will be required to include a chi-square value with your results in any scientific paper.

RETURN