Skip to content

Risk Difference, Risk Ratio & Odds Ratio

A cohort study follows exposed and unexposed people and counts who develops the outcome. The risk difference says how many extra cases the exposed group has per 100 people, the risk ratio says by what factor the risk is multiplied, and the odds ratio compares odds instead of risks. This page computes all three with intervals from one table, shows where the odds ratio parts from the risk ratio, removes confounding by age with the Mantel-Haenszel method, and ends with rates per person-year.

Download ckd_cohort.csv into your working directory. The invented table has 2,000 rows, one per person, and five columns: person_id, age_group (40-54, 55-69 or 70-84), hypertension (1 for hypertension at entry), ckd (1 for a diagnosis of chronic kidney disease during follow-up) and person_years. Everyone was followed for five years or until the diagnosis, and nobody was lost. The person is the unit of analysis.

The values come from a simulation with known answers. Without hypertension, the five-year risk of chronic kidney disease is 5%, 15% and 30% in the three age groups, and hypertension multiplies that risk by 1.5 in every age group. Older people also have hypertension more often: 25%, 45% and 70% of each group. So the true risk ratio is 1.5 at every age, and age is a confounder.

library(epitools)
library(ggplot2)
cohort <- read.csv("ckd_cohort.csv")
dir.create("outputs", showWarnings = FALSE)
two_by_two <- table(hypertension = cohort$hypertension, ckd = cohort$ckd)
print(addmargins(two_by_two))
ckd
hypertension 0 1 Sum
0 995 145 1140
1 609 251 860
Sum 1604 396 2000

Of the 860 people with hypertension, 251 developed chronic kidney disease. Of the 1,140 people without it, 145 did. Every measure below is a function of these four counts.

A risk is cases divided by people. The risk difference subtracts the two risks, and its standard error is the square root of the sum of the two binomial variances. The two ratios are skewed, so their intervals are built on the log scale and then exponentiated. With a cases and b non-cases among the exposed, and c cases and d non-cases among the unexposed, the standard error of the log risk ratio is the square root of 1/a − 1/(a + b) + 1/c − 1/(c + d). For the log odds ratio it is the square root of 1/a + 1/b + 1/c + 1/d. These are Wald intervals.

#' Count the four cells of an exposure by outcome table.
#'
#' @param data A data frame with the 0/1 columns hypertension and ckd.
#' @return A named vector: cases and people with hypertension, then cases
#' and people without it.
CountCells <- function(data) {
exposed <- data$hypertension == 1
c(cases_1 = sum(data$ckd[exposed]), n_1 = sum(exposed),
cases_0 = sum(data$ckd[!exposed]), n_0 = sum(!exposed))
}
#' Compute the risk difference, risk ratio and odds ratio with 95% limits.
#'
#' @param cells A named vector from CountCells().
#' @return A data frame with one row per measure and the columns estimate,
#' se, lower and upper. The se of each ratio is on the log scale.
RiskMeasures <- function(cells) {
z <- qnorm(0.975)
risk_1 <- cells[["cases_1"]] / cells[["n_1"]]
risk_0 <- cells[["cases_0"]] / cells[["n_0"]]
non_cases_1 <- cells[["n_1"]] - cells[["cases_1"]]
non_cases_0 <- cells[["n_0"]] - cells[["cases_0"]]
difference <- risk_1 - risk_0
se_difference <- sqrt(risk_1 * (1 - risk_1) / cells[["n_1"]] +
risk_0 * (1 - risk_0) / cells[["n_0"]])
log_rr <- log(risk_1 / risk_0)
se_log_rr <- sqrt(1 / cells[["cases_1"]] - 1 / cells[["n_1"]] +
1 / cells[["cases_0"]] - 1 / cells[["n_0"]])
log_or <- log((cells[["cases_1"]] * non_cases_0) /
(non_cases_1 * cells[["cases_0"]]))
se_log_or <- sqrt(1 / cells[["cases_1"]] + 1 / non_cases_1 +
1 / cells[["cases_0"]] + 1 / non_cases_0)
data.frame(
row.names = c("risk_difference", "risk_ratio", "odds_ratio"),
estimate = c(difference, exp(log_rr), exp(log_or)),
se = c(se_difference, se_log_rr, se_log_or),
lower = c(difference - z * se_difference, exp(log_rr - z * se_log_rr),
exp(log_or - z * se_log_or)),
upper = c(difference + z * se_difference, exp(log_rr + z * se_log_rr),
exp(log_or + z * se_log_or))
)
}
cells <- CountCells(cohort)
cat(sprintf("Risk with hypertension %.3f, without %.3f\n",
cells[["cases_1"]] / cells[["n_1"]],
cells[["cases_0"]] / cells[["n_0"]]))
crude <- RiskMeasures(cells)
print(round(crude, 3))
harm <- 1 / crude["risk_difference", ]
cat(sprintf("Number needed to harm %.1f, 95%% CI [%.1f, %.1f]\n",
harm$estimate, harm$upper, harm$lower))
Risk with hypertension 0.292, without 0.127
estimate se lower upper
risk_difference 0.165 0.018 0.129 0.201
risk_ratio 2.295 0.094 1.908 2.759
odds_ratio 2.828 0.116 2.252 3.552
Number needed to harm 6.1, 95% CI [5.0, 7.8]

