Odds Ratio & Relative Risk Calculator

Odds Ratio & Relative Risk Calculator

Enter the four counts of a 2×2 table and get the odds ratio, relative risk, risk difference and number needed to treat — each with a confidence interval and a forest-plot chart.

OutcomeNo outcomeTotal
Exposed100
Unexposed100
Total75125200
a = exposed with the outcome, b = exposed without it, c = unexposed with the outcome, d = unexposed without it. Counts must be whole numbers.
ODDS RATIO
1.91

The odds ratio is 1.91 (95% CI 1.07 to 3.42) — the odds of the outcome are 1.91 times the odds in the unexposed group. p = 0.0293, so the association is significant at α = 0.05.

The outcome is common: in the control group the outcome occurred in 30% of people (p0 = 0.30), above 0.10 — so the odds ratio (1.91) overstates the relative risk (1.50). Quote the relative risk here, not the odds ratio.
Odds ratio
1.9091
OR 95% CI
1.067 – 3.415
Relative risk
1.5000
RR 95% CI
1.037 – 2.171
Risk difference
0.1500
RD 95% CI
0.017 – 0.283
Number needed to treat
7 people
Wald z / p-value
z = 2.18, p = 0.0293

Calculation

  1. Table: a = 45, b = 55, c = 30, d = 70; N = 200. Risks: p1 = 45/100 = 0.45, p0 = 30/100 = 0.30.
  2. Odds ratio = (45 × 70)/(55 × 30) = 1.9091. SE(ln OR) = 0.2967 (Woolf).
  3. 95% CI for OR = exp(ln 1.9091 ± 1.96 × 0.2967) = [1.067, 3.415].
  4. Relative risk = (45/100)/(30/100) = 1.5000. SE(ln RR) = 0.1886 (Katz). 95% CI = [1.037, 2.171].
  5. Risk difference = 0.45 − 0.30 = 0.1500. SE(RD) = 0.0676. 95% CI = [0.017, 0.283].
  6. NNT = 1/|0.15| = 6.67 → 7 people.
  7. Wald z = ln(OR)/SE = 2.18, p = 0.0293. Decision: p < 0.05, so the association is significant at α = 0.05.

Your 2×2 table

Row percentages show the risk of the outcome in each group.

OutcomeNo outcomeTotal
Exposed45 (45%)55 (55%)100
Unexposed30 (30%)70 (70%)100
Total75125200

Forest plot: odds ratio and relative risk

Each line is a confidence interval; the dot is the estimate. The red dashed line at 1 means no effect — an interval that crosses it is not significant at the chosen level.

Is the association significant? For a small table use Fisher’s exact test; for a larger table use the chi-square test. To compare two proportions directly, use the two-proportion z-test.

Risk difference

The risk difference is on a linear scale; the red dashed line at 0 means no effect.

An odds ratio compares the odds of an outcome in two groups; a relative risk compares the risks directly. Enter the four counts of a 2x2 table and get the odds ratio, relative risk, risk difference and number needed to treat — each with a 95% confidence interval and a forest-plot chart.

An odds ratio and a relative risk are NOT the same number — the odds ratio compares odds, the relative risk compares risks, and they drift apart when the outcome is common (see the warning below). This page gives you both, with a confidence interval for each, so you can quote the right one.

To test whether the association is significant, use Fisher’s exact test. For larger tables, the chi-square test is the significance test. To measure how strong the association is — and in which direction — use the odds ratio and relative risk below.

How to use the odds ratio calculator

  1. Enter the four counts in the 2×2 table: a = exposed with the outcome, b = exposed without it, c = unexposed with the outcome, d = unexposed without it. The totals update as you type.
  2. Choose the study design. Cohort and randomised trials can report a relative risk; a case-control study can only report an odds ratio (the calculator hides the relative risk for you); a cross-sectional study reports a prevalence ratio.
  3. Choose the confidence level — 90%, 95% or 99%. The intervals and the significance decision follow the level you pick.
  4. Read the results. The odds ratio is the headline number; the relative risk, risk difference and number needed to treat sit beside it, each with its own interval, and the forest plot shows the intervals against the no-effect line.

