Sb16, SH1, SH2 - Testing contingency tables for association
A contingency table records two categorical variables for the same individuals. You will calculate the counts expected under independence, carry out a chi-squared test for association, and interpret both the overall result and the individual contributions.
Read counts without confusing them with proportions
Could a test reach a different verdict after collecting ten times as much data, even if every percentage stayed the same? The chi-squared test measures how convincing a departure from independence is, so both the pattern and the sample size matter.
You already know
A hypothesis test compares sample evidence with a population null hypothesis. A small -value can provide evidence against that hypothesis; failure to reject it does not prove it true. Random sampling provides a probability basis for population inference.
Start by asking what one observation represents. Here each randomly selected pupil supplies one pair: school site and usual main travel method. Each pupil appears in exactly one cell.
| School site | Bus | Other | Total |
|---|---|---|---|
| North | |||
| South | |||
| Total |
More South pupils use the bus in this sample, but the South group is also larger. The bus proportions are at North and at South. Raw counts and within-group proportions answer different questions.
Marginal totals can also recover missing observed cells: the North Other count is . Use the matching row or column total, keeping every observation counted once.
Contingency table
A contingency table records frequencies classified by two categorical variables. Each cell counts observations in one row category and one column category. Row totals and column totals are called marginal totals.
Association means that the distribution of one variable depends on the category of the other. Independence means that it does not.
Categories need not have a meaningful numerical order: a payment method cannot sensibly be averaged. Numerical measurements can also be put into categories, such as journey times below or above a threshold, but this loses the exact times. An association test then concerns the categories, not every detail of the original measurements.
Key idea
Compare relevant proportions to describe a table, then use a test to judge whether the sample provides evidence of association in the population. A visible difference alone is not a completed inference.
No assumption that the categorical observations are Normally distributed is needed. The chi-squared reference distribution belongs to the test statistic under the null hypothesis, not to the category labels.
Build the table expected under independence
Under independence, the same column proportions apply in every row. If half the observations belong to one row, that row should contain half of each column total in the expected table.
Expected frequency under independence
For a cell in a contingency table,
where is the grand total. This is the expected frequency under the null hypothesis of independence.
Not in the formula booklet: learn it.
For example, multiplying a row total by the overall column proportion gives the same expression. Expected frequencies may be fractional, even though actual observed counts are integers.
Chi-squared test statistic
For observed frequencies and corresponding positive expected frequencies ,
Each summand is a cell's contribution. Sum over the interior cells, not the marginal totals.
In the formula booklet.
The square stops positive and negative deviations cancelling. Dividing by judges a deviation relative to its expected count. Use unrounded expected values in calculations, even if a displayed table is rounded.
For the usual approximation used here, expected frequencies should be at least . Check expected counts, not observed counts, and use any grouping specified in the question. Also check that the sampling model is appropriate: one observation per individual and independent observations, rather than repeated replies treated as different people.
Worked example 1: expectations and contributions
Question. A random sample of pupils gives the following frequencies for site and main travel method. Calculate the expected table under independence and .
| Site | Bus | Walk | Cycle | Total |
|---|---|---|---|---|
| East | ||||
| West | ||||
| Total |
Plan. Use each row and column total for , then add the six contributions.
Both expected rows are . Thus
Why this step? The observed table has different bus and walking proportions, but the expected table imposes the same proportions at both sites.
Answer. Both expected rows are , and .
Check. Expected row totals are , expected column totals are , and all expected frequencies exceed .
Change only the allocation of bus and walking counts between the sites, keeping every marginal total fixed. The expected table should stay unchanged.
Worked example 2: a stronger departure with the same margins
Question. Find the expected table and when the observed East row is and West row is , with column order Bus, Walk, Cycle.
Plan. Retain the expectations determined by the margins and recalculate the contributions.
Why this step? Expected counts depend on the marginal totals, so changing interior counts alone does not necessarily change the expectations.
Answer. Both expected rows remain ; .
Check. Each non-zero deviation is three times its size in example 1, giving nine times the contribution. Indeed .
The marginal totals are a useful built-in check. They must agree in the observed and expected tables.
Watch out
Wrong: round expected counts to whole people, or include row and column totals as extra cells in .
Right: retain fractional expectations and sum contributions over exactly the classified observations' cells.
The next table changes those same interior allocations once more.
Turn the statistic into a population conclusion
Large discrepancies count against independence. State the hypotheses about the population factors, calculate the reference degrees of freedom, and use the upper tail of the chi-squared distribution.
Degrees of freedom for association
For an by table, excluding marginal totals,
Under the null hypothesis, has approximately the distribution when the test's conditions hold.
Not in the formula booklet: learn it.
Once the margins are fixed, the first rows and columns determine the remaining entries, explaining the degrees-of-freedom count. The booklet supplies the chi-squared percentage-point table. Its column gives an upper-tail area of ; do not split the level between two tails.
Continue this lesson.
You’re previewing NovaLearn without an account. Create a free account to read the rest.
Create free account