Learn R Programming

popEpi (version 0.3.1)

rate: Direct-Standardised Incidence/Mortality Rates

Description

rate calculates adjusted rates using preloaded weights data or user specified weights.

Usage

rate(data, obs = NULL, pyrs = NULL, print = NULL, adjust = NULL, weights = NULL, subset = NULL)

Arguments

data
aggregated data (see e.g. lexpand, aggre if you have subject-level data)
obs
observations variable name in data. Flexible input, typically e.g. obs = obs.
pyrs
person-years variable name in data. Flexible input, typically e.g. pyrs = pyrs.
print
variable name to stratify the rates. Flexible input, typically e.g. print = sex or print = list(sex, area).
adjust
variable for adjusting the rates. Flexible input, typically e.g. adjust = agegroup.
weights
typically a list of weights or a character string specifying an age group standardization scheme; see the dedicated help page and examples.
subset
a logical expression to subset data.

Value

Returns a data.table with observations, person-years, rates and adjusted rates, if availble. Results are stratified by print. Adjusted rates are identified with suffix .adj and .lo and .hi are for confidence intervals lower and upper 95% bounds, respectively. The prefix SE. stands for standard error.

Details

Input data needs to be in aggregated format with observations and person-years. For individual data use lexpand, or ltable and merge person-years manually.

See Also

lexpand, ltable

Examples

Run this code
## Prepare data with lexpand and then reformat agegroup.
data(sibr)
x <- lexpand(sibr, birth = bi_date, entry = dg_date, exit = ex_date,  
             breaks = list(per = c(1990,2000,2010,2020), age = c(0:17*5,Inf)),
             aggre = list(agegroup = age, year.cat = per),
             status =  status != 0)

x$agegroup <- cut(x$agegroup,  c(0:17*5,Inf), right = FALSE)

## calculate rates for selected periods with Nordic 2000 weights:
r1 <- rate( data = x, obs = from0to1, pyrs = pyrs, print = year.cat, 
            adjust = agegroup, weights = 'nordic')
r1

## use total person-years by stratum as weights (some have zero)
w <- ltable(x, by.vars = "agegroup", expr = sum(pyrs))
w[is.na(w$V1),]$V1 <- 0

r2 <- rate( data = x, obs = from0to1, pyrs = pyrs, print = year.cat, 
            adjust = agegroup,
            weights = w$V1)
r2

## use data.frame of weights:
names(w) <- c("agegroup", "weights")
r2 <- rate( data = x, obs = from0to1, pyrs = pyrs, print = year.cat, 
            adjust = agegroup,
            weights = w)
r2

## internal weights (same result as above)
r3 <- rate( data = x, obs = from0to1, pyrs = pyrs, print = year.cat, 
            adjust = agegroup,
            weights = "internal")
r3

Run the code above in your browser using DataLab