Try it now: the worked example is already loaded — 45 of 100 recovered on the drug, 30 of 100 on placebo. The calculator gives an odds ratio of 1.91 (95% CI 1.07 to 3.42), a relative risk of 1.50 (95% CI 1.04 to 2.17), a risk difference of 0.15 and a number needed to treat of 7. Press “Worked example: survey” for the second example.

What is an odds ratio?

An odds ratio compares the odds of an outcome in two groups. Odds are not the same as risk: the odds of recovery are the number who recovered divided by the number who did not, while the risk is the number who recovered divided by everyone in the group.

For a 2×2 table with cells a, b, c, d (exposed with the outcome, exposed without it, unexposed with the outcome, unexposed without it), the odds ratio is

OR = (a × d) / (b × c)

An odds ratio of 1 means the odds are the same in both groups — no association. Above 1, the odds are higher in the exposed group; below 1, they are lower. The odds ratio is the only measure of association you can get from a case-control study, because that design fixes how many cases and controls you recruit, not how many people were exposed.

What is a relative risk?

A relative risk compares the risks directly. The risk in the exposed group is p1 = a/(a+b); the risk in the unexposed group is p0 = c/(c+d). The relative risk is

RR = p1 / p0 = [a/(a+b)] / [c/(c+d)]

A relative risk of 1.50 means the outcome is 50% more likely in the exposed group — a statement about risk that most readers understand at once. That is why, when the outcome is common, you should quote the relative risk rather than the odds ratio: the odds ratio overstates it. You can only compute a relative risk when you know the risks, which means a cohort study or a randomised trial — not a case-control study.

Odds vs risk, side by side

The same table gives two different answers, because odds and risk are different quantities. Here is the drug-trial table worked both ways:

Exposed (drug)Unexposed (placebo)Ratio
Risk of recovery45/100 = 0.4530/100 = 0.30RR = 0.45/0.30 = 1.50
Odds of recovery45/55 = 0.8230/70 = 0.43OR = 0.82/0.43 = 1.91
Risk difference0.45 − 0.30 = 0.15NNT = 1/0.15 = 7

The relative risk says recovery is 50% more likely on the drug. The odds ratio says the odds are 91% higher. Both are correct — they are different summaries of the same table. The odds ratio is further from 1 because odds stretch the scale when the outcome is common.

Worked example 1: the drug trial

45 of 100 patients recovered on the drug, and 30 of 100 recovered on placebo. The table is [[45, 55], [30, 70]].

  • Odds ratio: (45 × 70)/(55 × 30) = 1.9091. The standard error of ln(OR) is 0.2967 (Woolf), so the 95% confidence interval is [1.067, 3.415].
  • Relative risk: (45/100)/(30/100) = 1.5000. The standard error of ln(RR) is 0.1886 (Katz), so the 95% confidence interval is [1.037, 2.171].
  • Risk difference: 0.45 − 0.30 = 0.1500, with a 95% confidence interval of [0.017, 0.283].
  • Number needed to treat: 1/0.15 = 6.67, rounded up to 7 people — treat 7 people for one extra recovery.
  • Significance: the Wald z is 2.18 and the p-value is 0.0293, so the association is significant at α = 0.05. The outcome is common (p0 = 0.30, above 0.10), so the calculator warns you that the odds ratio (1.91) overstates the relative risk (1.50) — quote the relative risk.

Worked example 2: the survey

A survey found 30 of 100 exposed people and 15 of 100 unexposed people with the outcome. The table is [[30, 70], [15, 85]].

  • Odds ratio: (30 × 85)/(70 × 15) = 2.4286, 95% CI [1.211, 4.870].
  • Relative risk: (30/100)/(15/100) = 2.0000, 95% CI [1.149, 3.482].
  • Risk difference: 0.30 − 0.15 = 0.1500, 95% CI [0.036, 0.264].
  • Number needed to treat: 1/0.15 = 6.67, rounded up to 7 people.
  • Significance: the Wald z is 2.50 and the p-value is 0.0124, so the association is significant at α = 0.05.

