Age Standardization & the SMR
A crude death rate depends on how fast people die at each age and on how old the population is. Two regions with identical death rates at every age can have crude rates that differ by a factor of more than two, and a region with higher rates at almost every age can have the lower crude rate. This page builds both cases from one table of deaths and person-years, then compares the regions three ways: direct standardization to a published standard population, the standardized mortality ratio (SMR), and a Poisson regression.
Get the data
Section titled “Get the data”Download regional_deaths.csv into your working directory. The table has 21 rows, one per age band in each of three regions, and six columns: region, age_band, deaths, person_years, esp2013 and who_world. The deaths and person-years are invented. They stand for deaths from all causes over three years. The unit of analysis is one age band of one region, a count with its person-years.
The last two columns are real standard populations, repeated in the rows of every region: the 2013 European Standard Population and the WHO World Standard Population for 2000 to 2025, each collapsed from the age groups of its source to the seven bands of this table. esp2013 sums to 100,000. who_world sums to 100,035 because its source rounds each age group, so the code divides each standard by its own sum.
The deaths come from a simulation with known rates. Metro and Coast share one set of true death rates: 25, 45, 110, 420, 1,500, 5,000 and 15,000 per 100,000 person-years across the seven age bands. Valley has 1.8 times those rates below age 60 and 1.1 times those rates from age 60. Each count is a Poisson draw around its rate times its person-years.
library(epitools)library(ggplot2)
mortality <- read.csv("regional_deaths.csv")dir.create("outputs", showWarnings = FALSE)regions <- c("Metro", "Coast", "Valley")age_bands <- unique(mortality$age_band)mortality$region <- factor(mortality$region, levels = regions)mortality$age_band <- factor(mortality$age_band, levels = age_bands)mortality$rate <- 1e5 * mortality$deaths / mortality$person_yearsmetro <- mortality[mortality$region == "Metro", ]coast <- mortality[mortality$region == "Coast", ]valley <- mortality[mortality$region == "Valley", ]age_shares <- data.frame( age_band = age_bands, Metro = 100 * metro$person_years / sum(metro$person_years), Coast = 100 * coast$person_years / sum(coast$person_years), Valley = 100 * valley$person_years / sum(valley$person_years), esp2013 = 100 * metro$esp2013 / sum(metro$esp2013), who_world = 100 * metro$who_world / sum(metro$who_world))cat("Percent of the person-years, or of the standard, in each age band\n")print(cbind(age_shares[1], round(age_shares[-1], 1)), row.names = FALSE)Percent of the person-years, or of the standard, in each age band age_band Metro Coast Valley esp2013 who_world 0-14 19 12 20 16.0 26.1 15-29 24 13 22 17.5 24.6 30-44 24 16 23 20.5 21.3 45-59 17 21 19 20.5 16.0 60-74 11 23 11 16.5 8.9 75-84 4 11 4 6.5 2.4 85+ 1 4 1 2.5 0.6from pathlib import Path
import matplotlib.pyplot as pltimport numpy as npimport pandas as pdimport statsmodels.api as smimport statsmodels.formula.api as smffrom scipy import statsfrom statsmodels.stats.rates import confint_poisson
mortality = pd.read_csv("regional_deaths.csv")output = Path("outputs")output.mkdir(exist_ok=True)regions = ["Metro", "Coast", "Valley"]standards = ["esp2013", "who_world"]age_bands = list(mortality["age_band"].unique())mortality["rate"] = 1e5 * mortality["deaths"] / mortality["person_years"]by_region = {}for region in regions: by_region[region] = mortality[ mortality["region"] == region].reset_index(drop=True)metro = by_region["Metro"]coast = by_region["Coast"]valley = by_region["Valley"]age_shares = pd.DataFrame({"age_band": age_bands})for region in regions: rows = by_region[region] age_shares[region] = (100 * rows["person_years"] / rows["person_years"].sum())for standard in standards: age_shares[standard] = 100 * metro[standard] / metro[standard].sum()print("Percent of the person-years, or of the standard, in each age band")print(age_shares.round(1).to_string(index=False))Percent of the person-years, or of the standard, in each age bandage_band Metro Coast Valley esp2013 who_world 0-14 19.0 12.0 20.0 16.0 26.1 15-29 24.0 13.0 22.0 17.5 24.6 30-44 24.0 16.0 23.0 20.5 21.3 45-59 17.0 21.0 19.0 20.5 16.0 60-74 11.0 23.0 11.0 16.5 8.9 75-84 4.0 11.0 4.0 6.5 2.4 85+ 1.0 4.0 1.0 2.5 0.6Coast is the old region: 38% of its person-years are lived at age 60 or over (23 + 11 + 4), against 16% in Metro and in Valley. The two standards differ as well. The European standard puts 16.0% of its weight on ages 0 to 14 and 2.5% on ages 85 and over; the WHO world standard puts 26.1% and 0.6% there.
Crude rates against age-specific rates
Section titled “Crude rates against age-specific rates”The crude rate is all deaths divided by all person-years. The age-specific rate does the same inside one age band. Compute both and set them side by side.
crude <- aggregate(cbind(deaths, person_years) ~ region, data = mortality, FUN = sum)crude$rate <- 1e5 * crude$deaths / crude$person_yearscat(sprintf("%-6s %5d deaths / %7d person-years = %6.1f per 100,000\n", crude$region, crude$deaths, crude$person_years, crude$rate), sep = "")cat(sprintf("Crude rate ratio: Coast / Metro %.2f, Valley / Coast %.2f\n", crude$rate[2] / crude$rate[1], crude$rate[3] / crude$rate[2]))specific <- data.frame( age_band = age_bands, Metro = metro$rate, Coast = coast$rate, Valley = valley$rate, coast_metro = coast$rate / metro$rate, valley_coast = valley$rate / coast$rate)cat("Deaths per 100,000 person-years in each age band\n")print(cbind(specific[1], round(specific[2:4], 1), round(specific[5:6], 2)), row.names = FALSE)Metro 9302 deaths / 1482000 person-years = 627.7 per 100,000Coast 6371 deaths / 396500 person-years = 1606.8 per 100,000Valley 478 deaths / 61300 person-years = 779.8 per 100,000Crude rate ratio: Coast / Metro 2.56, Valley / Coast 0.49Deaths per 100,000 person-years in each age band age_band Metro Coast Valley coast_metro valley_coast 0-14 22.4 25.2 32.6 1.13 1.29 15-29 39.4 48.5 66.7 1.23 1.38 30-44 115.0 110.3 170.2 0.96 1.54 45-59 413.2 393.9 669.7 0.95 1.70 60-74 1491.2 1436.5 1898.3 0.96 1.32 75-84 4930.8 4979.9 5750.4 1.01 1.15 85+ 15485.8 15472.9 15334.4 1.00 0.99crude = mortality.groupby("region", sort=False)[ ["deaths", "person_years"]].sum()crude["rate"] = 1e5 * crude["deaths"] / crude["person_years"]for row in crude.itertuples(): print(f"{row.Index:<6} {row.deaths:5d} deaths / {row.person_years:7d} " f"person-years = {row.rate:6.1f} per 100,000")print(f"Crude rate ratio: Coast / Metro " f"{crude.loc['Coast', 'rate'] / crude.loc['Metro', 'rate']:.2f}, " f"Valley / Coast " f"{crude.loc['Valley', 'rate'] / crude.loc['Coast', 'rate']:.2f}")specific = pd.DataFrame({ "age_band": age_bands, "Metro": metro["rate"].round(1), "Coast": coast["rate"].round(1), "Valley": valley["rate"].round(1), "coast_metro": (coast["rate"] / metro["rate"]).round(2), "valley_coast": (valley["rate"] / coast["rate"]).round(2)})print("Deaths per 100,000 person-years in each age band")print(specific.to_string(index=False))Metro 9302 deaths / 1482000 person-years = 627.7 per 100,000Coast 6371 deaths / 396500 person-years = 1606.8 per 100,000Valley 478 deaths / 61300 person-years = 779.8 per 100,000Crude rate ratio: Coast / Metro 2.56, Valley / Coast 0.49Deaths per 100,000 person-years in each age bandage_band Metro Coast Valley coast_metro valley_coast 0-14 22.4 25.2 32.6 1.13 1.29 15-29 39.4 48.5 66.7 1.23 1.38 30-44 115.0 110.3 170.2 0.96 1.54 45-59 413.2 393.9 669.7 0.95 1.70 60-74 1491.2 1436.5 1898.3 0.96 1.32 75-84 4930.8 4979.9 5750.4 1.01 1.15 85+ 15485.8 15472.9 15334.4 1.00 0.99The crude rate of Coast is 1,606.8 per 100,000 and that of Metro is 627.7, a ratio of 2.56. The two regions were simulated with the same death rate at every age, and the coast_metro column shows it: from age 30 the ratios lie between 0.95 and 1.01. The two youngest bands give 1.13 and 1.23 on few deaths. Nothing in the age-specific columns supports a ratio of 2.56; the whole of it comes from the age structure.
The second comparison is worse, because the crude ratio points the wrong way. Valley has a crude rate of 779.8, less than half that of Coast (ratio 0.49). Inside the age bands Valley has the higher rate in six of seven, by factors of 1.15 to 1.70, and the two regions tie at 85 and over (0.99). A reader who ranks regions by crude rate calls the region with the highest death rates the healthier one.
Age is a confounder here in the usual sense: it differs between the regions and it drives mortality. The confounding and DAGs page gives the general argument. Standardization is adjustment for that one confounder.
Draw the age-specific rates
Section titled “Draw the age-specific rates”Death rates rise several hundredfold from childhood to old age, so plot them on a log axis. Two regions with a constant rate ratio then trace parallel lines.
rate_plot <- ggplot(mortality, aes(age_band, rate, group = region, color = region, shape = region, linetype = region)) + geom_line(linewidth = 0.7) + geom_point(size = 2.5) + scale_y_log10(breaks = c(30, 100, 300, 1000, 3000, 10000), labels = c("30", "100", "300", "1,000", "3,000", "10,000")) + scale_color_manual(values = c(Metro = "#2a78d6", Coast = "#eb6834", Valley = "#1baf7a")) + labs(x = "Age band", y = "Deaths per 100,000 person-years (log scale)", color = NULL, shape = NULL, linetype = NULL) + theme_classic(base_size = 12) + theme(legend.position = "inside", legend.position.inside = c(0.15, 0.85))ggsave("outputs/age-specific-rates-r.png", rate_plot, width = 6.5, height = 4.2, dpi = 150)
styles = {"Metro": ("#2a78d6", "o", "-"), "Coast": ("#eb6834", "^", ":"), "Valley": ("#1baf7a", "s", "--")}figure, axes = plt.subplots(figsize=(6.5, 4.2))for region in regions: color, marker, linestyle = styles[region] axes.plot(age_bands, by_region[region]["rate"], color=color, marker=marker, linestyle=linestyle, label=region)axes.set_yscale("log")axes.set_yticks([30, 100, 300, 1000, 3000, 10000], labels=["30", "100", "300", "1,000", "3,000", "10,000"])axes.set_yticks([], minor=True)axes.set_xlabel("Age band")axes.set_ylabel("Deaths per 100,000 person-years (log scale)")axes.legend(frameon=False)axes.spines[["top", "right"]].set_visible(False)figure.tight_layout()figure.savefig(output / "age-specific-rates-python.png", dpi=150)plt.close(figure)
The Valley line is not parallel to the other two. Its distance from them shrinks with age, so no single rate ratio describes Valley. That detail decides how the summaries below behave.
Direct standardization
Section titled “Direct standardization”A directly standardized rate is a weighted average of the age-specific rates of a region, with the weights taken from a standard population instead of from the region. It answers one question: what would the crude rate of this region be if it had the age structure of the standard? With weight w for each age band, d deaths and n person-years, the standardized rate is the sum of w × d / n, and its variance is the sum of w² × d / n². The code standardizes each region to both standards.
ageadjust.direct() in epitools returns the rate with the gamma interval of Fay and Feuer, the method its help page names. epitools is an R package, so the Python function computes the same interval by hand. The lower limit is a gamma quantile with shape rate² / variance and scale variance / rate. The upper limit uses the same formula after the largest value of w / n is added to the rate and its square is added to the variance.
#' Standardize the death rate of one region to a standard population.#'#' @param count Deaths in each age band.#' @param person_years Person-years in each age band.#' @param standard The standard population in each age band.#' @return The standardized rate per person-year and its variance.DirectRate <- function(count, person_years, standard) { weight <- standard / sum(standard) c(rate = sum(weight * count / person_years), variance = sum(weight^2 * count / person_years^2))}
true_rate <- c(25, 45, 110, 420, 1500, 5000, 15000)true_rates <- list(Metro = true_rate, Coast = true_rate, Valley = true_rate * rep(c(1.8, 1.1), c(4, 3)))standards <- c("esp2013", "who_world")direct <- list(esp2013 = list(), who_world = list())cat("Deaths per 100,000 person-years\n")for (standard in standards) { weight <- metro[[standard]] / sum(metro[[standard]]) for (region in regions) { rows <- mortality[mortality$region == region, ] direct[[standard]][[region]] <- DirectRate(rows$deaths, rows$person_years, rows[[standard]]) package <- 1e5 * ageadjust.direct(rows$deaths, rows$person_years, stdpop = rows[[standard]]) cat(sprintf("%-9s %-6s by hand %6.1f, ageadjust.direct %6.1f", standard, region, 1e5 * direct[[standard]][[region]][["rate"]], package[["adj.rate"]])) cat(sprintf(" [%6.1f, %6.1f], truth %6.1f\n", package[["lci"]], package[["uci"]], sum(weight * true_rates[[region]]))) }}Deaths per 100,000 person-yearsesp2013 Metro by hand 1072.4, ageadjust.direct 1072.4 [1049.9, 1095.4], truth 1068.0esp2013 Coast by hand 1063.4, ageadjust.direct 1063.4 [1037.0, 1090.5], truth 1068.0esp2013 Valley by hand 1259.4, ageadjust.direct 1259.4 [1144.0, 1384.7], truth 1259.2who_world Metro by hand 456.6, ageadjust.direct 456.6 [ 447.2, 466.2], truth 458.1who_world Coast by hand 451.8, ageadjust.direct 451.8 [ 437.7, 466.7], truth 458.1who_world Valley by hand 573.9, ageadjust.direct 573.9 [ 522.8, 629.6], truth 579.5def direct_rate(count, person_years, standard): """Standardize the rate of one region, with the Fay-Feuer interval.
Args: count: Deaths in each age band. person_years: Person-years in each age band. standard: The standard population in each age band.
Returns: A dictionary with the rate per person-year, its variance and its 95% limits. """ weight = standard / standard.sum() rate = (weight * count / person_years).sum() variance = (weight**2 * count / person_years**2).sum() largest = (weight / person_years).max() lower = stats.gamma.ppf(0.025, rate**2 / variance, scale=variance / rate) upper = stats.gamma.ppf( 0.975, (rate + largest) ** 2 / (variance + largest**2), scale=(variance + largest**2) / (rate + largest)) return {"rate": rate, "variance": variance, "lower": lower, "upper": upper}
true_rate = np.array([25, 45, 110, 420, 1500, 5000, 15000])true_rates = {"Metro": true_rate, "Coast": true_rate, "Valley": true_rate * np.repeat([1.8, 1.1], [4, 3])}direct = {"esp2013": {}, "who_world": {}}print("Deaths per 100,000 person-years")for standard in standards: weight = metro[standard] / metro[standard].sum() for region in regions: rows = by_region[region] result = direct_rate(rows["deaths"], rows["person_years"], rows[standard]) direct[standard][region] = result print(f"{standard:<9} {region:<6} by hand " f"{1e5 * result['rate']:6.1f} [{1e5 * result['lower']:6.1f}, " f"{1e5 * result['upper']:6.1f}], truth " f"{(weight * true_rates[region]).sum():6.1f}")Deaths per 100,000 person-yearsesp2013 Metro by hand 1072.4 [1049.9, 1095.4], truth 1068.0esp2013 Coast by hand 1063.4 [1037.0, 1090.5], truth 1068.0esp2013 Valley by hand 1259.4 [1144.0, 1384.7], truth 1259.2who_world Metro by hand 456.6 [ 447.2, 466.2], truth 458.1who_world Coast by hand 451.8 [ 437.7, 466.7], truth 458.1who_world Valley by hand 573.9 [ 522.8, 629.6], truth 579.5On the European standard, Metro has 1,072.4 deaths per 100,000 and Coast has 1,063.4. Both intervals contain the true value of 1,068.0, which is the same for the two regions because their true rates are the same. The crude rates of 627.7 and 1,606.8 have become two numbers that differ by less than 1%. Valley stands at 1,259.4 against a truth of 1,259.2, and its interval from 1,144.0 to 1,384.7 is about five times as wide as that of Metro because it rests on 478 deaths and not on 9,302. The hand calculation and ageadjust.direct() agree in R, and the gamma limits computed in Python match the limits that epitools prints.
The comparative rate ratio
Section titled “The comparative rate ratio”The ratio of two directly standardized rates compares two regions as if both had the age structure of the standard. It is also called the standardized rate ratio or the comparative mortality figure. Its interval comes from a normal approximation on the log scale, where the variance of the log ratio is the sum of variance / rate² over the two regions. The difference of the two rates is the absolute measure, and its variance is the sum of the two variances.
#' Compare two directly standardized rates as a ratio.#'#' @param numerator A vector from DirectRate().#' @param denominator A vector from DirectRate().#' @return The ratio and its 95% limits from the log scale.StandardizedRatio <- function(numerator, denominator) { log_ratio <- log(numerator[["rate"]] / denominator[["rate"]]) se <- sqrt(numerator[["variance"]] / numerator[["rate"]]^2 + denominator[["variance"]] / denominator[["rate"]]^2) exp(log_ratio + c(estimate = 0, lower = -1, upper = 1) * qnorm(0.975) * se)}
pairs <- list(c("Coast", "Metro"), c("Valley", "Metro"), c("Valley", "Coast"))for (standard in standards) { weight <- metro[[standard]] / sum(metro[[standard]]) for (pair in pairs) { ratio <- StandardizedRatio(direct[[standard]][[pair[1]]], direct[[standard]][[pair[2]]]) cat(sprintf("%-9s %-6s / %-5s %.3f [%.3f, %.3f], truth %.3f\n", standard, pair[1], pair[2], ratio[1], ratio[2], ratio[3], sum(weight * true_rates[[pair[1]]]) / sum(weight * true_rates[[pair[2]]]))) }}esp <- direct$esp2013difference <- 1e5 * (esp$Valley[["rate"]] - esp$Metro[["rate"]])margin <- 1e5 * qnorm(0.975) * sqrt(esp$Valley[["variance"]] + esp$Metro[["variance"]])cat(sprintf("esp2013 Valley - Metro %.1f per 100,000 [%.1f, %.1f]\n", difference, difference - margin, difference + margin))cat(sprintf("Weight below age 60: esp2013 %.3f, who_world %.3f\n", sum(metro$esp2013[1:4]) / sum(metro$esp2013), sum(metro$who_world[1:4]) / sum(metro$who_world)))esp2013 Coast / Metro 0.992 [0.960, 1.025], truth 1.000esp2013 Valley / Metro 1.174 [1.067, 1.293], truth 1.179esp2013 Valley / Coast 1.184 [1.075, 1.305], truth 1.179who_world Coast / Metro 0.989 [0.953, 1.027], truth 1.000who_world Valley / Metro 1.257 [1.145, 1.380], truth 1.265who_world Valley / Coast 1.270 [1.154, 1.399], truth 1.265esp2013 Valley - Metro 187.0 per 100,000 [66.7, 307.3]Weight below age 60: esp2013 0.745, who_world 0.880def standardized_ratio(numerator, denominator): """Compare two directly standardized rates as a ratio.
Args: numerator: A dictionary from direct_rate(). denominator: A dictionary from direct_rate().
Returns: A list with the ratio and its 95% limits from the log scale. """ log_ratio = np.log(numerator["rate"] / denominator["rate"]) se = np.sqrt(numerator["variance"] / numerator["rate"] ** 2 + denominator["variance"] / denominator["rate"] ** 2) z = stats.norm.ppf(0.975) return [np.exp(log_ratio), np.exp(log_ratio - z * se), np.exp(log_ratio + z * se)]
pairs = [("Coast", "Metro"), ("Valley", "Metro"), ("Valley", "Coast")]for standard in standards: weight = metro[standard] / metro[standard].sum() for top, bottom in pairs: ratio = standardized_ratio(direct[standard][top], direct[standard][bottom]) true_ratio = ((weight * true_rates[top]).sum() / (weight * true_rates[bottom]).sum()) print(f"{standard:<9} {top:<6} / {bottom:<5} {ratio[0]:.3f} " f"[{ratio[1]:.3f}, {ratio[2]:.3f}], truth {true_ratio:.3f}")esp = direct["esp2013"]difference = 1e5 * (esp["Valley"]["rate"] - esp["Metro"]["rate"])margin = 1e5 * stats.norm.ppf(0.975) * np.sqrt( esp["Valley"]["variance"] + esp["Metro"]["variance"])print(f"esp2013 Valley - Metro {difference:.1f} per 100,000 " f"[{difference - margin:.1f}, {difference + margin:.1f}]")print(f"Weight below age 60: esp2013 " f"{metro['esp2013'][:4].sum() / metro['esp2013'].sum():.3f}, " f"who_world " f"{metro['who_world'][:4].sum() / metro['who_world'].sum():.3f}")esp2013 Coast / Metro 0.992 [0.960, 1.025], truth 1.000esp2013 Valley / Metro 1.174 [1.067, 1.293], truth 1.179esp2013 Valley / Coast 1.184 [1.075, 1.305], truth 1.179who_world Coast / Metro 0.989 [0.953, 1.027], truth 1.000who_world Valley / Metro 1.257 [1.145, 1.380], truth 1.265who_world Valley / Coast 1.270 [1.154, 1.399], truth 1.265esp2013 Valley - Metro 187.0 per 100,000 [66.7, 307.3]Weight below age 60: esp2013 0.745, who_world 0.880On the European standard, Coast against Metro gives 0.992 with an interval from 0.960 to 1.025, where the crude ratio was 2.56. Valley against Coast gives 1.184, where the crude ratio was 0.49. Standardization has put the three regions in the order that the age-specific rates show. Valley has 1.174 times the death rate of Metro, or 187.0 more deaths per 100,000 person-years. The interval of the ratio excludes 1 and the interval of the difference, from 66.7 to 307.3, excludes 0.
The standard changes the answer
Section titled “The standard changes the answer”The WHO world standard is a younger population, and the same deaths in the same people give Metro a rate of 456.6 per 100,000 on it, against 1,072.4 on the European standard. Neither number is wrong. Each one is the death rate of a hypothetical Metro with the age structure of its standard.
The ratio moves too. Valley against Metro is 1.174 on the European standard and 1.257 on the WHO standard, and the true values move the same way, from 1.179 to 1.265. The WHO standard puts 0.880 of its weight below age 60 and the European standard 0.745, and below age 60 is where Valley’s excess is largest. Coast against Metro barely changes, 0.992 and 0.989, because those two regions share one ratio at every age. A standardized ratio depends on the standard when the age-specific ratios differ, and the truth of 1.179 is specific to the European standard.
Indirect standardization and the SMR
Section titled “Indirect standardization and the SMR”Indirect standardization turns the calculation around. It takes the age-specific rates of a reference population, applies them to the person-years of the study region, and adds up the deaths that the region would have had at those rates. The standardized mortality ratio is the observed deaths divided by these expected deaths. Metro is the reference here.
The exact Poisson interval treats the observed count as Poisson and the expected count as fixed. With O observed and E expected deaths, the lower limit is the 2.5% quantile of a chi-square distribution with 2 × O degrees of freedom, divided by 2 × E. The upper limit is the 97.5% quantile with 2 × (O + 1) degrees of freedom, divided by 2 × E. poisson.test() in R and confint_poisson() with method="exact-c" in statsmodels return the same limits, and epitools has ageadjust.indirect(). The code also prints the exact interval of the youngest band of Valley, the cost of one more death in two bands of the standardized rate, and the relative standard error of each summary.
#' Compute a standardized mortality ratio with exact Poisson limits.#'#' @param count Deaths in each age band of the study region.#' @param person_years Person-years in each age band of the study region.#' @param reference_rate Deaths per person-year in each age band of the#' reference population.#' @return The observed and expected deaths, the ratio and its 95% limits.MortalityRatio <- function(count, person_years, reference_rate) { observed <- sum(count) expected <- sum(reference_rate * person_years) c(observed = observed, expected = expected, smr = observed / expected, lower = qchisq(0.025, 2 * observed) / (2 * expected), upper = qchisq(0.975, 2 * (observed + 1)) / (2 * expected))}
metro_rate <- metro$deaths / metro$person_yearsvalley_expected <- metro_rate * valley$person_yearsprint(data.frame(age_band = age_bands, observed = valley$deaths, expected = round(valley_expected, 1)), row.names = FALSE)for (region in c("Valley", "Coast")) { rows <- mortality[mortality$region == region, ] by_hand <- MortalityRatio(rows$deaths, rows$person_years, metro_rate) package <- ageadjust.indirect(rows$deaths, rows$person_years, stdcount = metro$deaths, stdpop = metro$person_years)$sir exact <- poisson.test(sum(rows$deaths), by_hand[["expected"]])$conf.int cat(sprintf("%s: %d observed, %.1f expected, SMR %.3f\n", region, sum(rows$deaths), by_hand[["expected"]], by_hand[["smr"]])) cat(sprintf(" by hand [%.3f, %.3f], poisson.test [%.3f, %.3f], ", by_hand[["lower"]], by_hand[["upper"]], exact[1], exact[2])) cat(sprintf("ageadjust.indirect [%.3f, %.3f]\n", package[["lci"]], package[["uci"]]))}youngest <- 1e5 * poisson.test(valley$deaths[1], valley$person_years[1])$conf.intcat(sprintf("Valley, age 0-14: rate %.1f, exact CI [%.1f, %.1f]\n", valley$rate[1], youngest[1], youngest[2]))for (standard in standards) { per_death <- 1e5 * metro[[standard]] / sum(metro[[standard]]) / valley$person_years cat(sprintf("One more Valley death, %-9s +%.2f at 0-14, +%.2f at 85+\n", standard, per_death[1], per_death[7]))}cat(sprintf("Relative standard error: esp2013 %.3f, who_world %.3f, ", sqrt(direct$esp2013$Valley[["variance"]]) / direct$esp2013$Valley[["rate"]], sqrt(direct$who_world$Valley[["variance"]]) / direct$who_world$Valley[["rate"]]))cat(sprintf("SMR %.3f\n", 1 / sqrt(sum(valley$deaths)))) age_band observed expected 0-14 4 2.7 15-29 9 5.3 30-44 24 16.2 45-59 78 48.1 60-74 128 100.6 75-84 141 120.9 85+ 94 94.9Valley: 478 observed, 388.8 expected, SMR 1.230 by hand [1.122, 1.345], poisson.test [1.122, 1.345], ageadjust.indirect [1.124, 1.345]Coast: 6371 observed, 6414.5 expected, SMR 0.993 by hand [0.969, 1.018], poisson.test [0.969, 1.018], ageadjust.indirect [0.969, 1.018]Valley, age 0-14: rate 32.6, exact CI [8.9, 83.5]One more Valley death, esp2013 +1.31 at 0-14, +4.08 at 85+One more Valley death, who_world +2.13 at 0-14, +1.04 at 85+Relative standard error: esp2013 0.048, who_world 0.046, SMR 0.046def mortality_ratio(count, person_years, reference_rate): """Compute a standardized mortality ratio with exact Poisson limits.
Args: count: Deaths in each age band of the study region. person_years: Person-years in each age band of the study region. reference_rate: Deaths per person-year in each age band of the reference population.
Returns: A dictionary with the observed and expected deaths, the ratio and its 95% limits. """ observed = count.sum() expected = (reference_rate * person_years).sum() return {"observed": observed, "expected": expected, "smr": observed / expected, "lower": stats.chi2.ppf(0.025, 2 * observed) / (2 * expected), "upper": (stats.chi2.ppf(0.975, 2 * (observed + 1)) / (2 * expected))}
metro_rate = metro["deaths"] / metro["person_years"]valley_expected = metro_rate * valley["person_years"]print(pd.DataFrame({"age_band": age_bands, "observed": valley["deaths"], "expected": valley_expected.round(1)}).to_string( index=False))for region in ("Valley", "Coast"): rows = by_region[region] by_hand = mortality_ratio(rows["deaths"], rows["person_years"], metro_rate) package = confint_poisson(by_hand["observed"], by_hand["expected"], method="exact-c") print(f"{region}: {by_hand['observed']} observed, " f"{by_hand['expected']:.1f} expected, SMR {by_hand['smr']:.3f}") print(f" by hand [{by_hand['lower']:.3f}, {by_hand['upper']:.3f}], " f"confint_poisson [{package[0]:.3f}, {package[1]:.3f}]")youngest = 1e5 * np.array(confint_poisson( valley["deaths"][0], valley["person_years"][0], method="exact-c"))print(f"Valley, age 0-14: rate {valley['rate'][0]:.1f}, exact CI " f"[{youngest[0]:.1f}, {youngest[1]:.1f}]")for standard in standards: per_death = (1e5 * metro[standard] / metro[standard].sum() / valley["person_years"]) print(f"One more Valley death, {standard:<9} +{per_death[0]:.2f} at " f"0-14, +{per_death[6]:.2f} at 85+")relative_se = [np.sqrt(direct[standard]["Valley"]["variance"]) / direct[standard]["Valley"]["rate"] for standard in standards]print(f"Relative standard error: esp2013 {relative_se[0]:.3f}, " f"who_world {relative_se[1]:.3f}, " f"SMR {1 / np.sqrt(valley['deaths'].sum()):.3f}")age_band observed expected 0-14 4 2.7 15-29 9 5.3 30-44 24 16.2 45-59 78 48.1 60-74 128 100.6 75-84 141 120.9 85+ 94 94.9Valley: 478 observed, 388.8 expected, SMR 1.230 by hand [1.122, 1.345], confint_poisson [1.122, 1.345]Coast: 6371 observed, 6414.5 expected, SMR 0.993 by hand [0.969, 1.018], confint_poisson [0.969, 1.018]Valley, age 0-14: rate 32.6, exact CI [8.9, 83.5]One more Valley death, esp2013 +1.31 at 0-14, +4.08 at 85+One more Valley death, who_world +2.13 at 0-14, +1.04 at 85+Relative standard error: esp2013 0.048, who_world 0.046, SMR 0.046Valley had 478 deaths where the rates of Metro predict 388.8 for its person-years, an SMR of 1.230 with an exact interval from 1.122 to 1.345. That is 89.2 more deaths over the three years than Metro’s rates would produce in a population of Valley’s size and ages. Coast has an SMR of 0.993 with an interval from 0.969 to 1.018, in line with its true rates, which equal those of Metro.
The hand formula matches poisson.test() and confint_poisson(). ageadjust.indirect() prints a lower limit of 1.124 for Valley where the exact limit is 1.122. In epitools 0.5-10.1 that function computes exp(log SMR ± 1.96 / √O), a normal approximation on the log scale, although its help page speaks of exact intervals. With 478 deaths the two methods differ in the third decimal. Report the exact limits, which need no large-sample argument.
All of these intervals take the expected count as known. That is reasonable for Valley, because the reference rates come from 9,302 deaths in Metro and Valley has 478. It is not reasonable for Coast, whose 6,371 deaths are of the same order as the 9,302 reference deaths. The noise in the expected count of Coast is then not small next to the noise in its observed count, and the Coast interval above is too narrow. The Poisson model at the end of this page carries both sources of noise, and it gives Coast an interval from 0.962 to 1.027.
Small strata
Section titled “Small strata”The direct method needs a death rate from every age band of the study region. The indirect method needs only the total deaths of the region and its person-years by age. The youngest band of Valley has 4 deaths, against 2.7 expected. Its rate of 32.6 per 100,000 carries an exact interval from 8.9 to 83.5, a ninefold range, and the direct method has to use that rate with 16.0% of the weight on the European standard or 26.1% on the WHO standard. The SMR never computes it.
Each death adds to the directly standardized rate the weight of its band divided by the band’s person-years. On the WHO standard one more death at ages 0 to 14 adds 2.13 per 100,000 to the rate of Valley, about twice the 1.04 of a death at 85 and over. On the European standard a death at 85 and over adds 4.08, three times the 1.31 of a death in the youngest band, because that standard gives 2.5% of its weight to a band that holds 1.0% of the person-years of Valley. A standard that weights a band far more heavily than the region populates it makes the rate depend on a few events. In the SMR every death counts the same.
For Valley as a whole the cost is small: the relative standard error is 0.048 for the European rate, 0.046 for the WHO rate and 0.046 for the SMR, because 478 deaths are enough for either method. Choose the indirect method for a district or a rare cause of death where several bands hold zero to five events, or where the deaths are not available by age at all.
Two SMRs are not comparable
Section titled “Two SMRs are not comparable”Each SMR weights the age bands by the expected deaths of its own region. Two regions with different age structures therefore use two different sets of weights, and their SMRs can differ when their death rates do not. To see it, apply the age-specific rates of Valley to the person-years of Coast and compute the SMR that such a region would have.
valley_rate <- valley$deaths / valley$person_yearscoast_expected <- metro_rate * coast$person_yearstrue_own <- sum(true_rates$Valley * valley$person_years) / sum(true_rate * valley$person_years)true_coast <- sum(true_rates$Valley * coast$person_years) / sum(true_rate * coast$person_years)cat(sprintf("Valley rates, Valley age structure: SMR %.3f, truth %.3f\n", sum(valley$deaths) / sum(valley_expected), true_own))cat(sprintf("Valley rates, Coast age structure: SMR %.3f, truth %.3f\n", sum(valley_rate * coast$person_years) / sum(coast_expected), true_coast))cat(sprintf("Expected deaths below age 60: Valley %.1f%%, Coast %.1f%%\n", 100 * sum(valley_expected[1:4]) / sum(valley_expected), 100 * sum(coast_expected[1:4]) / sum(coast_expected)))Valley rates, Valley age structure: SMR 1.230, truth 1.232Valley rates, Coast age structure: SMR 1.152, truth 1.150Expected deaths below age 60: Valley 18.6%, Coast 7.0%valley_rate = valley["deaths"] / valley["person_years"]coast_expected = metro_rate * coast["person_years"]coast_structure = ((valley_rate * coast["person_years"]).sum() / coast_expected.sum())true_own = ((true_rates["Valley"] * valley["person_years"]).sum() / (true_rate * valley["person_years"]).sum())true_coast = ((true_rates["Valley"] * coast["person_years"]).sum() / (true_rate * coast["person_years"]).sum())print(f"Valley rates, Valley age structure: SMR " f"{valley['deaths'].sum() / valley_expected.sum():.3f}, " f"truth {true_own:.3f}")print(f"Valley rates, Coast age structure: SMR " f"{coast_structure:.3f}, truth {true_coast:.3f}")print(f"Expected deaths below age 60: Valley " f"{100 * valley_expected[:4].sum() / valley_expected.sum():.1f}%, " f"Coast {100 * coast_expected[:4].sum() / coast_expected.sum():.1f}%")Valley rates, Valley age structure: SMR 1.230, truth 1.232Valley rates, Coast age structure: SMR 1.152, truth 1.150Expected deaths below age 60: Valley 18.6%, Coast 7.0%The same age-specific death rates give an SMR of 1.230 in a region with the ages of Valley and 1.152 in a region with the ages of Coast. No sampling noise separates the two, since both use the same rates, and the true rates of the simulation give 1.232 and 1.150. Valley’s excess is largest below age 60, where 18.6% of the expected deaths of Valley fall and only 7.0% of those of Coast, so an old region gives the large ratios little weight.
An SMR therefore compares one region with the reference and nothing else. Coast has an SMR of 0.993 and Valley has 1.230, and each number is a fair statement about that region against Metro. Their quotient is not a standardized comparison of Valley with Coast. For that comparison use the direct method, which holds one set of weights for both regions and gave 1.184 on the European standard. Two SMRs are comparable only when the rate ratio against the reference is the same at every age, or when the two regions have the same age structure.
The model-based alternative
Section titled “The model-based alternative”A Poisson regression of the death counts on region and age band, with the log of the person-years as an offset, estimates one rate ratio for each region against Metro, adjusted for age. The count regression page explains the offset. The model makes an assumption that standardization does not make: the ratio of a region to Metro is the same in every age band. The second model below drops that assumption for Valley and gives it one ratio below age 60 and another from age 60, where the simulation changes the ratio.
main_fit <- glm(deaths ~ region + age_band + offset(log(person_years)), family = poisson, data = mortality)main_ratio <- exp(cbind(coef(main_fit), confint.default(main_fit)))cat(sprintf("%-7s rate ratio %.3f, 95%% CI [%.3f, %.3f]\n", c("Coast", "Valley"), main_ratio[2:3, 1], main_ratio[2:3, 2], main_ratio[2:3, 3]), sep = "")cat(sprintf("Residual deviance %.1f on %d df, p = %.3f\n", deviance(main_fit), df.residual(main_fit), pchisq(deviance(main_fit), df.residual(main_fit), lower.tail = FALSE)))below_60 <- mortality$age_band %in% age_bands[1:4]mortality$coast <- as.integer(mortality$region == "Coast")mortality$valley_below_60 <- as.integer(mortality$region == "Valley" & below_60)mortality$valley_from_60 <- as.integer(mortality$region == "Valley" & !below_60)split_fit <- glm(deaths ~ coast + valley_below_60 + valley_from_60 + age_band + offset(log(person_years)), family = poisson, data = mortality)split_ratio <- exp(cbind(coef(split_fit), confint.default(split_fit)))cat(sprintf("%-19s rate ratio %.3f, 95%% CI [%.3f, %.3f]\n", c("Valley below age 60", "Valley from age 60"), split_ratio[3:4, 1], split_ratio[3:4, 2], split_ratio[3:4, 3]), sep = "")likelihood_ratio <- deviance(main_fit) - deviance(split_fit)cat(sprintf("Likelihood ratio test of one Valley ratio: %.2f on 1 df, ", likelihood_ratio))cat(sprintf("p = %.4f\n", pchisq(likelihood_ratio, 1, lower.tail = FALSE)))Coast rate ratio 0.994, 95% CI [0.962, 1.027]Valley rate ratio 1.230, 95% CI [1.122, 1.348]Residual deviance 15.4 on 12 df, p = 0.220Valley below age 60 rate ratio 1.596, 95% CI [1.323, 1.926]Valley from age 60 rate ratio 1.146, 95% CI [1.032, 1.273]Likelihood ratio test of one Valley ratio: 8.63 on 1 df, p = 0.0033below_60 = mortality["age_band"].isin(age_bands[:4])is_valley = mortality["region"] == "Valley"mortality["coast"] = (mortality["region"] == "Coast").astype(int)mortality["valley"] = is_valley.astype(int)mortality["valley_below_60"] = (is_valley & below_60).astype(int)mortality["valley_from_60"] = (is_valley & ~below_60).astype(int)offset = np.log(mortality["person_years"])main_fit = smf.glm("deaths ~ coast + valley + age_band", data=mortality, family=sm.families.Poisson(), offset=offset).fit()split_fit = smf.glm( "deaths ~ coast + valley_below_60 + valley_from_60 + age_band", data=mortality, family=sm.families.Poisson(), offset=offset).fit()terms = [(main_fit, "coast", "Coast"), (main_fit, "valley", "Valley"), (split_fit, "valley_below_60", "Valley below age 60"), (split_fit, "valley_from_60", "Valley from age 60")]for fit, term, label in terms: limits = np.exp(fit.conf_int().loc[term]) print(f"{label:<19} rate ratio {np.exp(fit.params[term]):.3f}, " f"95% CI [{limits[0]:.3f}, {limits[1]:.3f}]") if term == "valley": print(f"Residual deviance {main_fit.deviance:.1f} on " f"{int(main_fit.df_resid)} df, p = " f"{stats.chi2.sf(main_fit.deviance, main_fit.df_resid):.3f}")likelihood_ratio = main_fit.deviance - split_fit.devianceprint(f"Likelihood ratio test of one Valley ratio: " f"{likelihood_ratio:.2f} on 1 df, p = " f"{stats.chi2.sf(likelihood_ratio, 1):.4f}")Coast rate ratio 0.994, 95% CI [0.962, 1.027]Valley rate ratio 1.230, 95% CI [1.122, 1.348]Residual deviance 15.4 on 12 df, p = 0.220Valley below age 60 rate ratio 1.596, 95% CI [1.323, 1.926]Valley from age 60 rate ratio 1.146, 95% CI [1.032, 1.273]Likelihood ratio test of one Valley ratio: 8.63 on 1 df, p = 0.0033The model gives Coast a rate ratio of 0.994 with an interval from 0.962 to 1.027, close to the standardized ratio of 0.992. For Valley it gives 1.230, which is neither the 1.174 of the European standard nor the 1.257 of the WHO standard. It matches the SMR. A Poisson model with a region term makes the fitted deaths of Valley add up to its observed deaths, so its rate ratio is observed over expected deaths, with the expected deaths taken from the model’s age-specific rates for Metro, and those rates lie close to the observed rates of Metro. Both languages print Wald limits; confint() on a glm in R would give profile likelihood limits.
So three methods have returned three ratios for Valley against Metro: 1.174, 1.257 and 1.230. Each is a different weighted average of age-specific ratios that are not equal. The second model recovers them: 1.596 below age 60, with an interval from 1.323 to 1.926, and 1.146 from age 60, with an interval from 1.032 to 1.273. The true values are 1.8 and 1.1, and both intervals contain them. The likelihood ratio test gives p = 0.0033 against one common ratio. When the ratios differ by age like this, report them by age, or report a standardized ratio and name its standard.
The residual deviance of the first model, 15.4 on 12 degrees of freedom with p = 0.220, gave no warning, because it spreads the misfit over 12 degrees of freedom and the departure sits in one contrast. Look at the age-specific ratios or at the plot before you trust a single adjusted number. The cut at age 60 was known here because the data are simulated. With real data, choose the age groups for such a test before you look at the rates, because a cut placed where the data suggest it makes the p-value too small.
Mistakes to avoid
Section titled “Mistakes to avoid”Do not compare crude rates across populations of different ages. Coast had 2.56 times the crude rate of Metro with the same death rates at every age, and Valley had 0.49 times the crude rate of Coast with higher death rates in six of seven age bands.
Do not quote a standardized rate without its standard. Valley has 1,259.4 deaths per 100,000 on the 2013 European Standard Population and 573.9 on the WHO world standard. A standardized rate can be compared only with rates on the same standard, with the same age bands.
Do not treat a standardized rate as the real rate of the population. Metro had 627.7 deaths per 100,000 person-years. The 1,072.4 on the European standard describes a Metro that does not exist. Use the crude rate and the age-specific rates to plan services, and the standardized rate to compare.
Do not rank regions by their SMRs. The same age-specific rates gave 1.230 with the age structure of Valley and 1.152 with the age structure of Coast.
Do not report one adjusted rate ratio when the ratios differ by age. The Poisson model returned 1.230 for Valley, a number that holds in no age band: the ratio is 1.596 below age 60 and 1.146 from age 60.
Scientific references
Section titled “Scientific references”The epitools package by Aragon computes risk ratios, odds ratios and rate ratios with their intervals from epidemiologic tables.
Fay and Feuer, 1997 describe an approximate confidence interval for directly standardized rates that is based on the gamma distribution.
Eurostat, 2013 reports the revision of the European Standard Population by a Eurostat task force, with the 2013 standard population in Annex F.
Ahmad and colleagues, 2001 propose the WHO World Standard Population, based on the average world population between 2000 and 2025, and compare it with two earlier standards.
Further reading
Section titled “Further reading”The epitools reference manual documents ageadjust.direct() and ageadjust.indirect() with a worked example of both methods on one mortality table.
The statsmodels documentation of confint_poisson() lists the interval methods for a Poisson rate, including the exact method that this page uses for the SMR.
The risk measures page pools age strata with the Mantel-Haenszel method, a third way to weight stratum ratios, and gives the interval of a crude rate ratio. The count regression page covers the offset, overdispersion and the negative binomial model.
The study designs page builds rates from person-time, and the confounding and DAGs page shows how to decide which variables an analysis has to adjust for.