DATA2002 Chap.5 Contingency tables: homogeneity, independence, exact tests
Contingency tables: homogeneity, independence, exact tests
This is the chapter that rewards reading a question twice. Two of the most frequently examined tests in the unit produce the same expected counts, the same statistic, the same degrees of freedom and the same p-value from the same table of numbers.
They test different hypotheses, require different sampling schemes, and only one of them is available for any given study, so getting the arithmetic right and the label wrong loses most of a question. The distinction is a fact about how the study was run and is invisible in the counts themselves.
If the investigator decided in advance how many observations would come from each row, those totals are design constants and the question is whether the outcome distributions match across groups, which is homogeneity. If a single sample was drawn and then cross classified, only the grand total was fixed and the question is whether the two classifications are independent.
Both nulls say the same thing about the shape of the table, that the cell probabilities factor into a row part and a column part, which is why the expected counts and the statistic coincide.
The expected count is not a rule to memorise but an estimate of a product: each marginal probability is estimated by its own margin over the total, and multiplying by the sample size gives the row total times the column total over the grand total. The degrees of freedom are worth deriving rather than recalling, since the derivation is three lines and the formula is easy to confuse with a similar looking product.
When a table is too small for the chi-squared approximation, the unit supplies three responses: an exact test built on the hypergeometric distribution, a continuity correction available only for a two by two table, and a simulated null distribution that works for a table of any size.
What this chapter covers
- 01
Which margins the design fixed, and why that is invisible in the table of counts
- 02
Homogeneity: several populations, each sampled at a size the investigator chose
- 03
Independence: one population, cross classified on two variables
- 04
Why both nulls produce the same expected counts and the same arithmetic
- 05
The expected count derived as an estimate of a product, rather than recalled as a rule
- 06
Two free arithmetic checks: expected rows sum to row totals, expected columns to column totals
- 07
The degrees of freedom derived algebraically from the number of cells and the estimated marginals
- 08
What changes between the two reports, line by line, and what does not
- 09
Why the expected count condition is checked on expected counts and never on observed ones
- 10
The structural fact that one cell determines a two by two table with fixed margins
- 11
Fisher's exact test and the hypergeometric distribution it enumerates
- 12
The continuity correction, its direction, and the simulated alternative for larger tables
Route two studies to two different tests
- +1The first study drew one sample of 400 and then classified it on two variables, so only the grand total was fixed. That is a test of independence.
- +1.5Its null hypothesis is that support and travel mode are unrelated in this population, so the joint probability of any combination is the product of the two marginal probabilities. Degrees of freedom are three times one, which is three.
- +1The second study drew three separate samples of a size the investigator chose, so the row totals are design constants. That is a test of homogeneity.
- +1.5Its null hypothesis is that the distribution of support is the same in all three suburb populations. Degrees of freedom are two times one, which is two.
Key terms
- Contingency table
- A table of counts cross classifying observations on two categorical variables. Its row and column totals are called the margins, and which of them were fixed by the design decides the test.
- Marginal probability
- The probability of a level of one variable, obtained by summing the joint probabilities across the other. Under both nulls in this chapter the cell probabilities are products of two marginals.
- Independence
- The hypothesis that the joint distribution of two variables factors into their marginals, so that knowing one tells you nothing about the other. It applies to one sample classified two ways.
- Hypergeometric distribution
- The distribution of the number of successes when drawing without replacement from a finite collection of two kinds of item. It is the exact null distribution of a two by two table with fixed margins.
- Exact test
- A test whose p-value is computed by enumerating every possible outcome rather than by approximating with a continuous distribution. It has no expected count condition to satisfy.
- Continuity correction
- An adjustment that shrinks each absolute gap by a half before squaring, available only for a two by two table. It makes the statistic smaller and the p-value larger, so it is conservative.
- Simulated p-value
- A p-value obtained by generating many random tables with the observed margins and counting how many produce a statistic at least as large. It reports no degrees of freedom, which is correct rather than an omission.
- Conditional maximum likelihood estimate
- The odds ratio reported by the exact test, which is not the cross product of the table. Quoting it as the sample odds ratio is a small but real error.
- Fixed margin
- A row or column total determined by the design rather than observed. Fixed row totals indicate separately drawn samples and therefore a test of homogeneity.
- Random seed
- A value that makes a simulation reproducible. Any simulated p-value moves slightly between runs, so the seed is fixed before the simulation and reported with the result.
Contingency tables: homogeneity, independence, exact tests FAQ
If the arithmetic is identical, why does it matter which test I name?
Because the conclusion differs, and the conclusion is where the marks are. A test of homogeneity concludes that the groups which were sampled differ in their outcome distribution. A test of independence concludes that two variables are associated within one population.
Those are statements about different things, and a script that computes the right number and attaches the wrong sentence has answered a question that was not asked. The hypotheses differ too, so the loss is usually more than one mark.
How do I tell the two apart in a question?
Hunt for a sentence that names a sample size per group. Phrases such as one hundred were selected from each of three regions describe fixed row totals and therefore homogeneity. Phrases such as three hundred respondents were asked both questions describe one sample classified two ways and therefore independence.
If the question genuinely does not say, the honest answer names the ambiguity and states which test each reading would call for.
What exactly does the expected count condition apply to?
To the expected counts, every time. It is not a condition on the observed counts, and an observed zero in a cell whose expected count is twelve is perfectly acceptable. Students routinely check the wrong table and the error runs in both directions: it declares valid tests invalid, and more dangerously it lets a table with a small expected count through because the observed counts happened to be larger.
Why does Fisher's exact test not need an expected count condition?
Because it does not approximate anything. With the row and column totals held where they are, a two by two table is completely determined by a single cell, so the number of possible tables is small and finite. Each has an exact probability under the hypothesis of no association, and the p-value is the sum of the probabilities of the tables at least as extreme as the one observed.
There is no continuous curve being fitted to discrete counts, so there is nothing for a minimum count to protect.
What should I do with a large table that has small expected counts?
Pool first if the categories have natural neighbours, and recount the degrees of freedom afterwards. If pooling is not available, or would destroy the comparison the question asks about, use a simulated p-value with the margins held fixed, which reproduces the exact idea numerically for a table of any size.
The one response that is never acceptable is reporting the ordinary test with a note that the condition failed, since the condition is what makes the printed p-value mean anything.
Exam move
The whole chapter fits into four things you can make for yourself, and making them is the revision. The comparison: homogeneity down one side, independence down the other, and seven rows to fill in, sampling, what is fixed, null hypothesis, expected counts, statistic and distribution, what the conclusion names, and the phrase in a question that gives it away.
Two of those rows come out identical, and that is the point of building it. The derivation: get the degrees of freedom from first principles once, starting at the number of cells, removing one for the constraint that probabilities sum to one, and removing the estimated marginals, then do it again a week later without looking, because deriving it takes fifteen seconds and misremembering the product costs a whole question.
The arithmetic habit: never compute expected counts without the two self checks running, since a table whose expected rows do not sum to the row totals has an error in it that no amount of care later will fix.
The decision list: every expected count above five means the ordinary test, a two by two table with a small expected count means the exact test, borderline counts in a two by two table allow the continuity correction, and a larger table with small counts means simulation.
Working through Contingency tables: homogeneity, independence, exact tests in DATA2002? Sia is AskSia’s AI Statistics tutor — ask any DATA2002 Contingency tables: homogeneity, independence, exact tests question and get a clear, step-by-step explanation grounded in how DATA2002 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.