Odds Ratio & Relative Risk Calculator
Enter the four counts of a 2 × 2 table — exposure by outcome — and get the odds ratio, risk ratio and risk difference, each with a 95% confidence interval, plus the number needed to treat or harm. Pick your study design and the calculator shows only the measures that design supports, with the working for each. Free, no sign-up, and nothing leaves your browser.
| Outcome | No outcome | Total | |
|---|---|---|---|
| Exposed | 0 | ||
| Unexposed | 0 | ||
| Total | 0 | 0 | 0 |
Enter the four counts — whole numbers, zero or more — to see the odds ratio, risk ratio and risk difference.
How to Use the Odds Ratio & Relative Risk Calculator
- 1. Choose the study design. A cohort study or trial follows exposed and unexposed people forward; a case-control study samples people with and without the outcome; a cross-sectional study measures both at one time. The design decides which measures are valid.
- 2. Enter the four counts. Rows are exposed and unexposed (or treatment and control); columns are with and without the outcome. The totals fill in as you type, so you can check them against your paper's group sizes.
- 3. Read the measures. The table gives each estimate with its 95% confidence interval and a Wald p-value. For a case-control design only the odds ratio appears, with the reason.
- 4. Check the number needed to treat. For a cohort or trial, the calculator converts the risk difference into an NNT or NNH and explains its interval. Copy the result line when you are done.
Formulas for the Odds Ratio, Risk Ratio and Risk Difference
| Outcome | No outcome | Total | |
|---|---|---|---|
| Exposed | a | b | a + b |
| Unexposed | c | d | c + d |
- Odds ratio: OR = (a × d) / (b × c). The 95% CI is Woolf's: exp(ln OR ± 1.96 × SE), with SE(ln OR) = √(1/a + 1/b + 1/c + 1/d).
- Risk ratio (relative risk): RR = [a/(a + b)] / [c/(c + d)]. The 95% CI is Katz's log method: exp(ln RR ± 1.96 × SE), with SE(ln RR) = √(1/a − 1/(a + b) + 1/c − 1/(c + d)).
- Risk difference: RD = r₁ − r₀, the risk in the exposed minus the risk in the unexposed, with the Wald interval RD ± 1.96 × √(r₁(1 − r₁)/n₁ + r₀(1 − r₀)/n₀).
- Number needed to treat: NNT = 1 / |RD|, the number of people who must be exposed for one more (or one fewer) to have the outcome. Its interval is the reciprocal of the RD limits (Altman, 1998).
When a zero cell makes a ratio or its standard error undefined, the calculator adds 0.5 to all four cells for that measure — the Haldane–Anscombe correction — and says so. For the odds ratio that is any zero; for the risk ratio, a zero in a or c. If a whole row or column is zero, no ratio can be estimated.
Worked Example: Night Shifts and High Blood Pressure
A cohort study follows 200 night-shift workers and 200 day workers for five years: 40 night workers and 20 day workers develop hypertension. Enter a = 40, b = 160, c = 20 and d = 180, or press Load example.
| Measure | Estimate | 95% CI | p |
|---|---|---|---|
| Odds ratio | 2.250 | [1.263, 4.008] | 0.006 |
| Risk ratio | 2.000 | [1.213, 3.296] | 0.007 |
| Risk difference | 0.100 | [0.031, 0.169] | — |
The odds ratio is (40 × 180) / (160 × 20) = 7,200 / 3,200 = 2.250, with SE(ln OR) = 0.2946. The risks are 40/200 = 0.200 and 20/200 = 0.100, so the risk ratio is 2.000 — night workers had twice the risk — and the risk difference is 0.100, ten extra cases per 100 workers over five years. That gives NNT = 1 / 0.100 = 10.0: about 10 workers on night shifts for one additional case of hypertension, a number needed to harm, with a 95% CI of 5.9 to 32.6.
Notice that the odds ratio (2.25) is further from 1 than the risk ratio (2.00). The two agree only when the outcome is rare — a common rule of thumb is under about 10% in both groups. With a 20% risk among the exposed, reading the odds ratio as "2.25 times the risk" would overstate the effect.
Odds Ratio or Risk Ratio? Choose by Study Design
| Design | What you can estimate | Why |
|---|---|---|
| Cohort study or randomized trial | Risk ratio, risk difference, NNT and odds ratio | Exposure groups are followed, so each row's share with the outcome is a real risk. |
| Case-control study | Odds ratio only | You fix the numbers of cases and controls, so the row percentages reflect your sampling, not risk. |
| Cross-sectional survey | Prevalence ratio and prevalence odds ratio | Outcome and exposure are measured together, so you have prevalences and no time order. |
The case-control rule is the one most often broken. If the hypertension table above had come from a study that recruited 60 people with hypertension and 340 without, the share of night workers who are "cases" would depend entirely on how many controls the researchers chose to recruit. The odds ratio survives because it is symmetric — the odds of exposure among cases over the odds among controls equals the odds of the outcome among the exposed over the unexposed — and, when the outcome is rare in the population, it approximates the risk ratio.
Reporting and Common Mistakes
Report the measure, its interval and the counts behind it: "Night-shift workers were more likely to develop hypertension (20.0% vs 10.0%), RR = 2.00, 95% CI [1.21, 3.30]." A ratio's interval is not symmetric around the estimate, because it is built on the log scale.
- Calling an odds ratio a risk ratio. "Twice as likely" describes a risk ratio of 2, not an odds ratio of 2 — the gap widens as the outcome becomes common.
- Swapping rows or columns. With the exposure in the columns, the ratios come out inverted; keep exposure in the rows and the outcome in the first column.
- Reporting an NNT without its interval. When the risk difference's interval crosses zero, the NNT's interval runs through infinity, and a single NNT figure hides that.
- Ignoring confounding. These are crude measures from one table. Adjusted estimates need stratification or regression.
Frequently Asked Questions
- What is the difference between an odds ratio and a relative risk?
- The relative risk (risk ratio) divides the probability of the outcome in the exposed group by the probability in the unexposed group. The odds ratio divides odds instead — the probability of the outcome over the probability of not having it. When the outcome is rare the two are close; when it is common, the odds ratio lies further from 1 than the risk ratio, as in the worked example (2.25 against 2.00).
- Why can't I calculate relative risk from a case-control study?
- Because a case-control study fixes how many people with and without the outcome are included. The proportion of exposed people who are cases then depends on the number of controls you chose to recruit, so it is not a risk. The odds ratio does not depend on that choice, which is why it is the measure for case-control designs.
- What does an odds ratio below 1 mean?
- An odds ratio below 1 means the outcome is less likely among the exposed — exposure is associated with lower odds, as for a protective factor or an effective treatment. An OR of 0.5 means the odds are halved. If the 95% confidence interval includes 1, the data are compatible with no association.
- What happens when a cell in the 2 × 2 table is zero?
- A zero makes the odds ratio 0 or infinite and its standard error undefined. The calculator then adds 0.5 to every cell (the Haldane–Anscombe correction) for that measure and tells you it did. The corrected estimate is a pragmatic fix; with very sparse tables, an exact method such as Fisher's exact test is a useful check.
- Why does the NNT confidence interval sometimes include infinity?
- The NNT is 1 divided by the risk difference. When the risk difference's interval runs from a negative to a positive value, it passes through zero, and 1 / 0 is infinite. The NNT interval then runs from a number needed for benefit, through infinity, to a number needed for harm (Altman, 1998) — an honest way of saying the data cannot rule out either.