Chi-Square Test
of Independence
Determine whether two categorical variables are associated or independent using observed and expected frequencies in a contingency table.
What Are Categorical Variables?
Categorical variables place individuals into groups or categories rather than measuring them on a numeric scale. Examples include blood type, treatment group, or disease status.
The Big Question
Imagine you collect data on smoking status (smoker vs. non-smoker) and lung disease (present vs. absent). You notice that smokers seem more likely to have lung disease. But is this difference real or just random chance?
The Contingency Table
Data for two categorical variables is organized into a contingency table (also called a cross-tabulation). Each cell shows the count of observations falling into that combination of categories.
| Disease Present | Disease Absent | Total | |
|---|---|---|---|
| Smoker | 120 | 80 | 200 |
| Non-smoker | 90 | 210 | 300 |
| Total | 210 | 290 | 500 |
Hypotheses for the Test
Expected Frequencies
If the null hypothesis is true (variables are independent), we can calculate expected frequencies for each cell:
Example: Expected count for Smoker + Disease Present:
The \(\chi^2\) Statistic
Degrees of Freedom & the Distribution
For our \(2 \times 2\) table: \(df = (2-1)(2-1) = 1\). We compare our \(\chi^2\) statistic to the chi-square distribution with that many degrees of freedom.
Independence vs. Goodness of Fit
| Test of Independence | Goodness of Fit | |
|---|---|---|
| Purpose | Association between two variables | Does one variable match a known distribution? |
| Data layout | \(r \times c\) contingency table | One-row frequency table |
| Expected values | \(\frac{\text{row} \times \text{col}}{\text{total}}\) | From hypothesized proportions |
| Degrees of freedom | \((r-1)(c-1)\) | \(k - 1\) |
| Example | Smoking vs. lung disease | Observed vs. expected Mendelian ratios |
Conditions for Validity
Step-by-Step Procedure
Worked Example: Setup
A researcher investigates whether exercise frequency is associated with flu incidence in 400 adults. Use \(\alpha = 0.05\).
| Got Flu | No Flu | Total | |
|---|---|---|---|
| Regular Exercise | 30 | 120 | 150 |
| No Exercise | 70 | 180 | 250 |
| Total | 100 | 300 | 400 |
Worked Example: Calculation
Step 1: Compute expected counts for each cell:
| E (Got Flu) | E (No Flu) | |
|---|---|---|
| Regular Exercise | \(\frac{150 \times 100}{400} = \) 37.5 | \(\frac{150 \times 300}{400} = \) 112.5 |
| No Exercise | \(\frac{250 \times 100}{400} = \) 62.5 | \(\frac{250 \times 300}{400} = \) 187.5 |
Step 2: All \(E_{ij} \geq 5\) ✓. Compute \(\chi^2\):
Worked Example: Conclusion
Example 2: \(3 \times 2\) Table
A study examines whether blood type (A, B, O) is associated with infection status in 300 patients.
| Infected | Not Infected | Total | |
|---|---|---|---|
| Type A | 40 | 60 | 100 |
| Type B | 50 | 50 | 100 |
| Type O | 30 | 70 | 100 |
| Total | 120 | 180 | 300 |
Common Mistakes to Avoid
Summary Reference Table
| Component | Details |
|---|---|
| Purpose | Test association between two categorical variables |
| Hypotheses | \(H_0\): independent; \(H_a\): associated |
| Statistic | \(\chi^2 = \sum \frac{(O - E)^2}{E}\) |
| Expected counts | \(E_{ij} = \frac{(\text{row total})(\text{col total})}{n}\) |
| Degrees of freedom | \((r-1)(c-1)\) |
| Key condition | All \(E_{ij} \geq 5\) |
| Decision | Reject \(H_0\) if \(\chi^2 > \chi^2_{\alpha, df}\) (or \(p < \alpha\)) |
Question 1 of 5
What does the null hypothesis \(H_0\) state in a chi-square test of independence?
Question 2 of 5
For a \(4 \times 3\) contingency table, what are the degrees of freedom?
Question 3 of 5
In a \(2 \times 2\) table with row totals 80 and 120, column totals 90 and 110, and grand total 200, what is the expected count for the cell in row 1, column 1?
Question 4 of 5
A researcher computes \(\chi^2 = 9.21\) with \(df = 2\). The critical value at \(\alpha = 0.01\) is 9.210. What is the correct conclusion?
Question 5 of 5
Which condition would violate the assumptions for a chi-square test of independence?