The five-year risk is 0.292 with hypertension and 0.127 without. The risk difference is 0.165, or 16.5 extra cases per 100 people over five years, with a 95% interval from 12.9 to 20.1. The risk ratio is 2.295 and the odds ratio is 2.828. Both ratios describe the same table, and they are different numbers.

The number needed to harm is the reciprocal of the risk difference: 1 / 0.165 = 6.1, so one extra case appears for about every six people with hypertension. Its interval comes from the reciprocals of the limits of the risk difference, in swapped order, because the largest difference gives the smallest number: 5.0 to 7.8. The swap works only when both limits of the risk difference have the same sign. When that interval includes zero, the reciprocal runs to infinity and gives no usable limits, so report the risk difference itself. State the time span as well, since a number needed to harm over five years is not the number over one year.

All of these are crude measures. They compare everyone with hypertension to everyone without, and the section on confounding shows what that comparison mixes in.

In R, prop.test() with correct = FALSE returns the Wald interval of the risk difference, and epitools has riskratio() and oddsratio(). Both epitools functions expect the unexposed row first and the column without the outcome first, which is how table() orders 0/1 columns. In Python, confint_proportions_2indep() returns the limits of the difference, and Table2x2 takes the exposed row first and the cases in the first column.

wald_difference <- prop.test(c(cells[["cases_1"]], cells[["cases_0"]]),
c(cells[["n_1"]], cells[["n_0"]]),
correct = FALSE)
package_check <- rbind(
"prop.test difference" = c(
wald_difference$estimate[[1]] - wald_difference$estimate[[2]],
wald_difference$conf.int
),
"riskratio, wald" = riskratio(two_by_two, method = "wald")$measure["1", ],
"oddsratio, wald" = oddsratio(two_by_two, method = "wald")$measure["1", ],
"oddsratio, midp" = oddsratio(two_by_two)$measure["1", ]
)
print(round(package_check, 3))
estimate lower upper
prop.test difference 0.165 0.129 0.201
riskratio, wald 2.295 1.908 2.759
oddsratio, wald 2.828 2.252 3.552
oddsratio, midp 2.826 2.252 3.556

Each Wald result matches the hand calculation to three decimals. The defaults differ, so name the method you report. prop.test() applies a continuity correction unless you turn it off. oddsratio() in epitools defaults to method = "midp", a median-unbiased estimate with a mid-p exact interval, which gives 2.826 with limits 2.252 and 3.556 here; riskratio() defaults to Wald. confint_proportions_2indep() defaults to the Newcombe interval for a difference. Table2x2 reports the sample ratios with Wald limits on the log scale and offers no other method.

The odds of an outcome are its risk divided by one minus its risk. The odds ratio therefore equals the risk ratio times (1 − risk without exposure) / (1 − risk with exposure). That factor is close to 1 when both risks are small and grows as they rise, so the odds ratio lies further from 1 than the risk ratio whenever the two risks differ. The code compares the two in the whole cohort and in the youngest age group, where chronic kidney disease is less common, and then holds the risk ratio at 1.5 while the baseline risk rises.

