Calcylator
Odds ratio from contingency table

Odds ratio from contingency table:
formula and worked example

Four counts in a 2x2 grid, one cross-product, and a ratio that is easy to misread as a risk ratio.

Calcylator Editorial Team

Updated · 5 min read

Comparing odds across two groups

An odds ratio compares how the odds of an outcome differ between an exposed and an unexposed group. Odds are the number with the outcome divided by the number without it, so a group where 30 people have the outcome and 70 do not has odds of 30 to 70, about 0.43.

Odds ratios are the standard summary of case-control studies, where the investigator picks people by outcome and so cannot calculate risks directly. They are also what logistic regression estimates, which makes them familiar across medicine, social science and marketing analytics.

The measure is symmetric in an appealing way: the odds ratio of exposure given outcome equals the odds ratio of outcome given exposure. That property is why case-control designs can still estimate it.

The word 'odds' often trips up newcomers, so keep a gambler's phrasing in mind. Odds of 3 to 1 against mean one success for every three failures, a probability of 25%. In the example table the exposed group's odds of 30 to 70 correspond to a probability of 30%, and the unexposed group's 20 to 80 to 20%, so odds and probabilities are close at low values and drift apart as probabilities rise.

Formula and the 2x2 layout

Odds ratio from contingency table =a × d ÷ (b × c)
a:
A
b:
B
c:
C
d:
D
Result is a unitless ratio. In the usual layout a and b are the exposed with and without the outcome, and c and d are the unexposed with and without the outcome.
  • A: exposed group with the outcome.
  • B: exposed group without the outcome.
  • C: unexposed group with the outcome.
  • D: unexposed group without the outcome.

The formula is the cross-product ratio: multiply the diagonal cells a and d, then divide by the product of b and c. If you rotate the table so that the exposure and outcome swap places, the answer is unchanged, but swapping only the rows inverts it, so keep track of which group sits in which row.

Sample design determines what the cells mean. In a cohort study the row totals are set by the investigator and each row's risk is meaningful. In a case-control study the column totals are fixed, so only the cross-product is trustworthy and the risks computed from the rows are not.

Worked example with 30, 70, 20 and 80

Of 100 exposed people, 30 had the outcome and 70 did not. Of 100 unexposed people, 20 had the outcome and 80 did not.

  • A

    30

  • B

    70

  • C

    20

  • D

    80

Odds ratio from contingency table

1.714 ×

Exposed odds are 30/70 and unexposed odds are 20/80; the cross-product gives the same ratio in one step.

  1. Multiply the diagonal a x d: 30 x 80 = 2,400.
  2. Multiply the off-diagonal b x c: 70 x 20 = 1,400.
  3. Divide: 2,400 / 1,400 = 1.714.
  4. Check using odds: (30/70) / (20/80) = 0.4286 / 0.25 = 1.714.

What 1.71 does and does not mean

An odds ratio of 1 indicates no association, above 1 indicates higher odds of the outcome in the exposed group, and below 1 indicates lower odds. Here the exposed group has about 71% higher odds than the unexposed group.

The temptation is to read this as 71% higher risk. It is not. The risks in this table are 30% and 20%, giving a risk ratio of 1.5. The odds ratio of 1.71 is further from 1 because odds stretch faster than probabilities as an outcome becomes common.

When the outcome is rare, say under about 10% in both groups, the two measures are nearly equal and the distinction fades. For common outcomes, quote the risk ratio if the study design allows it.

Always attach a sense of precision. For a table this small, the interval around 1.71 is wide enough to include 1, so the data alone would not rule out no association. Intervals for log odds ratios are built from the reciprocals of the four counts, which is why a single small cell dominates the uncertainty.

What happens when cell A grows

Odds ratio when cell A rises by 10% and B, C and D stay fixed
ScenarioACalculated result
Original assumptions301.714 ×
A increased by 10%331.886 ×

Raising a from 30 to 33 lifts the ratio from 1.714 to 1.886, a rise of exactly 10%, since the ratio is proportional to a. The same logic runs in reverse for b and c: increasing either one reduces the ratio. Doubling a with everything else fixed doubles the ratio, which is a reminder that small counts in the off-diagonal cells can move the result a long way.

Frequent errors with 2x2 tables

  • Reading the odds ratio as a risk ratio, which exaggerates the effect when the outcome is common.
  • Misplacing cells so that exposure and outcome rows are swapped, giving the reciprocal of the correct answer.
  • Hitting a zero cell. The ratio is undefined or infinite, and a common remedy is to add 0.5 to every cell, which should be stated when used.
  • Ignoring confounding. A crude odds ratio can differ greatly from one adjusted for age, sex or other factors.
  • Presenting the figure without its confidence interval, so the reader cannot tell a stable estimate from a fluke on small counts.

A short checklist

Before trusting a calculated odds ratio, confirm that the table adds up to the sample size you expected, that a and d are the cells you meant, and that no cell is tiny. With the example table, the totals are 100 exposed and 100 unexposed, with 50 outcomes overall, which is consistent with a case-control or cohort layout. If a reader has only the odds ratio and not the table, ask for the counts.

Common questions

How do you calculate an odds ratio from a 2x2 table?

Multiply the top-left cell by the bottom-right cell, then divide by the product of the top-right and bottom-left cells. With 30, 70, 20 and 80 the result is 2,400 divided by 1,400, or 1.714.

What does an odds ratio of 1 mean?

An odds ratio of exactly 1 means the odds of the outcome are the same in both groups, so there is no association between exposure and outcome in the data. Values above or below 1 indicate a positive or negative association.

Is an odds ratio the same as relative risk?

Not generally. They are close when the outcome is rare, but the odds ratio moves further from 1 than the relative risk when the outcome is common. In the example, an odds ratio of 1.71 corresponds to a relative risk of 1.5.

What if a cell in the table is zero?

A zero makes the ratio undefined or infinite. Analysts commonly add 0.5 to each cell, the Haldane-Anscombe correction, or use exact methods. Whatever is done should be disclosed because the result is sensitive to it.

When should I use an odds ratio instead of a risk ratio?

Use it for case-control studies, where risks cannot be computed, and for logistic regression output. For cohort studies and trials where risks are directly observed, a risk ratio is usually easier to interpret.

Was this guide helpful?

Continue reading

View all blogs