15. Chi Squared: Goodness of Fit and Contingency Tables

15.2 Contingency Tables

The goodness of fit test may be viewed as a frequency analogue of comparing a sample mean from one population to a hypothesized H_{0} mean, \mu, with the one-sample t-test :

With the goodness of fit \chi^{2} test we compare an observed frequency profile with the H_{0} (expected) frequency profile :

After studying the one-sample t-test we moved on to the two-sample t-test (and ANOVA) where we compared populations with each other directly :

Similarly, we will now move from comparing the observed frequencies from one group to a fixed profile to comparing the observed frequencies from several groups with each other :

In the process we are testing to see if there is any relationship between the different groups and the categories labeled on the x axis.

To do this comparison, we need to make two contingency tables, one for the observed frequencies and one for the expected frequencies. The expected frequency table is computed from the values in the observed frequency table and not from some predetermined expected frequencies[1]. That way, the expected frequencies contingency table represents the frequencies expected if there were no difference between the groups.

The contingency table setup looks like :

.

Group
Category 1 2 3 4
1
2
3

The numbers in the table will be frequencies. The contingency table has R rows with R = number of categories and C columns with C = number of groups[2].

To compute the expected frequency table, we need to sum the rows and columns in the expected frequency table. We can write the sums at the ends of the rows and columns. So we will take our data and make the observed frequency contingency table :

Group  
Category 1 2 3 4  
1 O_{1,1} O_{1,2} O_{1,3} O_{1,4} {\cal R}_{1}
2 O_{2,1} O_{2,2} O_{2,3} O_{2,4} {\cal R}_{2}
3 O_{3,1} O_{3,2} O_{3,3} O_{3,4} {\cal R}_{3}
    {\cal C}_{1} {\cal C}_{2} {\cal C}_{3} {\cal C}_{4} \tau

where {\cal R}_{i} is the sum of row i, {\cal C}_{j} is the sum of column j and \tau is the sum of all the entries in the table ( = sum of row sums = sum of column sums). Using the sums, the expected frequency table is :

Group
Category 1 2 3 4
1 (R_{1}C_{1})/\tau (R_{1}C_{2})/\tau (R_{1}C_{3})/\tau (R_{1}C_{4})/\tau
2 (R_{2}C_{1})/\tau (R_{2}C_{2})/\tau (R_{2}C_{3})/\tau (R_{2}C_{4})/\tau
3 (R_{3}C_{1})/\tau (R_{3}C_{2})/\tau (R_{3}C_{3})/\tau (R_{3}C_{4})/\tau

The expected frequency contingency table is the numerical expression of H_{0}. In words: H_{0} is the hypothesis that the groups and categories are independent. Therefore this \chi^{2} contingency table test is called the \chi^{2} test for independence.

The test statistic for this test is

    \[ \chi^{2} = \sum_{\mbox{all table entries }i,j} \frac{(O_{i,j} - E_{i,j})^{2}}{E_{i,j}} \]

with \nu = (R-1)(C-1) where R is the number of rows and C is the number of columns.

Example 15.3 : Is there a relationship between the number of years spent in college and where you live? Test at \alpha = 0.05. The data, in table form are :

years spent in college (group)
No College 4 yr degree Advanced degree sums
living location (category) Urban 15 12 8 = 35
Suburban 8 15 9 = 32
Rural 6 8 7 = 21
sums = 29 = 35 = 24 = 88

In the table above, we have done some data reduction in summing the rows and columns. Continuing with the solution :

0. Data reduction. Compute the expected frequency table :

No College 4 yr degree Advanced degree
Urban \frac{(35)(29)}{88}=11.53 \frac{(35)(35)}{88}=13.92 \frac{(35)(24)}{88}=9.55
Suburban \frac{(32)(29)}{88}=10.55 \frac{(32)(35)}{88}=12.73 \frac{(32)(24)}{88}=8.73
Rural \frac{(21)(29)}{88}=6.92 \frac{(21)(35)}{88}=8.35 \frac{(21)(24)}{88}=5.73

1. Hypotheses.

(Pay close attention to the wording.)

H_{0}: Living location (category) is independent of the amount of education (group).
H_{1}: Living location (category) is dependent of the amount of education (group).

2. Critical statistic.

Use the Chi-Square Distribution Table with \alpha = 0.05 and

\nu = (R-1)(C-1) = (3-1)(3-1) = (2)(2) = 4 to find

    \[ \chi^{2}_{\mbox{crit}} = 9.488 \]

3. Test statistic.

    \begin{eqnarray*} \chi^{2} & = & \sum \frac{(O-E)^{2}}{E} \\ & = & \frac{(15 - 11.53)^{2}}{11.53} + \frac{(12 - 13.92)^{2}}{13.92} + \frac{(8 - 9.55)^{2}}{9.55} + \\ & & \frac{(8 - 10.55)^{2}}{10.55} + \frac{(15 - 12.73)^{2}}{12.73} + \frac{(9 - 8.73)^{2}}{8.73} + \\ & & \frac{(6 - 6.92)^{2}}{6.92} + \frac{(8 - 8.35)^{2}}{8.35} + \frac{(7 - 5.73)^{2}}{5.73} \\ & = & 3.01 \end{eqnarray*}

4. Decision.

Do not reject H_{0}.

5. Interpretation. The living location is independent of education.

15.2.1 Homogeneity of proportions \chi^{2} test

This test is a special case of the \chi^{2} test of independence where the number of rows is always 2 and the total number of data points per column (the sum of frequencies per column) is the same for every column. With these restrictions we have a test that compares proportions between the populations represented by the columns. In particular, the \chi^{2} test of independence generalizes the two-sample proportions test that we covered in Chapter 11. The first row of the contingency table represents \hat{p}_{i}, the sample proportion of interest and the second row represents \hat{q}_{i} = 1 - \hat{p}_{i}, the sample proportion not of interest. In using the homogeneity of proportions test, it is not necessary to explicitly compute the proportions \hat{p}_{i}.

Example 15.4 : We wish to test the hypothesis, at \alpha = 0.05 that different proportions of students in different high schools drive their own car given the following data :

School 1 School 2 School 3 sums
Own Car 18 22 16 = 56
Parent’s Car 32 28 34 = 94
sums = 50 = 50 = 50 = 150

0. Data reduction. The first step in data reduction has been completed by summing the rows and columns. Using these sums, the expected frequencies are :

School 1 School 2 School 3
Own Car 18.67 18.67 18.67
Parent’s Car 31.33 31.33 31.33

1. Hypotheses :

    \begin{eqnarray*} H_{0} &:& p_{1} = p_{2} = p_{3} \\ H_{1} &:& \mbox{ at least one proportion is different from the others} \end{eqnarray*}

2. Critical statistic.

Using the Chi-Square Distribution Table with \alpha = 0.05 and \nu = (R-1)(C-1) = (2-1)(3-1) = 2 find

    \[ \chi^{2}_{\mbox{crit}} = 5.991 \]

3. Test statistic.

    \[ \chi^{2}_{\mbox{test}} = \sum_{table} \frac{(O - E)^{2}}{E} = 1.596 \]

4. Decision.

Do not reject H_{0}.

5. Interpretation. We were unable to find any difference in the proportion of students who drive their own car between the schools at \alpha = 0.05.


  1. The equivalent procedure in the goodness of fit test is to distribute the expected frequencies uniformly among the categories by setting O_{i} = n/C. This is the chance or completely random distribution for the expected frequencies.
  2. At this point the labels "group" and "category" are arbitrary.

License

Share This Book