FS1 6.1 - Contingency table tests

FS1 6.1 - Contingency table tests

Two categorical variables can be associated even when neither is numerical. You will calculate expected frequencies under independence, carry out a chi-squared contingency table test, combine sparse categories appropriately and explain why real counts cannot be replaced by percentages.

Expected counts when the variables are independent

Two samples have exactly the same percentages in every category. Must their chi-squared tests reach the same conclusion?

Keep that question open while building the test. Percentages describe the pattern; the number of independent observations also affects how much evidence the pattern provides.

You already know

A chi-squared test compares observed and expected counts using T=∑(O−E)2/ET=\sum(O-E)^2/E. Large discrepancies give large TT; expected cells below 55 need attention. An upper-tail p-value or critical value determines significance, and a non-significant result does not prove the null hypothesis.

A contingency table classifies the same individuals in two ways. For example, each traveller has a day type and a travel choice. Each individual must occupy exactly one cell; repeated entries from one person are not fresh independent cases.

Contingency table and independence

A contingency table records frequencies for combinations of categories of two variables. Row and column totals are its marginal totals.

Under independence, the population proportion in a column is the same within every row. Thus the expected count for a row follows the overall column proportions.

Write H0H_0: there is no association between the two named variables; H1H_1: there is an association. “The variables are independent” is an equivalent null statement. Use association, rather than correlation, for these categorical variables.

Expected frequencies under independence

If row ii has total RiR_i, column jj has total CjC_j, and the grand total is NN,

Eij=RiCjNE_{ij}=\frac{R_iC_j}{N}

The expected table has the same row and column totals as the observed table. This calculation assumes the null hypothesis of independence. Not in the formula booklet: learn it.

For a fixed row, Cj/NC_j/N is the overall fraction in column jj; multiplying by RiR_i distributes that row according to the null pattern.

Worked example 1: equal row totals

Question. A random sample of independent travellers is classified by day type and choice of travel. Calculate the expected frequencies under no association.

Day typeWalkCycleBusTotal
Weekday1818121230306060
Weekend1212282820206060
Total303040405050120120

Plan. Multiply each row total by each column proportion.

Eweekday,walk=60(30)120=15Eweekday,cycle=60(40)120=20Eweekday,bus=60(50)120=25\begin{aligned} E_{\text{weekday,walk}}&=\frac{60(30)}{120}=15\\ E_{\text{weekday,cycle}}&=\frac{60(40)}{120}=20\\ E_{\text{weekday,bus}}&=\frac{60(50)}{120}=25 \end{aligned}

Both row totals are 6060, so the expected table is:

Day typeWalkCycleBusTotal
Weekday1515202025256060
Weekend1515202025256060
Total303040405050120120

Why this step? Independence makes the proportions equal across rows; it does not require equal expectations across different columns.

Answer. The two expected rows are both 15,20,2515,20,25.

Check. All original margins are preserved and the minimum expectation is 1515, safely above 55.

Worked example 2 changes only the balance between the row totals, retaining column totals 30,40,5030,40,50 and grand total 120120.

Worked example 2: unequal row totals

Question. A sample instead has row totals 4040 weekday and 8080 weekend travellers. The column totals are unchanged. Calculate the expected table.

Plan. Use the new row totals with the same overall column proportions.

(Eweekday,walk,Eweekday,cycle,Eweekday,bus)=40(30120,40120,50120)=(10,403,503)(Eweekend,walk,Eweekend,cycle,Eweekend,bus)=80(30120,40120,50120)=(20,803,1003)\begin{aligned} (E_{\text{weekday,walk}},E_{\text{weekday,cycle}},E_{\text{weekday,bus}}) &=40\left(\frac{30}{120},\frac{40}{120},\frac{50}{120}\right)\\ &=\left(10,\frac{40}{3},\frac{50}{3}\right)\\ (E_{\text{weekend,walk}},E_{\text{weekend,cycle}},E_{\text{weekend,bus}}) &=80\left(\frac{30}{120},\frac{40}{120},\frac{50}{120}\right)\\ &=\left(20,\frac{80}{3},\frac{100}{3}\right) \end{aligned}

Why this step? The larger row needs twice the expected counts, while the expected proportions stay the same.

Answer. The expected rows are (10,40/3,50/3)(10,40/3,50/3) and (20,80/3,100/3)(20,80/3,100/3).

Check. The first row sums to 4040, the second to 8080, and corresponding cells sum to 30,40,5030,40,50. Fractions need not be rounded to whole people.

The diagram contrasts actual counts with the independence model for the first table.