Notice that the odds ratio (2.43) is again larger than the relative risk (2.00) — the same pattern as the drug trial, because the outcome is common in both groups (15% and 30%).

When the odds ratio and the relative risk disagree

When the outcome is rare, the odds ratio and the relative risk are almost the same number — this is the “rare-disease assumption” that lets case-control studies quote an odds ratio as if it were a relative risk. When the outcome is common, they pull apart, and the odds ratio is always the more extreme of the two.

Take a table where the outcome is very common: 80 of 100 exposed and 60 of 100 unexposed have it ([[80, 20], [60, 40]]). The relative risk is 1.33 (95% CI 1.105 to 1.609) — a modest 33% increase in risk. The odds ratio is 2.67 (95% CI 1.417 to 5.020) — it looks twice as strong. Quoting 2.67 as if it were a risk ratio would double the apparent effect. The calculator shows its warning whenever the control-group risk (p0) is above 0.10.

Rule of thumb: if the outcome occurs in more than about 10% of the control group, quote the relative risk. If it is rarer than that, the odds ratio and the relative risk are close enough that either will do — and in a case-control study the odds ratio is the only one you have.

The confidence intervals

All four intervals are built on the log scale (except the risk difference), because ratios are skewed and their logarithms are close to normal:

  • Odds ratio (Woolf): SE(ln OR) = √(1/a + 1/b + 1/c + 1/d). The interval is exp(ln OR ± z × SE), where z is 1.645 for 90%, 1.96 for 95% and 2.576 for 99%.
  • Relative risk (Katz): SE(ln RR) = √(1/a − 1/(a+b) + 1/c − 1/(c+d)). The interval is exp(ln RR ± z × SE).
  • Risk difference (Wald): SE(RD) = √(p1(1−p1)/(a+b) + p0(1−p0)/(c+d)). The interval is RD ± z × SE — and it is clamped to [−1, 1], because a risk difference cannot exceed 1. In the table [[8, 2], [1, 9]] the raw upper bound is 1.0099; the calculator shows 1.00 and says so.
  • Number needed to treat: NNT = 1/|RD|, rounded up to a whole person — you cannot treat 6.67 people, so the answer is 7. If the risk difference is negative, the same number is the number needed to harm.

The Wald test for the odds ratio is z = ln(OR)/SE(ln OR), with a two-tailed p-value from the normal distribution. The decision on the page compares that p-value with α = 1 − the confidence level you chose (0.05 for a 95% interval).

What if a cell is zero?

A zero cell makes the raw odds ratio 0 or undefined (division by zero), and the log standard errors blow up. The calculator applies the Haldane–Anscombe correction: it adds 0.5 to all four cells and says so on the results, rather than hiding it. The raw odds ratio is shown as “undefined (zero cell)” alongside.

For example, the table [[5, 0], [10, 20]] has a zero in the exposed, no-outcome cell. After adding 0.5 to each cell the odds ratio is 21.48 (95% CI 1.081 to 426.68) and the relative risk is 2.71 (95% CI 1.565 to 4.681). The interval is very wide — that is honest: a single zero cell carries almost no information about the upper end.

Study design matters

Which measures you may report depends on how the data were collected:

DesignWhat you can reportWhy
Cohort studyOR, RR, RD, NNTYou follow exposed and unexposed people, so you know both risks.
Randomised trial (RCT)OR, RR, RD, NNTRandomisation fixes the groups; the risks are known.
Case-control studyOR onlyYou fix how many cases and controls to recruit, so the risks are not known — only the odds.
Cross-sectional studyOR, RD, prevalence ratioYou measure exposure and outcome at one moment, so the “relative risk” is a prevalence ratio, not a true risk ratio.

Choose the design in the calculator and it shows you only the measures your study supports. If you pick case-control, the relative risk, risk difference and NNT are hidden and the page explains why.