young <- RiskMeasures(CountCells(cohort[cohort$age_group == "40-54", ]))
cat(sprintf("Whole cohort: risk ratio %.2f, odds ratio %.2f\n",
crude["risk_ratio", "estimate"],
crude["odds_ratio", "estimate"]))
cat(sprintf("Age 40-54: risk ratio %.2f, odds ratio %.2f\n",
young["risk_ratio", "estimate"],
young["odds_ratio", "estimate"]))
baseline_risk <- c(0.01, 0.05, 0.15, 0.30, 0.50)
exposed_risk <- 1.5 * baseline_risk
implied_or <- (exposed_risk / (1 - exposed_risk)) /
(baseline_risk / (1 - baseline_risk))
cat(sprintf("Risk %.3f against %.2f: risk ratio 1.50, odds ratio %.2f\n",
exposed_risk, baseline_risk, implied_or), sep = "")
Whole cohort: risk ratio 2.29, odds ratio 2.83
Age 40-54: risk ratio 1.28, odds ratio 1.30
Risk 0.015 against 0.01: risk ratio 1.50, odds ratio 1.51
Risk 0.075 against 0.05: risk ratio 1.50, odds ratio 1.54
Risk 0.225 against 0.15: risk ratio 1.50, odds ratio 1.65
Risk 0.450 against 0.30: risk ratio 1.50, odds ratio 1.91
Risk 0.750 against 0.50: risk ratio 1.50, odds ratio 3.00

In the whole cohort, where 29% and 13% of the two groups became cases, the odds ratio of 2.83 is 23% larger than the risk ratio of 2.29. In the youngest group the risks are below 8%, and the two measures are 1.30 and 1.28. The last five lines use no data. A risk ratio of exactly 1.5 corresponds to an odds ratio of 1.51 when the baseline risk is 1%, of 1.91 when it is 30%, and of 3.00 when it is 50%. The three age groups of this simulation share one risk ratio, so their true odds ratios differ: 1.54, 1.65 and 1.91.

Some studies can estimate only the odds ratio. A case-control study recruits cases and controls separately, so the investigator sets the share of cases in the sample, and no risk can be computed in either exposure group. The odds ratio has the same value whether the table is read by exposure or by outcome, which is why it survives that sampling. With controls drawn from people who never became cases, it approximates the risk ratio only when the outcome is rare in the source population. Logistic regression also returns odds ratios, in any design, and the same caution applies to its coefficients.

A confounder is associated with the exposure and is a cause of the outcome without being a consequence of the exposure. Age qualifies on both counts here. To see what it does, compute the risk ratio inside each age group and set the crude ratio beside them.

strata <- data.frame()
for (age in sort(unique(cohort$age_group))) {
stratum_cells <- CountCells(cohort[cohort$age_group == age, ])
measures <- RiskMeasures(stratum_cells)
strata <- rbind(strata, data.frame(
age_group = age, t(stratum_cells),
difference = measures["risk_difference", "estimate"],
rr = measures["risk_ratio", "estimate"],
rr_lower = measures["risk_ratio", "lower"],
rr_upper = measures["risk_ratio", "upper"],
se_log_rr = measures["risk_ratio", "se"],
or = measures["odds_ratio", "estimate"],
se_log_or = measures["odds_ratio", "se"]
))
}
cat(sprintf("%-5s %-15s %-14s %-5s %s\n", "Age", "Hypertension",
"Without", "Diff", "Risk ratio [95% CI]"))
cat(sprintf("%s %3d/%d = %.3f %d/%d = %.3f %.3f %.2f [%.2f, %.2f]\n",
strata$age_group, strata$cases_1, strata$n_1,
strata$cases_1 / strata$n_1, strata$cases_0, strata$n_0,
strata$cases_0 / strata$n_0, strata$difference, strata$rr,
strata$rr_lower, strata$rr_upper), sep = "")
cat(sprintf("Crude risk ratio %.2f [%.2f, %.2f]\n",
crude["risk_ratio", "estimate"], crude["risk_ratio", "lower"],
crude["risk_ratio", "upper"]))
cat(sprintf("Share with hypertension by age group: %s\n",
paste(sprintf("%.2f", strata$n_1 / (strata$n_1 + strata$n_0)),
collapse = ", ")))
Age Hypertension Without Diff Risk ratio [95% CI]
40-54 15/199 = 0.075 36/611 = 0.059 0.016 1.28 [0.72, 2.29]
55-69 79/311 = 0.254 59/370 = 0.159 0.095 1.59 [1.18, 2.15]
70-84 157/350 = 0.449 50/159 = 0.314 0.134 1.43 [1.10, 1.84]
Crude risk ratio 2.29 [1.91, 2.76]
Share with hypertension by age group: 0.25, 0.46, 0.69