[DIAGRAM: asset_name: Observed and independent expected counts; asset_slug: 9fm0-fs1-112-independence; caption: Under independence each row follows the overall column proportions; description: Two clearly separated two-by-three frequency tables have weekday and weekend rows and walk, cycle and bus columns. The observed table contains rows 18,12,30 and 12,28,20; the expected table contains two rows 15,20,25. Both display row totals 60 and column totals 30,40,50 with grand total 120. A footer shows the example calculation 60 times 40 divided by 120 equals 20, and states that expected margins are unchanged]
Under independence each row follows the overall column proportions

To check whether every expected count is large enough, the smallest row total and smallest column total give the smallest product RiCj/NR_iC_j/N. The smallest observed entry need not be in that cell.

Watch out

Wrong: divide the total equally among all cells, choose the smallest observed cell to check validity, or round an expected count to an integer. Right: use the margins and retain precision.

Change the row balance again.

Testing for an association

Once the expected table is ready, calculate the same discrepancy statistic as in goodness of fit, including every interior cell. Row totals, column totals and the grand total are checks, not additional cells in the sum.

The degrees of freedom reflect the margins. In a 22 by 22 table with all margins fixed, choosing one cell determines the other three. More generally, only the top-left block of (r−1)(c−1)(r-1)(c-1) cells can be chosen freely.

Contingency table degrees of freedom

For a retained table with rr rows and cc columns, using the usual independence test,

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

Use TT approximately distributed as χν2\chi^2_\nu, with adequate expected frequencies and independent observations. The marginal-proportion fitting is already allowed for by this formula; do not subtract it again. Not in the formula booklet: learn it.

Use the upper chi-squared tail, just as before. A significant result supports an association between the named population variables; it does not identify a causal direction.

Worked example 3: evidence of an association

Question. Test for an association between day type and travel choice in Worked example 1, using a 5%5\% significance level.

Plan. State contextual hypotheses, calculate the six contributions and use ν=2\nu=2.

H0: day type and travel choice are independentH1: day type and travel choice are associatedT=(18−15)215+(12−20)220+(30−25)225+(12−15)215+(28−20)220+(20−25)225=0.6+3.2+1+0.6+3.2+1=9.6ν=(2−1)(3−1)=2,c=5.991\begin{aligned} H_0&:\ \text{day type and travel choice are independent}\\ H_1&:\ \text{day type and travel choice are associated}\\ T&=\frac{(18-15)^2}{15}+\frac{(12-20)^2}{20} +\frac{(30-25)^2}{25}\\ &\quad+\frac{(12-15)^2}{15}+\frac{(28-20)^2}{20} +\frac{(20-25)^2}{25}\\ &=0.6+3.2+1+0.6+3.2+1=9.6\\ \nu&=(2-1)(3-1)=2,\qquad c=5.991 \end{aligned}

Why this step? Six cells do not give 6−16-1 degrees of freedom: the row and column margins impose more restrictions.

Answer. Since 9.6>5.9919.6>5.991, reject H0H_0. There is sufficient evidence at the 5%5\% level of an association between day type and travel choice.

Check. All expectations are at least 1515. The upper-tail p-value is 0.0082297…<0.050.0082297\ldots<0.05, giving the same decision.

Worked example 4 changes only the observed interior counts, preserving all margins and hence the expected table.

Worked example 4: a smaller discrepancy with the same margins

Question. Repeat the test with observed rows 16,18,2616,18,26 and 14,22,2414,22,24, retaining the same day-type and travel-choice categories.

Plan. Keep expected rows 15,20,2515,20,25 and recalculate TT.

T=1215+(−2)220+1225+(−1)215+2220+(−1)225=0.613333…ν=2,0.613333…<5.991\begin{aligned} T&=\frac{1^2}{15}+\frac{(-2)^2}{20}+\frac{1^2}{25} +\frac{(-1)^2}{15}+\frac{2^2}{20}+\frac{(-1)^2}{25}\\ &=0.613333\ldots\\ \nu&=2,\qquad 0.613333\ldots<5.991 \end{aligned}

Why this step? The margins determine the null expectations, but the interior pattern determines how far the observations depart from them.

Answer. Do not reject H0H_0. There is insufficient evidence of an association between day type and travel choice at 5%5\%.

Check. The calculator upper-tail p-value is 0.7358958…>0.050.7358958\ldots>0.05. This does not establish that the variables are independent.

A calculator can evaluate TT or its p-value, but the expected table, degrees of freedom and contextual conclusion must still be clear.

Watch out

Wrong: use ν=6−1=5\nu=6-1=5 because the table has six interior cells. The fixed row and column margins impose additional restrictions. Right: use ν=(2−1)(3−1)=2\nu=(2-1)(3-1)=2, and sum the statistic over the interior cells only, excluding the totals.

The numerical comparison still needs a statement about the two population variables.

Exam tip

Keep both variables in the hypotheses and conclusion. “Reject” alone is incomplete; “there is a correlation” is inappropriate for an ordinary test of these categorical variables.

Move the cells a little further from independence.

Continue this lesson.

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

Create free account