What this calculator gives you
From a 2×2 table it gives every common measure of association: the risk in each group, the relative risk, the absolute risk difference, the number needed to treat (NNT) and the odds ratio, each with a confidence interval, plus chi-square and Fisher’s exact test. Use it for trials, cohort studies and any comparison of two proportions. For case-control studies, where risks cannot be estimated, use the odds ratio calculator.
Worked example
In a trial, 12 of 150 patients on a new treatment developed an infection, against 30 of 150 on the standard treatment.
- Risks: 8.0% and 20.0%.
- Relative risk: 0.40 (95% CI 0.21 to 0.75), a 60% relative risk reduction.
- Risk difference: −12.0 percentage points (Newcombe 95% CI −19.9 to −4.2).
- NNT: 1 / 0.12 = 8.3, rounded up to 9: treat 9 patients to prevent one infection (95% CI about 5 to 24).
- Odds ratio: 0.35 (95% CI 0.17 to 0.71). Test: χ²(1, N = 300) = 8.97, p = .003; Fisher’s exact p = .004.
Relative or absolute?
A 60% relative reduction sounds impressive whether the risk falls from 20% to 8% or from 0.02% to 0.008%. The absolute difference and the NNT show what it means in practice, which is why many journals ask for both. See relative risk vs odds ratio.
Methods
- CI for RR and OR: the log (Katz and Woolf) method. When a cell is 0, 0.5 is added to every cell.
- CI for the risk difference: Newcombe’s hybrid score method, which behaves well for small samples and extreme risks. The simple Wald interval is shown for comparison.
- NNT is 1 / |risk difference|, rounded up. Its interval is the inverse of the risk-difference interval; if that interval includes 0, the NNT interval runs through infinity.
Accuracy
RR, OR and their intervals match statsmodels’ Table2x2, the Newcombe and Wald intervals match statsmodels’ confint_proportions_2indep, and the p-values match SciPy, on 37 tables.
Frequently asked questions
How do I calculate relative risk?
Divide the risk in the exposed group by the risk in the unexposed group. With 12 of 150 against 30 of 150: 0.08 / 0.20 = 0.40.
What is the number needed to treat?
The number of people who must receive the treatment instead of the control for one more person to benefit. It is 1 divided by the absolute risk difference, rounded up.
When should I use the odds ratio instead?
In case-control studies, where you choose people by outcome and cannot estimate risks, and in logistic regression. Otherwise the relative risk is easier to interpret.
What if a cell is zero?
The relative risk or odds ratio would be 0 or infinite, so the calculator adds 0.5 to every cell before computing them, and you should report Fisher's exact test.