A chi-square test of independence is used with two qualitative (categorical) variables. It checks whether the two variables are independent of one another, or whether they are associated.
Name each variable (you can leave them as "X" and "Y" if you like), choose how many categories each has, and name each category. These names are used throughout the rest of the exercise.
Variable X (the rows)
Variable Y (the columns)
Error: Each variable must have a whole number of at least 2 categories.
The null hypothesis for a test of independence is that the two variables are independent — that knowing the value of one variable tells you nothing about the value of the other.
If the variables really were independent, then within the population the proportion falling in any combination of categories would just be the product of the two separate (marginal) proportions. This is the idea we will use to work out the expected frequencies shortly.
Null Hypothesis
As with the goodness of fit test, there is no choice to make for the alternate hypothesis. The alternate hypothesis is simply that the two variables are associated (i.e. not independent) — that the value of one variable does tell you something about the value of the other.
Alternate Hypothesis
The expected frequency of a cell is the count we would expect to see if the null hypothesis were true (i.e. if the two variables were independent). For the cell in row \( i \) and column \( j \) it is calculated as:
$$E_{ij} = \frac{(\text{row } i \text{ total}) \times (\text{column } j \text{ total})}{\text{grand total}}$$The intuition: under independence, the proportion in row \( i \) is \( \frac{\text{row } i \text{ total}}{\text{grand total}} \) and the proportion in column \( j \) is \( \frac{\text{column } j \text{ total}}{\text{grand total}} \). Multiplying these proportions together and scaling back up by the grand total gives the formula above.
The table on the right shows the expected frequency for every cell.
Expected Frequencies
For the chi-square test of independence to be valid, we need to check the following assumptions:
The first assumption is that the observations are independent of one another. In practice, this means that each individual (or item) contributes to exactly one cell of the contingency table — nobody is counted twice, and no observation's category is influenced by another's.
How do we check? We check by investigating the experimental setup — how the data was collected — making sure each individual was recorded once and gathered at random.
The chi-square distribution is only a good approximation when the expected counts are not too small. Cochran's rule gives a common guideline, which holds when both of the following are true:
The expected counts are the \( E_{ij} \) values computed in the previous section:
The test statistic measures how far the observed counts are from the expected counts, summed over every cell of the table:
$$\chi^2 = \sum_{\text{all cells}} \frac{(O - E)^2}{E}$$We build it up in two steps. Use the tabs below to move through them.
For each cell we take the observed count minus the expected count. The table shows observed − expected = difference in each cell.
Next, for each cell we square the difference and divide by the expected count, giving \( \frac{(O - E)^2}{E} \). Adding these up over all cells gives the test statistic.
One way to tell whether we accept or reject the null hypothesis is to observe whether our p-value is below or above the significance level.
Step 1) What is your significance level?
\( \alpha = \)
Error: The value for α must be between 0 and 1.
Step 2) Final Conclusion