Primer 7 · Measuring association
The 2×2 table, and the four numbers you read off it
This page runs R inside your browser. It needs about 17 MB on first load and a minute or two on a slow connection.
This page still works without them. Every answer is printed in the text as well, so you can follow the whole primer with a pencil and a calculator.
Primer 6 measured disease in one group. Now we compare 2 groups, which is where analytical epidemiology starts.
The 2×2 table
4 numbers. Learn this layout and keep to it. Many mistakes with odds ratios are really mistakes about which cell is which.
| Disease | No disease | Total | |
|---|---|---|---|
| Exposed | a | b | a + b |
| Unexposed | cc | d | cc + d |
Exposure down the side, outcome across the top. Always.
In the code below the 4 cells are called a, b, cc and d.
The third is cc, not c. c() is a function you use in almost every line. Naming a variable over it is a bad habit.
Our worked example: a cohort of 2,000 adults followed for five years for coronary heart disease.
| CHD | No CHD | Total | |
|---|---|---|---|
| Smoker | 90 | 910 | 1000 |
| Non-smoker | 30 | 970 | 1000 |
Risk is 0.09 in smokers and 0.03 in non-smokers. Everything below is a different way of comparing those two numbers.
Risk ratio: how many times more likely
\[\text{RR} = \frac{\text{risk in the exposed}}{\text{risk in the unexposed}}\]
RR = 3.00. Smokers were three times as likely to develop CHD.
How to read any risk ratio:
| RR | Means |
|---|---|
| 1 | no association; the two risks are the same |
| above 1 | exposure is associated with more disease |
| below 1 | exposure is associated with less disease — protective |
The RR is 3, but the extra risk is 6 people per 100 over five years. A large ratio on top of a tiny baseline risk is still a tiny absolute effect. This is a common way health statistics mislead in the press, and it is why the risk difference below matters as much as the ratio.
Risk difference: how much extra disease
\[\text{RD} = \text{risk}_{\text{exposed}} - \text{risk}_{\text{unexposed}}\]
RD = 0.06, or 6 extra cases per 100 smokers over five years.
The ratio tells you about cause: how strongly is this exposure related to this disease? The difference tells you about impact: how much disease would go away if the exposure did?
A good results section reports both.
Watch for a paper that says “three times the risk” and never prints the 6 per 100. Three times sounds alarming. 6 per 100 over five years is something a patient can weigh against the cost of a tablet. Reporting only the first is how a small effect is made to sound large.
Number needed to treat, and to harm
\[\text{NNT} = \frac{1}{|\text{RD}|}\]
16.7. The exposure here is harmful, so this is a number needed to harm.
About 17 people would have to smoke for 5 years for one extra case of CHD to appear.
Always round NNT up when you report it, and always state the time period. “NNT 17 over five years” is a sentence a patient can act on. “NNT 17” is not.
Odds ratio: the one people get wrong
Odds is not risk. Odds compares those with the disease to those without, rather than to the total.
\[\text{odds} = \frac{a}{b} \qquad \text{OR} = \frac{a/b}{cc/d} = \frac{a \times d}{b \times cc}\]
OR = 3.20, against an RR of 3.00. The odds ratio is further from 1 than the risk ratio. It always is: above 1 the OR is larger, below 1 it is smaller.
Because in a case-control study you cannot compute a risk.
You chose how many cases and how many controls to recruit. So a + b is a number you decided, not a number you observed. Any risk you compute from it measures your sampling plan, not the world.
The odds ratio survives that. It is the same whether you sample on exposure or on disease. That is why case-control studies work at all.
When the disease is rare, b is close to a + b and d is close to cc + d, so OR ≈ RR. When the disease is common, they diverge sharply, and an OR read aloud as “three times more likely” overstates the effect.
Our example has a 9% risk, which is not rare, and the OR is already 6.6% higher than the RR. At 30% risk the gap would be much wider. Never describe an odds ratio in the words of a risk ratio unless the outcome is genuinely uncommon.
Attributable fraction: how much of the disease is down to this
Among the exposed, what share of their disease is attributable to the exposure?
\[\text{AF}_{\text{exposed}} = \frac{\text{RR} - 1}{\text{RR}}\]
0.667. Two-thirds of the CHD in smokers is attributable to their smoking. That assumes the association is causal and unconfounded, which is a large assumption. We take it apart in the room.
For the whole population you also need how common the exposure is:
0.5. Half of all CHD in this population is attributable to smoking — because half the population smokes and smoking triples the risk. A strong exposure that almost nobody has moves this number very little; that is why population impact and individual risk are different arguments.
Doing it with a table object
You will usually get a 2×2 out of table() rather than by typing four numbers.
Read the printed table before you trust it.
table() sorts its levels alphabetically, so FALSE comes before TRUE. The first row is the unexposed. The first column is the non-diseased. That is upside down and back to front compared with the layout above.
RR = 3.00 again: 3 of 6 exposed versus 1 of 6 unexposed.
tab[2, 2] will silently become the wrong cell the moment your data has a different set of levels, or a level with no observations in it. tab["TRUE", "TRUE"] either gives the right cell or fails loudly.
On the course we use epitools. It does not reorder the table for you: it reads the first row as unexposed and the first column as non-case, and you pass rev= to change that. So the ordering above is not a detail you can hand off.
What you should now be able to do
- Lay out a 2×2 table the same way every time, exposure down the side.
- Compute a risk ratio, a risk difference, an odds ratio and an NNT from it.
- Say what each one is for: ratio for cause, difference for impact.
- Explain why an odds ratio is not a risk ratio, and when the gap matters.
- Compute an attributable fraction, and say what it assumes.
- Pull cells out of a
table()by name rather than by position.
Every measure here compares exposed with unexposed as if the two groups differed only in the exposure. They almost never do. Study design, bias and confounding are what the course spends its time on.
You have finished the primers
→ Step 5: additional resources