Within the age groups the risk ratios are 1.28, 1.59 and 1.43, scattered around the true 1.5. The crude ratio, 2.29, is larger than all three, and its interval from 1.91 to 2.76 excludes the truth. No stratum shows an association that strong. The crude table compares a group that is mostly old with a group that is mostly young: 69% of the oldest group has hypertension against 25% of the youngest, and the risk without hypertension climbs from 0.059 to 0.314 across the same groups. Part of the crude ratio is the effect of age.

The youngest group has 51 cases, and its interval runs from 0.72 to 2.29. That interval includes 1, and it also includes the true 1.5, so it gives no ground for saying that hypertension is harmless before age 55.

The Diff column makes a second point. One risk ratio of about 1.5 means 1.6 extra cases per 100 people in the youngest group and 13.4 per 100 in the oldest. A ratio alone hides that.

The Mantel-Haenszel estimate is a weighted average of the stratum ratios, with weights that stay stable when a stratum is small. It estimates the ratio at a fixed age, on the assumption that one ratio holds at every age. mantelhaen.test() in R and StratifiedTable in statsmodels return the pooled odds ratio with its interval and the Cochran-Mantel-Haenszel test of no association in any stratum. R applies a continuity correction to that test by default and statsmodels does not, so the R code sets correct = FALSE.

Neither one gives an interval for the pooled risk ratio. mantelhaen.test() works on odds ratios only, and StratifiedTable has riskratio_pooled as a point estimate. The function below computes the pooled risk ratio with the standard error of Greenland and Robins, and a second function tests homogeneity with a Wald chi-square: the weighted squared distance of each stratum log ratio from their inverse-variance weighted mean. For odds ratios this is Woolf’s test.

#' Pool stratum risk ratios with the Mantel-Haenszel weights.
#'
#' The standard error of the log ratio is the Greenland-Robins estimator.
#'
#' @param strata A data frame with one row per stratum and the columns
#' cases_1, n_1, cases_0 and n_0.
#' @return A named vector with the pooled estimate and its 95% limits.
MantelHaenszelRiskRatio <- function(strata) {
total <- strata$n_1 + strata$n_0
numerator <- sum(strata$cases_1 * strata$n_0 / total)
denominator <- sum(strata$cases_0 * strata$n_1 / total)
cases <- strata$cases_1 + strata$cases_0
variance <- sum((strata$n_1 * strata$n_0 * cases -
strata$cases_1 * strata$cases_0 * total) / total^2) /
(numerator * denominator)
log_rr <- log(numerator / denominator)
z <- qnorm(0.975)
c(estimate = exp(log_rr), lower = exp(log_rr - z * sqrt(variance)),
upper = exp(log_rr + z * sqrt(variance)))
}
#' Test whether stratum log ratios share one value with a Wald chi-square.
#'
#' @param log_ratio Stratum estimates on the log scale.
#' @param se Standard errors of the log estimates.
#' @return One line of text with the statistic, its degrees of freedom and
#' the p-value.
HomogeneityTest <- function(log_ratio, se) {
weight <- 1 / se^2
pooled <- sum(weight * log_ratio) / sum(weight)
statistic <- sum(weight * (log_ratio - pooled)^2)
df <- length(log_ratio) - 1
sprintf("chi-square %.2f, df %d, p = %.2f", statistic, df,
pchisq(statistic, df, lower.tail = FALSE))
}
three_way <- table(hypertension = cohort$hypertension, ckd = cohort$ckd,
age_group = cohort$age_group)
mh_or <- mantelhaen.test(three_way, correct = FALSE)
mh_rr <- MantelHaenszelRiskRatio(strata)
cat(sprintf("Mantel-Haenszel odds ratio %.3f, 95%% CI [%.3f, %.3f]\n",
mh_or$estimate, mh_or$conf.int[1], mh_or$conf.int[2]))
cat(sprintf("Mantel-Haenszel risk ratio %.3f, 95%% CI [%.3f, %.3f]\n",
mh_rr[["estimate"]], mh_rr[["lower"]], mh_rr[["upper"]]))
cat(sprintf("Cochran-Mantel-Haenszel chi-square %.2f, p = %.2g\n",
mh_or$statistic, mh_or$p.value))
cat(sprintf("Homogeneity of risk ratios: %s\n",
HomogeneityTest(log(strata$rr), strata$se_log_rr)))
cat(sprintf("Homogeneity of odds ratios: %s\n",
HomogeneityTest(log(strata$or), strata$se_log_or)))
Mantel-Haenszel odds ratio 1.701, 95% CI [1.326, 2.182]
Mantel-Haenszel risk ratio 1.472, 95% CI [1.222, 1.773]
Cochran-Mantel-Haenszel chi-square 17.50, p = 2.9e-05
Homogeneity of risk ratios: chi-square 0.54, df 2, p = 0.76
Homogeneity of odds ratios: chi-square 0.82, df 2, p = 0.66

