04: Generating Estimates: Age-standardization

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(RSTr)
is_cran <- !identical(Sys.getenv("NOT_CRAN"), "true")

Overview

In the previous vignette, we discussed the model setup process in-depth. But how do we get our estimates once we've run our model? In this vignette, we discuss extracting estimates from our model object with the get_estimates() function, and how to age-standardize those estimates with age_standardize().

The get_estimates() function

In the RSTr introductory vignette, we generated age-standardized estimates for lambda based on our example Michigan dataset. To extract rates from an RSTr object, we can simply run get_estimates():

mod_mst <- mstcar(name = "my_test_model", data = miheart, adjacency = miadj)
# For computational reasons, full model fitting is not run during CRAN checks.
# When building on CRAN, this vignette loads a pre-fitted example model included with the package.
# The pkgdown website shows the full model-fitting workflow.
example_dir <- system.file("extdata", package = "RSTr")
mod_mst <- load_model("mstcar_example", example_dir)
estimates <- get_estimates(mod_mst, rates_per = 1e5)
head(estimates)

The age_standardization() function

In many cases, we will want to age-standardize our estimates based on some (or all) age groups in our dataset. In our Michigan dataset, we have six ten-year age groups over which we can standardize; let's age-standardize from ages 35-64. For RSTr objects, age_standardize() takes in four arguments:

Once we have our std_pop vector, we can age-standardize our estimates:

std_pop <- c(113154, 100640, 95799)
mod_mst <- age_standardize(mod_mst, std_pop, new_name = "35-64", groups = c("35-44", "45-54", "55-64"))
mod_mst

Notice now that the mod_mst object indicates we have age-standardized our estimates and the names of our age-standardized group. We can also add on to our list of age-standardized estimates by simply specifying a different group:

std_pop <- c(68775, 34116, 9888)
mod_mst <- age_standardize(mod_mst, std_pop, new_name = "65up", groups = c("65-74", "75-84", "85+"))
mod_mst

If we want to generate estimates for all groups, i.e. 35 and up, we can omit the groups argument and expand std_pop to include all of our populations:

std_pop <- c(113154, 100640, 95799, 68775, 34116, 9888)
mod_mst <- age_standardize(mod_mst, std_pop, new_name = "35up")
mod_mst
mst_estimates_as <- get_estimates(mod_mst)
head(mst_estimates_as)

Now, get_estimates(mod_mst) shows the age-standardized estimates as opposed to our non-standardized estimates. Should you want to see the non-standardized estimates instead, you can set the argument standardized = FALSE.

Final thoughts

In this vignette, we explored the get_estimates() function and investigated age-standardization with the age_standardize() function. Age-standardization is one of the most important features of the RSTr package; using just a few arguments, we can easily generate estimates across our population groups.



Try the RSTr package in your browser

Any scripts or data that you put into this service are public.

RSTr documentation built on Jan. 31, 2026, 9:07 a.m.