4.3 - Chi-squared tests of independence

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, NN.

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 3030 of 100100 observations overall. Under independence, a row containing 6060 observations is expected to put the proportion 30/10030/100 in that column, giving 60(30/100)=1860(30/100)=18.

Expected contingency-table count

Under independence, the expected count in row ii, column jj, is

Eij=RiCjN,E_{ij}=\frac{R_iC_j}{N},

where RiR_i is that row's total and CjC_j 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.

MethodMorningAfternoonEveningTotal
A1212181830306060
B1818121210104040
Total303030304040100100

Plan. Multiply each row total by each overall column proportion.

The pooled proportions are 0.3,0.3,0.40.3,0.3,0.4. Thus

Row A expected=60(0.3,0.3,0.4)=(18,18,24)Row B expected=40(0.3,0.3,0.4)=(12,12,16).\begin{aligned} \text{Row A expected}&=60(0.3,0.3,0.4)=(18,18,24)\\ \text{Row B expected}&=40(0.3,0.3,0.4)=(12,12,16). \end{aligned}

Answer. The expected table is

MethodMorningAfternoonEvening
A181818182424
B121212121616

Check. Each expected row has the same proportions 3:3:43:3:4, but the counts are in the ratio 60:40=3:260:40=3:2. The expected column totals are still 30,30,4030,30,40, 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.

MethodMorningAfternoonEveningTotal
A1212181830306060
B3636242420208080
Total484842425050140140

Plan. Recalculate the pooled proportions before finding all six expected counts.

Row A expected=60140(48,42,50)=(144/7,18,150/7)Row B expected=80140(48,42,50)=(192/7,24,200/7).\begin{aligned} \text{Row A expected} &=\frac{60}{140}(48,42,50)=(144/7,18,150/7)\\ \text{Row B expected} &=\frac{80}{140}(48,42,50)=(192/7,24,200/7). \end{aligned}

Answer. To two decimal places, the expected table is

MethodMorningAfternoonEvening
A20.5720.5718.0018.0021.4321.43
B27.4327.4324.0024.0028.5728.57

Keep the exact fractions or full calculator values in subsequent calculations.

Check. With the margins fixed, the first expected count 144/7144/7 determines the other two in its row by the common column proportions. Directly checking margins gives 144/7+192/7=48144/7+192/7=48 and 144/7+18+150/7=60144/7+18+150/7=60; 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 55.

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 rr rows and cc columns,

ν=(r−1)(c−1).\nu=(r-1)(c-1).

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 (r−1)(c−1)(r-1)(c-1) cells outside the final row and column can vary independently. The remaining cells must complete the row and column totals. For a 22 by 22 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.

GroupNoneOneTwo or more
P4848101022
Q32326622

Plan. Find expected counts, combine a small session category with its neighbour, then count final rows and columns.

The row totals are 60,4060,40, the column totals are 80,16,480,16,4, and N=100N=100. The expected rows are

(48,9.6,2.4),(32,6.4,1.6).(48,9.6,2.4), \qquad (32,6.4,1.6).

Both expected counts in the last column are below five. Combine “One” and “Two or more” into “At least one”:

GroupNoneAt least one
P observed48481212
Q observed323288
P expected48481212
Q expected323288

Now every expected cell count is at least five.

Answer. Use the two-category table above, with ν=(2−1)(2−1)=1\nu=(2-1)(2-1)=1.

Check. Recalculating from the new column totals 80,2080,20 gives EP,at least one=60(20)/100=12E_{P,\text{at least one}}=60(20)/100=12 and EQ,at least one=40(20)/100=8E_{Q,\text{at least one}}=40(20)/100=8. 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.

SessionsPassFail
None40403030
One15151010
Two or more3322

Plan. Check expectations from the margins, then combine the final two attendance rows.

The row totals are 70,25,570,25,5, with column totals 58,4258,42 and N=100N=100. Expected rows are

(40.6,29.4),(14.5,10.5),(2.9,2.1).(40.6,29.4), \quad(14.5,10.5), \quad(2.9,2.1).

The final row is too small. Combining “One” with “Two or more” gives

SessionsPass observedFail observedPass expectedFail expected
None4040303040.640.629.429.4
At least one1818121217.417.412.612.6

Answer. The final table has two rows and two columns, all expected counts at least five, and ν=1\nu=1.

Check. The combined row has total 3030, so its expected pass count is 30(58)/100=17.430(58)/100=17.4. The expected column totals remain 40.6+17.4=5840.6+17.4=58 and 29.4+12.6=4229.4+12.6=42.

Continue this lesson.

You’re previewing NovaLearn without an account. Create a free account to read the rest.

Create free account