Odds ratio in Excel

Excel has no built-in odds-ratio or relative-risk function. You can compute them by hand from four cells — say A1 = a, B1 = b, C1 = c, D1 = d:

  • Odds ratio: =(A1*D1)/(B1*C1)
  • Relative risk: =(A1/(A1+B1))/(C1/(C1+D1))
  • Risk difference: =A1/(A1+B1)-C1/(C1+D1)
  • 95% CI for the odds ratio: =EXP(LN((A1*D1)/(B1*C1))-1.96*SQRT(1/A1+1/B1+1/C1+1/D1)) for the lower bound, and the same with +1.96 for the upper bound.
  • 95% CI for the relative risk: =EXP(LN((A1/(A1+B1))/(C1/(C1+D1)))-1.96*SQRT(1/A1-1/(A1+B1)+1/C1-1/(C1+D1))) for the lower bound, and the same with +1.96 for the upper bound.

The confidence intervals need the log-scale standard errors above — the point estimates alone are not enough. If a cell is zero, add 0.5 to all four cells first (the Haldane–Anscombe correction) or the formulas divide by zero.

Frequently asked questions

What is the difference between an odds ratio and a relative risk?

An odds ratio compares odds — the number with the outcome divided by the number without it in each group. A relative risk compares risks — the number with the outcome divided by everyone in each group. They are the same only when the outcome is rare; when it is common, the odds ratio is further from 1 than the relative risk.

When is the odds ratio a good stand-in for the relative risk?

When the outcome is rare — roughly, when it occurs in fewer than 10% of people. That is the “rare-disease assumption”. In a case-control study you have no choice: the odds ratio is the only measure available, and it is a good stand-in exactly when the outcome is rare.

Why is my odds ratio so much bigger than my relative risk?

Because the outcome is common in your data. Odds stretch the scale: when the risk is 0.45, the odds are 0.82; when the risk is 0.30, the odds are 0.43. The ratio of the odds (1.91) is bigger than the ratio of the risks (1.50). It is not an error — it is the two measures answering different questions. Quote the relative risk when the outcome is common.

What do I do with a zero cell?

Use the Haldane–Anscombe correction: add 0.5 to all four cells before computing. The calculator does this for you and labels it on the results, with the raw odds ratio shown as “undefined (zero cell)”. Do not just drop the row or the column — that throws away the information the zero carries.

What is NNT, and why is it rounded up?

The number needed to treat is 1 divided by the absolute risk difference: how many people you must treat to prevent (or cause) one extra outcome. It is rounded up to a whole person because you cannot treat a fraction of a person — 6.67 becomes 7. If the risk difference is negative, the same number is the number needed to harm.

Can I use this for a case-control study?

Yes — pick “Case-control study” in the design selector. The calculator shows the odds ratio only, because a case-control study fixes the numbers of cases and controls, so the risks (and therefore the relative risk, risk difference and NNT) cannot be computed. The page explains the reason on the results.

Sources: NIST Dataplot reference, ODDS RATIO — “The odds ratio is (N11·N22)/(N12·N21)”, with the bias-corrected version adding 0.5 to each cell, the same correction this calculator applies to zero cells; NIST/SEMATECH e-Handbook, 7.3.3. How can we determine whether two processes produce the same proportion of defectives?; Fleiss, Levin & Paik (2003), Statistical Methods for Rates and Proportions, 3rd ed., Wiley, ch. 1. All examples on this page were checked by hand against the formulas above.

See all 67 free statistics tools on Empirical Rule Calculators.

Next steps

๐Ÿ“˜โ— Live

What Is a Confidence Interval?

What a confidence interval means โ€” and what it does not.GuideRead the Guide โ†’

๐Ÿงฎโ— Live

Fisher’s Exact Test Calculator

Test the same 2ร—2 table for significance โ€” the exact p-value.CalculatorTry Calculator โ†’

๐Ÿงฎโ— Live

Chi-Square Test Calculator

Test independence on the same table โ€” the large-count test.CalculatorTry Calculator โ†’