4.3 - Chi-squared tests of independence
A contingency table records two categorical variables for each observation. You will predict cell counts under independence, combine categories when expected counts are too small, and use a chi-squared test to assess evidence of association in the population.
Independence in a contingency table
If one group contains twice as many people as another, should it have the same number choosing each option? Under independence, we expect the same proportions, so the larger group should usually have larger counts.
A contingency table cross-classifies observations by two categorical variables. Each observation belongs to exactly one row and one column. The row and column totals are called the marginal totals; the sum of every cell is the grand total, .
Independence of categorical variables
Two variables are independent if knowing the category of one does not change the probabilities for the other. Under independence, each row has the same population proportions across the columns.
Suppose a column contains of observations overall. Under independence, a row containing observations is expected to put the proportion in that column, giving .
Expected contingency-table count
Under independence, the expected count in row , column , is
where is that row's total and is that column's total. Calculate these from the observed table's margins.
This formula is not in the formula booklet: learn it.
We estimate the common column proportions from the pooled data. We do not use the separate observed proportions in each row: those are precisely what the test will compare.
Worked example 1: unequal row totals
Question. A random sample records study method and preferred session. Calculate the expected table under independence.
| Method | Morning | Afternoon | Evening | Total |
|---|---|---|---|---|
| A | ||||
| B | ||||
| Total |
Plan. Multiply each row total by each overall column proportion.
The pooled proportions are . Thus
Answer. The expected table is
| Method | Morning | Afternoon | Evening |
|---|---|---|---|
| A | |||
| B |
Check. Each expected row has the same proportions , but the counts are in the ratio . The expected column totals are still , agreeing with the observed margins.
Double every observed count in row B, keeping row A unchanged. The pooled column proportions change, so the expected row A changes too.
Worked example 2: new margins change every expectation
Question. Calculate the expected table under independence for these observed counts.
| Method | Morning | Afternoon | Evening | Total |
|---|---|---|---|---|
| A | ||||
| B | ||||
| Total |
Plan. Recalculate the pooled proportions before finding all six expected counts.
Answer. To two decimal places, the expected table is
| Method | Morning | Afternoon | Evening |
|---|---|---|---|
| A | |||
| B |
Keep the exact fractions or full calculator values in subsequent calculations.
Check. With the margins fixed, the first expected count determines the other two in its row by the common column proportions. Directly checking margins gives and ; the other margins agree too.
The observations must be independent of one another, as in a suitable random sample with each person recorded once. That sampling condition is different from the independence of the two variables being tested. We may assume independent observations while investigating whether the variables are associated.
Watch out
Equal expected counts across rows are appropriate only when their row totals are equal. Independence concerns equal proportions, not equal raw frequencies.
Use the margins to complete one more predicted table.
Expected counts and degrees of freedom
A contingency-table chi-squared test requires every final expected cell count to be at least .
First calculate the expected table. If a category is too small, combine whole rows or whole columns that have a sensible joint meaning. Add their observed counts, recalculate the margins and expected counts, and check every cell again. Combining just one isolated cell would destroy the rectangular classification.
Independence-test degrees of freedom
For a final table with rows and columns,
Use the dimensions after any combining. This rule is not in the formula booklet: learn it. The expected-count formula has already allowed for estimation of the marginal proportions; do not subtract further fitted parameters from this rule.
Why this product? Once the margins are fixed, the cells outside the final row and column can vary independently. The remaining cells must complete the row and column totals. For a by table, fixing one cell therefore fixes the other three.
Worked example 3: combining columns
Question. The table records how many optional sessions people attend. Construct a table suitable for an independence test, combining only where necessary, and find its degrees of freedom.
| Group | None | One | Two or more |
|---|---|---|---|
| P | |||
| Q |
Plan. Find expected counts, combine a small session category with its neighbour, then count final rows and columns.
The row totals are , the column totals are , and . The expected rows are
Both expected counts in the last column are below five. Combine “One” and “Two or more” into “At least one”:
| Group | None | At least one |
|---|---|---|
| P observed | ||
| Q observed | ||
| P expected | ||
| Q expected |
Now every expected cell count is at least five.
Answer. Use the two-category table above, with .
Check. Recalculating from the new column totals gives and . These agree with adding the original expected counts in those columns.
A small category can appear in a row instead. The principle is unchanged: merge the entire category across every column.
Worked example 4: combining rows
Question. In this table, session attendance is classified by rows and outcome by columns. Combine categories where necessary for an independence test and find the degrees of freedom.
| Sessions | Pass | Fail |
|---|---|---|
| None | ||
| One | ||
| Two or more |
Plan. Check expectations from the margins, then combine the final two attendance rows.
The row totals are , with column totals and . Expected rows are
The final row is too small. Combining “One” with “Two or more” gives
| Sessions | Pass observed | Fail observed | Pass expected | Fail expected |
|---|---|---|---|---|
| None | ||||
| At least one |
Answer. The final table has two rows and two columns, all expected counts at least five, and .
Check. The combined row has total , so its expected pass count is . The expected column totals remain and .
Continue this lesson.
You’re previewing NovaLearn without an account. Create a free account to read the rest.
Create free account