The pooled risk ratio is 1.472 with an interval from 1.222 to 1.773, which contains the true 1.5. Stratifying on age moved the estimate from 2.29 to 1.47. The pooled odds ratio, 1.701, is larger than the pooled risk ratio for the reason given above: the outcome is common in the two older groups. The Cochran-Mantel-Haenszel p-value of 2.9e-05 says that no association at any age fits these data poorly, and the interval carries the size. statsmodels adds the Breslow-Day test, a second test of equal odds ratios that base R does not have.

Neither homogeneity test comes near rejection, with p = 0.76 for the risk ratios and p = 0.66 for the odds ratios. That does not show that the strata share one ratio. This simulation shows it, because its true odds ratios are 1.54, 1.65 and 1.91, and the test of the odds ratios returned 0.66 all the same. A homogeneity test has little power when a stratum holds few cases. Decide whether one pooled number is a fair summary from the stratum estimates, their intervals and what is known about the exposure, and show the stratum table next to the pooled result.

A forest plot on a log axis puts the stratum, crude and pooled ratios in one view. On a log axis a ratio of 2 sits as far from 1 as a ratio of 0.5, and the Wald intervals are symmetric.

forest <- data.frame(
label = c(paste("Age", strata$age_group), "Crude", "Mantel-Haenszel"),
estimate = c(strata$rr, crude["risk_ratio", "estimate"],
mh_rr[["estimate"]]),
lower = c(strata$rr_lower, crude["risk_ratio", "lower"],
mh_rr[["lower"]]),
upper = c(strata$rr_upper, crude["risk_ratio", "upper"],
mh_rr[["upper"]]),
kind = c(rep("Stratum", nrow(strata)), "Crude", "Pooled")
)
forest$label <- factor(forest$label, levels = rev(forest$label))
forest_plot <- ggplot(forest, aes(estimate, label, color = kind)) +
geom_vline(xintercept = 1, color = "grey60") +
geom_vline(xintercept = 1.5, linetype = "dashed", color = "grey40") +
geom_errorbar(aes(xmin = lower, xmax = upper), width = 0.2,
orientation = "y") +
geom_point(size = 3) +
scale_x_log10(breaks = c(0.75, 1, 1.5, 2, 3), limits = c(0.7, 3)) +
scale_color_manual(values = c(Stratum = "#69b3a2", Crude = "#c44e52",
Pooled = "#1f4e5f"), guide = "none") +
labs(x = "Risk ratio (log scale), dashed line at the true value 1.5",
y = NULL) +
theme_classic(base_size = 12)
ggsave("outputs/risk-ratio-forest-r.png", forest_plot, width = 6,
height = 3.5, dpi = 150)

Forest plot drawn with ggplot2. The risk ratios of the three age groups and the Mantel-Haenszel ratio lie near a dashed line at 1.5, and the crude ratio lies to the right of all of them near 2.3. The interval of the youngest age group is the widest and crosses 1.

The pooled interval is narrower than any stratum interval because it uses all 396 cases. The crude interval is just as narrow and sits in the wrong place. A narrow interval measures precision, and confounding is a bias that more people do not remove.

A risk needs a fixed follow-up window with nobody lost during it. A rate divides the cases by the person-time at risk, so each person counts for the time actually observed. On the log scale, the standard error of the rate ratio is the square root of 1/a + 1/c, where a and c are the cases in the two groups. A Poisson regression with the log of person-years as an offset gives the same ratio, and it adjusts for age when age group joins the model. The count regression page explains the offset and the overdispersion check for counts per unit.

