Title: Chi Square
Course: UGQuants (SSPS) > Section: Association for Nominal and Ordinal Variables

Chi Square

Chi square is a very common test that allows us to determine the independence of two variables.  Here, the null hypothesis (H_0) is that the two variables we are interested in are unrelated, or independent. The alternative hypothesis, or H_1, is that they are not independent.  Chi square assesses the likelihood that the relationship between two variables is in fact due to chance and asks: what is the probability that the relationship between these two variables does not exist in the population?

Much as with Yule’s Q, chi square is based on an examination of the figures in cells of a table.  It examines the data that we have in our table (the observed data - denoted as 'fo' for 'observed frequency) and compares this to data that we might have if there were in fact no relationship at all between our two variables (the expected data, or hypothetical data, denoted 'fe' for 'expected frequency').

We can map out our hypotheses in the following way:

H_0: fo=fe

H_1: fo≠fe

In our null hypothesis, if there is in fact no relationship between our two variables the frequency of the data we observe (fo) would be the same as the frequency of data we expect (fe) . If a difference is found, we can conclude that one variable is statistically related to the other variable (and we reject the null hypothesis, that no relationship exists). If a difference is not found, we conclude that the variables are not associated, and we fail to reject the null hypothesis.

As with all statistical tests, the chi square test has several assumptions:

1 | The variables are categorical (in other words they are nominal or ordinal). Typically we use this for nominal data as we have more powerful tests for ordinal data.
2 | The observations are independent.
3 | Each cell must have a minimum expected value of 5.

Since this is a table-based calculation, it is best to begin with a table of data. Let us imagine that we ask a class of students whether they voted in an election so that we can investigate whether gender has an impact on voter turnout. We can present his as a 2x2 table:

Gender and turnout: class of students.

Voted | Gender
Male | Female | Total
Yes | 38 | 15 | 53
No | 7 | 40 | 47
Total | 45 | 55 | 100

To calculate chi square we need to examine the gap between this observed data and what we would have expected to see in our table if there was no relationship at all between our two variables. Our first step, then, is to calculate the expected data. How do we calculate expected frequency? The first step is to look at the row and column totals and to calculate what frequency we would expect each cell to contain if there were no association between the independent and dependent variables:

 | Male | Female | Total
Yes | ? | ? | 53
No | ? | ? | 47
Total | 45 | 55 | 100

To calculate our expected data for a particular cell, we identify its row total and column total, multiple them together and divide by the total number of observations. In cell a, which has 38 observations, we would multiple the column total (45) by the row total (53) and divide by the number of observations (100).  We would do this for each cell in our table.

 | Male | Female | Total
Yes | (45*53)/100 | (55*53)/100 | 53
No | (45*47)/100 | (55*47)/100 | 47
Total | 45 | 55 | 100

The resulting figures are as follows:

 | Male | Female | Total
Yes | 23.85 (expected) | 29.15 (expected) | 53
No | 21.15 (expected) | 25.85 (expected) | 47
Total | 45 (.45) | 55 (.55) | Total

Now we have our observed data, from our original data, and our expected data which we have calculated.

To calculate chi square we employ the following formula:

To calculate the formula for chi square it is easiest to view it as a table.  We can re-arrange them as follows:

Male/Yes (cell a)
Female/Yes
(cell b)
Male/No (cell c)
Female/No (cell d)
Total
Observed | 38 | 15 | 7 | 40 | 100
Expected | 23.85 | 29.15 | 21.15 | 25.85 | 100

(There are a number of checks we can make along the way. The first is that when we calculate the total across the observed cells this should equal the total across the expected cells. in other words when we add together all the figures across row one this should equal the total across row two).

Next we can calculate the difference between the observed and expected figures since (O-E) is an important part of our formula.

 | Male/Yes | Female/Yes | Male/No | Female/No | Total
Observed | 38 | 15 | 7 | 40 | 100
Expected | 23.85 | 29.15 | 21.15 | 25.85 | 100
O-E | 14.15 | -14.15 | -14.15 | 14.15 | 0

Again we can provide a useful check by adding all the figures for (O-E) together. This should equal zero.

Next we can square (O-E) and add the figures across each of the cells in row 4.

 | Male/Yes | Female/Yes | Male/No | Female/No | Total
Observed | 38 | 15 | 7 | 40 | 100
Expected | 23.85 | 29.15 | 21.5 | 25.85 | 100
O-E | 14.15 | -14.15 | -14.15 | 14.15 | 0
(0-E)² | 200.2225 | 200.2225 | 200.2225 | 200.2225 | 800.89

We can then calculate:

 | Male/Yes | Female/Yes | Male/No | Female/No | Total
Observed | 38 | 15 | 7 | 40 | 100
Expected | 23.85 | 29.15 | 21.15 | 25.85 | 100
0-E | 14.15 | -14.15 | -14.15 | 14.15 | 0
(0-E) ² | 200.2225 | 200.2225 | 200.2225 | 200.2225 | 800.89
(0-E)²

^E
8.395
6.8686
9.4667
7.7455
32.4758

We sum across the cells in this last row to come up with our final figure for chi-square, which in this case is 32.48.  Because we arrive at this number by squaring the differences between the observed and expected values, and therefore eliminate our negative signs, we should never have a negative value for chi square.

Whenever we calculate a statistic we should follow the same steps:

 | Specify the null hypothesis
 | Choose a statistical test
 | Calculate the test statistic
 | Look up the 'critical value' for the test
 | Draw conclusions

Now what do we do with this figure of 32.48?  Well we now have the test statistic (32.48) and we need to determine the critical value.  For chi square this relies on the degrees of freedom, which is a way of accounting for the size of the table. The bigger the table the more cells it will have and the more things we can add up. As a result, the larger the test statistic will become.  To account for this structure of the data, we need to identify a figure that will let us know whether the variables are independent or not. For chi square we calculate the degrees of freedom in the following way: df = (r-1)* (c-1)

Here, r = number of rows and c= number of columns. Because we have a 2 x 2 table, with 2 rows and 2 columns, we calculate degrees of freedom as (2-1) *(2-1) = (1)*(1) =1 so the degree of freedom is 1.

 We now need to find the critical value for chi square where the degree of freedom is 1.

There will be one critical value for alpha .05 and another at .01. These give us the figures with a 5 % and 1% chance of error (or 95% and 99% degree of accuracy), respectively.  The critical value at .05 with a degree of freedom 1 is 3.84 and at .01 is 6.63.  Because our calculated statistic is larger than both critical values, we report significance at the.01 level.  We reject the null hypothesis with a .01 chance of error and conclude that there is a relationship between our two variables: gender has an impact on turnout.

This is a useful measure for testing whether a relationship exists or not and is therefore a test of significance. What chi square cannot do, however, is tell us about the direction or strength of that relationship. For this we need different types of statistics.