age_standardize: Calculate age standardized rates from a data.table with age,...

age_standardizeR Documentation

Calculate age standardized rates from a data.table with age, counts, and population columns

Description

Calculate age standardized rates from a data.table with age, counts, and population columns.

Your dataset must have the following three columns ...

  • 'age' or 'agecat': 'age' in single years (if collapse = T) or 'agecat' with the same age bins as your selected reference population (if collapse = F)

  • an aggregated count for the event (e.g., disease) for which you want to find an age standardized rate

  • the population corresponding to the age or agecat in your original data

Usage

age_standardize(
  ph.data,
  ref.popname = NULL,
  collapse = T,
  my.count = "count",
  my.pop = "pop",
  per = 100000,
  conf.level = 0.95,
  group_by = NULL,
  diagnostic_report = F
)

Arguments

ph.data

a data.table or data.frame containing the data to be age-standardized.

ref.popname

Character vector of length 1. Only valid options are those in list_ref_pop and "none" (when standard population already exists in ph.data)

collapse

Logical vector of length 1. Do you want to collapse ph.data ages to match those in ref.popname?

my.count

Character vector of length 1. Identifies the column with the count data aggregated by the given demographics.

my.pop

Character vector of length 1. Identifies the column with the population corresponding to the given demographics.

per

Integer vector of length 1. A multiplier for all rates and CI, e.g., when per = 1000, the rates are per 1000 people

conf.level

A numeric vector of length 1. The confidence interval used in the calculations.

group_by

Character vector of indeterminate length. By which variable(s) do you want to stratify the rate results, if any?

diagnostic_report

If group_by is used and there are groups with missing ages, setting diagnostic_report = TRUE returns a diagnostic table instead of normal results. Use this option if a warning about missing age groups appears when running the function normally.

Value

a data.table of the count, rate & adjusted rate with CIs, name of the reference population and the 'group_by' variable(s) – if any

References

https://github.com/PHSKC-APDE/rads/wiki/age_standardize

See Also

adjust_direct for calculating crude and directly adjusted rates.

Examples


library(data.table)
temp1 <- data.table(age = c(50:60), count = c(25:35), pop = c(seq(1000, 900, -10)) )
age_standardize(ph.data = temp1,
ref.popname = "2000 U.S. Std Population (18 age groups - Census P25-1130)",
collapse = TRUE,
my.count = "count",
my.pop = "pop",
per = 1000,
conf.level = 0.95)[]

temp2 <- data.table(sex = c(rep("M", 11), rep("F", 11)), age = rep(50:60, 2),
count = c(25:35, 26:36), pop = c(seq(1000, 900, -10), seq(1100, 1000, -10)),
stdpop = rep(1000, 22))
age_standardize(ph.data = temp2, ref.popname = "none",
collapse = FALSE,
my.count = "count",
my.pop = "pop",
per = 1000,
conf.level = 0.95,
group_by = "sex")[]


PHSKC-APDE/rads documentation built on April 14, 2025, 10:47 a.m.