events <- tapply(cohort$ckd, cohort$hypertension, sum)
person_years <- tapply(cohort$person_years, cohort$hypertension, sum)
rate <- events / person_years
cat(sprintf("Hypertension %s: %d cases in %.0f person-years, %.2f per 100\n",
c("no ", "yes"), events, person_years, 100 * rate), sep = "")
log_irr <- log(rate[["1"]] / rate[["0"]])
se_log_irr <- sqrt(sum(1 / events))
cat(sprintf("By hand rate ratio %.3f, 95%% CI [%.3f, %.3f]\n",
exp(log_irr), exp(log_irr - qnorm(0.975) * se_log_irr),
exp(log_irr + qnorm(0.975) * se_log_irr)))
crude_fit <- glm(ckd ~ hypertension + offset(log(person_years)),
family = poisson, data = cohort)
adjusted_fit <- glm(ckd ~ hypertension + age_group +
offset(log(person_years)),
family = poisson, data = cohort)
models <- list(Crude = crude_fit, "Age-adjusted" = adjusted_fit)
for (name in names(models)) {
limits <- exp(confint.default(models[[name]])["hypertension", ])
cat(sprintf("%-12s rate ratio %.3f, 95%% CI [%.3f, %.3f]\n", name,
exp(coef(models[[name]])[["hypertension"]]), limits[1],
limits[2]))
}
baseline <- c(0.05, 0.15, 0.30)
true_rate_ratio <- log(1 - 1.5 * baseline) / log(1 - baseline)
cat(sprintf("True rate ratio by age group: %s\n",
paste(sprintf("%.2f", true_rate_ratio), collapse = ", ")))
Hypertension no : 145 cases in 5319 person-years, 2.73 per 100
Hypertension yes: 251 cases in 3641 person-years, 6.89 per 100
By hand rate ratio 2.529, 95% CI [2.061, 3.103]
Crude rate ratio 2.529, 95% CI [2.061, 3.103]
Age-adjusted rate ratio 1.583, 95% CI [1.278, 1.962]
True rate ratio by age group: 1.52, 1.57, 1.68

People with hypertension had 6.89 cases per 100 person-years and people without had 2.73, a rate ratio of 2.529. The crude Poisson model returns the same ratio and the same limits, 2.061 to 3.103, as the hand calculation. With age group in the model the rate ratio falls to 1.583, with limits 1.278 and 1.962. Both languages print Wald limits. In R, confint() on a glm gives profile likelihood limits, so the code calls confint.default() to match statsmodels.

The last line holds the true rate ratios of the simulation, 1.52 to 1.68. They exceed the risk ratio of 1.5 because a risk cannot pass 1: over a long follow-up both risks climb toward that ceiling and their ratio shrinks toward 1, while the ratio of the rates stays where it is. A risk ratio therefore belongs to its follow-up time, and a rate ratio is not a substitute for it when the outcome is common.

In this cohort everyone completed five years or became a case, so both the risks and the rates are valid. With staggered entry or loss to follow-up, a five-year risk cannot be read from the counts. Use rates, or the Kaplan-Meier estimator for a risk at a chosen time.

Do not read an odds ratio as “times more likely” when the outcome is common. The odds ratio of this table is 2.83, and people with hypertension were 2.29 times as likely to develop chronic kidney disease. The categorical data page makes the same point for the odds ratio of Fisher’s exact test.

Do not report a relative measure without the absolute risk. The same ratio of about 1.5 added 1.6 cases per 100 people aged 40 to 54 and 13.4 per 100 people aged 70 to 84. Give the two risks, or the risk difference, beside every ratio.

Do not collapse over a confounder. The crude risk ratio of 2.29 came with a tight interval and sat about 50% above the true 1.5; the age-stratified estimate was 1.47. Any number derived from the crude table, including the number needed to harm above, inherits the bias.

Do not adjust for a variable on the causal path from the exposure to the outcome. If hypertension damages the kidney partly by causing albuminuria, then stratifying on albuminuria measured during follow-up removes that part of the effect, and the adjusted ratio understates what hypertension does. Adjust for variables that were fixed before the exposure, such as age at entry.

The epitools package by Aragon computes risk ratios, odds ratios and rate ratios with their intervals from epidemiologic tables.

Mantel and Haenszel, 1959 describe the pooled odds ratio across strata and the chi-square test of association that carries their names.

Greenland and Robins, 1985 describe the Mantel-Haenszel estimators for follow-up data, including the variance of the pooled risk ratio that this page uses.

The R documentation of mantelhaen.test() describes the continuity correction, the exact conditional version of the test, and a Woolf test for the homogeneity of the odds ratios.

The statsmodels guide to contingency tables covers Table2x2 and StratifiedTable, including the Breslow-Day test and its Tarone adjustment.

The categorical data page covers the chi-square and Fisher tests for the table that this page starts from. The logistic regression page estimates an odds ratio adjusted for several covariates at once.

The propensity scores page handles confounding by several measured covariates when strata would be too many and too small.