age_standardize | R Documentation |
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
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
)
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 |
collapse |
Logical vector of length 1. Do you want to collapse ph.data ages
to match those in |
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 |
a data.table of the count, rate & adjusted rate with CIs, name of the reference population and the 'group_by' variable(s) – if any
https://github.com/PHSKC-APDE/rads/wiki/age_standardize
adjust_direct
for calculating crude and directly adjusted rates.
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")[]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.