Setting Up a Chi-Square Test
How the chi-square statistic and its distributions work, how to choose between the test for homogeneity and the test for independence, and how to write the hypotheses and check the conditions, including expected counts.
A chi-square test works with a two-way table of counts. H₀ predicts what the counts should be (the expected counts); the chi-square statistic measures how far the observed counts are from those predictions. Use the test for homogeneity to compare a variable’s distribution across two or more populations or treatments, and the test for independence to look for an association between two variables in one population.
1The chi-square statistic and its distributions
The chi-square statistic, \(\chi^2\), measures the distance between the observed and expected counts relative to the expected counts. Every cell adds a nonnegative amount, so \(\chi^2\) is never negative. A value near 0 means the counts are close to what H₀ predicts; a large value means they are far off.
The chi-square distributions are a family of density curves. Each has positive values and is skewed right, and each is identified by its degrees of freedom (df). As df increases, the skew becomes less pronounced.
2Homogeneity or independence?
| Test for homogeneity | Test for independence | |
|---|---|---|
| Question | Do the distributions of one categorical variable differ across populations or treatments? | Are two categorical variables associated in one population? |
| Data | Independent random samples from each population, or a randomized experiment | One random sample, with two variables recorded on each individual |
| Refer to | The categorical variable and the populations | Both categorical variables and the population |
Three studies
Name the chi-square test for each study.
- Independent random samples of students at three high schools are asked how they usually get to school.
- One random sample of 240 students at a large high school records each student’s grade and whether they have a part-time job.
- A teacher randomly assigns 90 students to three review formats and records whether each rates the review helpful, neutral, or unhelpful.
- 1Study 1: three populations (schools), each sampled separately, one variable. Homogeneity.
- 2Study 2: one population, one sample, two variables recorded on each student. Independence.
- 3Study 3: three treatments assigned at random, one response variable. Homogeneity (comparing treatments).
The same table of counts could come from either design. Decide from how the data were produced: separate samples or treatment groups means homogeneity; one sample sorted two ways means independence.
3Hypotheses
| Test | H₀ | Hₐ |
|---|---|---|
| Homogeneity | There is no difference in the distributions of [variable] across [populations or treatments] | There is a difference in the distributions of [variable] across [populations or treatments] |
| Independence | There is no association between [variable 1] and [variable 2] in [population] (they are independent) | There is an association between [variable 1] and [variable 2] in [population] (they are not independent) |
Getting to school
State the hypotheses for Study 1.
- 1Homogeneity hypotheses are about distributions: name the categorical variable and the populations.
The sample percentages clearly differ (40%, 30%, 40% take the bus). The question is whether the distributions differ among all students at the three schools. Hypotheses always describe populations.
4Expected counts and conditions
Expected counts are the counts H₀ predicts. If the distributions are the same, each row should split in the same proportions as the column totals, which gives
| Condition | Check |
|---|---|
| Randomization | Independence: one random sample. Homogeneity: independent random samples, or a randomized experiment |
| 10% condition | When sampling without replacement, \(n \le 0.10N\) for each sample (not needed for an experiment) |
| Expected counts | Every expected count is at least 5 |
Getting to school
The samples gave the table below. The three schools enroll 1,800, 1,200, and 2,000 students. Find the expected counts and check the conditions.
| Bus | Car | Walk or bike | Total | |
|---|---|---|---|---|
| School A | 60 | 54 | 36 | 150 |
| School B | 30 | 48 | 22 | 100 |
| School C | 60 | 48 | 42 | 150 |
| Total | 150 | 150 | 100 | 400 |
- 1Expected count = (row total)(column total) / table total. For School A, Bus: \(150 \times 150 / 400 = 56.25\).
- 2The other expected counts follow the same way (table below). The smallest is 25.
- 3Randomization: independent random samples from the three schools. 10% condition: 150 ≤ 180, 100 ≤ 120, and 150 ≤ 200.
- 4Expected counts condition: every expected count is at least 5.
| Expected | Bus | Car | Walk or bike |
|---|---|---|---|
| School A | 56.25 | 56.25 | 37.5 |
| School B | 37.5 | 37.5 | 25 |
| School C | 56.25 | 56.25 | 37.5 |
The condition is about the expected counts. An observed count of 3 is fine if its expected count is 8; an observed count of 12 does not help if some cell’s expected count is 2. In a sample of 30, a row total of 10 and a column total of 6 give an expected count of \(10 \times 6/30 = 2\), so the condition fails.
Grade and part-time jobs
A random sample of 240 students at a high school with 2,600 students found that 12 of 80 tenth graders, 22 of 80 eleventh graders, and 34 of 80 twelfth graders have a part-time job. Set up the test.
- 1H₀: There is no association between grade level and having a part-time job among students at the school. Hₐ: There is an association between them.
- 2Randomization: one random sample. 10% condition: 240 ≤ 0.10(2,600) = 260.
- 3Column totals: 68 with a job, 172 without. Expected counts: \(80 \times 68/240 \approx 22.67\) with a job and \(80 \times 172/240 \approx 57.33\) without, in each grade. All are at least 5.
The chi-square statistic is built from counts. Entering 40%, 36%, 24% instead of 60, 54, 36 changes the result, because the size of the sample matters. Always use the counts.
Quick reference
| Piece | Homogeneity | Independence |
|---|---|---|
| Design | Separate samples or treatments; one variable | One sample; two variables |
| H₀ | No difference in distributions | No association (independent) |
| Randomization | Independent random samples or random assignment | A random sample |
| Expected count | (row total)(column total) ÷ table total | Same formula |
| Expected counts condition | All at least 5 | All at least 5 |