View source: R/incidence_rates.R
rate | R Documentation |
rate
calculates adjusted rates using
preloaded weights data or user specified weights.
rate(
data,
obs = NULL,
pyrs = NULL,
print = NULL,
adjust = NULL,
weights = NULL,
subset = NULL
)
data |
aggregated data (see e.g. |
obs |
observations variable name in data.
Flexible input, typically e.g.
|
pyrs |
person-years variable name in data.
Flexible input, typically e.g.
|
print |
variable name to stratify the rates.
Flexible input, typically e.g.
|
adjust |
variable for adjusting the rates.
Flexible input, typically e.g.
|
weights |
typically a list of weights or a |
subset |
a logical expression to subset data. |
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.
The confidence intervals are based on the normal approximation of the logarithm of the rate. The variance of the log rate that is used to derive the confidence intervals is derived using the delta method.
Returns a data.table
with observations, person-years, rates and
adjusted rates, if available. 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.
Matti Rantanen, Joonas Miettinen
[lexpand]
, [ltable]
Other main functions:
Surv()
,
relpois()
,
relpois_ag()
,
sir()
,
sirspline()
,
survmean()
,
survtab()
,
survtab_ag()
Other rate functions:
rate_ratio()
## 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.