# Odds Ratio Calculator

> Computes the odds ratio and relative risk of a 2×2 exposure/outcome table with confidence intervals by the log method (Woolf), plus the absolute risk difference and the number needed to treat or harm.

- Calculator id: `odds-ratio` · Category: Statistics & Probability (`statistics`) · Tool name: `calculate_odds_ratio`
- Canonical page: https://tttkmbb.com/statistics/odds-ratio · This document: https://tttkmbb.com/statistics/odds-ratio.md · JSON definition: https://tttkmbb.com/statistics/odds-ratio.json

## Purpose

Computes the odds ratio and relative risk of a 2×2 exposure/outcome table with confidence intervals by the log method (Woolf), plus the absolute risk difference and the number needed to treat or harm.

**Use when:** You have counts of events and non-events in an exposed/treated group and an unexposed/control group (case-control or cohort data, clinical trials) and need OR, RR or NNT.

**Do not use when:** You need a significance test for the table (use chi-square-test), the outcome is continuous (use cohens-d), or you want predictive values of a diagnostic test (use diagnostic-test).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `a` | integer |  | required | Exposed / treated group: number with the outcome (events). (min 0) |
| `b` | integer |  | required | Exposed / treated group: number without the outcome. (min 0) |
| `c` | integer |  | required | Unexposed / control group: number with the outcome. (min 0) |
| `d` | integer |  | required | Unexposed / control group: number without the outcome. (min 0) |
| `confidence_level_percent` | number | % | optional, default 95 | Confidence level in percent (commonly 90, 95 or 99). Determines the critical z value. (> 0) |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `odds_ratio` | number |  | (a·d) / (b·c): odds of the outcome in the exposed relative to the unexposed group. |
| `or_ci_lower` | number |  | Lower confidence limit of the OR (log method). |
| `or_ci_upper` | number |  | Upper confidence limit of the OR. |
| `relative_risk` | number |  | (a/(a+b)) / (c/(c+d)): risk in the exposed divided by risk in the unexposed (cohort / trial data only). |
| `rr_ci_lower` | number |  | Lower confidence limit of the RR (log method). |
| `rr_ci_upper` | number |  | Upper confidence limit of the RR. |
| `risk_exposed` | number |  | a / (a + b). |
| `risk_unexposed` | number |  | c / (c + d). |
| `risk_difference` | number |  | risk_exposed − risk_unexposed (positive = exposure increases risk). |
| `nnt` | number |  | 1 / \|risk_difference\|: people to treat (benefit) or expose (harm) for one additional outcome; conventionally rounded up. Omitted when the risks are equal. |
| `nnt_type` | string |  | 'NNT (benefit)' when the exposure lowers risk, 'NNH (harm)' when it raises it. |
| `interpretation` | string |  | Direction of the association and whether the OR interval excludes 1. |

## Formula

`OR = a·d / (b·c); SE(ln OR) = √(1/a + 1/b + 1/c + 1/d); CI = exp(ln OR ± z·SE). RR = (a/(a+b)) / (c/(c+d)); SE(ln RR) = √(1/a − 1/(a+b) + 1/c − 1/(c+d)); ARD = a/(a+b) − c/(c+d); NNT = 1/|ARD|`

Confidence intervals use the Woolf logit method with the normal critical value. If any cell is 0, 0.5 is added to every cell (Haldane–Anscombe correction) for OR, RR and their intervals, and a note is returned. Relative risk is only meaningful for cohort or trial designs, not case-control sampling.

## Data Sources

- Bland JM, Altman DG (2000) Statistics Notes: The odds ratio, BMJ 320:1468 — https://www.bmj.com/content/320/7247/1468 (peer_reviewed, retrieved 2026-09-24)
- Altman DG (1998) Confidence intervals for the number needed to treat, BMJ 317:1309-1312 — https://www.bmj.com/content/317/7168/1309 (peer_reviewed, retrieved 2026-09-24)
- Wikipedia – Odds ratio — https://en.wikipedia.org/wiki/Odds_ratio (reference, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/odds-ratio?a=…&b=…&c=…&d=…`
- `POST https://tttkmbb.com/api/v1/calculate/odds-ratio` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/odds-ratio · OpenAPI operationId `calculate_odds_ratio` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "odds-ratio", "inputs": {…}}`

## Example

- Exposed 20/100 events, unexposed 10/100: inputs `{"a":20,"b":80,"c":10,"d":90}` → `{"odds_ratio":2.25,"or_ci_lower":0.9943,"or_ci_upper":5.0915,"relative_risk":2,"rr_ci_lower":0.9866,"rr_ci_upper":4.0545,"risk_exposed":0.2,"risk_unexposed":0.1,"risk_difference":0.1,"nnt":10,"nnt_type":"NNH (harm)"}`
- Treatment 15/100 events vs control 30/100: inputs `{"a":15,"b":85,"c":30,"d":70}` → `{"odds_ratio":0.4118,"or_ci_lower":0.2053,"or_ci_upper":0.8258,"relative_risk":0.5,"rr_ci_lower":0.2872,"rr_ci_upper":0.8704,"risk_difference":-0.15,"nnt":6.7,"nnt_type":"NNT (benefit)"}`

```
GET https://tttkmbb.com/api/v1/calculate/odds-ratio?a=20&b=80&c=10&d=90
```

## Limitations

You need a significance test for the table (use chi-square-test), the outcome is continuous (use cohens-d), or you want predictive values of a diagnostic test (use diagnostic-test). Confidence intervals use the Woolf logit method with the normal critical value. If any cell is 0, 0.5 is added to every cell (Haldane–Anscombe correction) for OR, RR and their intervals, and a note is returned. Relative risk is only meaningful for cohort or trial designs, not case-control sampling. All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**Odds ratio or relative risk?**

RR is easier to interpret but requires knowing the risks, so it is valid for cohort studies and trials; case-control studies can only estimate the OR. The OR approximates the RR when the outcome is rare (below about 10 %).

**How do I read the confidence interval?**

If the OR (or RR) interval includes 1, the association is not statistically significant at the chosen level; the interval width shows the precision of the estimate.

## Related

- [Chi-Square Test Calculator](https://tttkmbb.com/statistics/chi-square-test.md) — Significance test for the same 2×2 table.
- [Diagnostic Test Calculator](https://tttkmbb.com/statistics/diagnostic-test.md) — Sensitivity, specificity and predictive values of a test.
- [Bayes' Theorem Calculator](https://tttkmbb.com/statistics/bayes-theorem.md) — Update a probability with a likelihood ratio.
