standardize.rate: Standardize proportions and absolute risks to a given age...

View source: R/standardize.rate.R

standardize.rateR Documentation

Standardize proportions and absolute risks to a given age distribution

Description

Standardize proportions and absolute risks to a given age distribution

Usage

standardize.rate(
  x,
  age = "agegroups",
  exposure,
  by,
  standardize.to = "ref.level",
  data,
  method = "gamma",
  level = 0.95,
  crude = TRUE,
  ...
)

Arguments

x

List of names of variable names used to calculate the rates. Each element of the list contains the names of two variables in the dataset: the first variable contains the number of events and the second variable contains the number of subjects or person years.

age

Name of categorical age variable.

exposure

Name of the exposure variable for rate ratios.

by

Vector of names of further categorical strata variables

standardize.to

what population to use for standardization.

data

Data set which contains all the variables

method

Character. The method for calculating confidence intervals. If "gamma" use gamma distribution (see Fay et al.). If "wald" or "wald-log" use normal or log-normal approximation.

level

Confidence level

crude

Logical. If TRUE calculate crude rates too.

...

Not (yet) used

Details

Standardize proportions and absolute risks to a given age distribution

Value

Data table with standardized rates (and crude rates if asked for)

Author(s)

Thomas A. Gerds <tag@biostat.ku.dk>, Jeppe E. H. Madsen <jehm@sund.ku.dk>

References

Michael P Fay. Approximate confidence intervals for rate ratios from directly standardized rates with sparse data. Communications in Statistics- Theory and Methods, 28(9):2141–2160, 1999.

Niels Keiding, David Clayton, et al. Standardization and control for confounding in observational studies: a historical perspective. Statistical Science, 29(4):529–558, 2014.

See Also

standardize.prodlim standardize.proportion epitools::ageadjust.direct

Examples

library(riskRegression)
library(data.table)
set.seed(84)
n=160
d <- data.table(e1=rpois(n,lambda=9),
                rt1=rpois(n,lambda=1880),
                e2=rpois(n,lambda=123),
                rt2=rpois(n,lambda=80000))
d[,agegroups:=factor(rep(c("40-50","45-50","50-55","55-60","60-65","65-70","70-75","75-80"),n/8))]
d[,sex:=factor(rep(c("f","m"),c(n/2,n/2)))]
d[,year:=rep(2001:2010,n/10)]
D=d[,.(e1=sum(e1),rt1=sum(rt1),e2=sum(e2),rt2=sum(rt2)),by=c("sex","agegroups")]
D[sex=="m",e1:=e1+rpois(.N,lambda=as.numeric(agegroups)*17)]
D[sex=="m",rt1:=rt1-rpois(.N,lambda=as.numeric(agegroups)*1600)]
standardize.rate(x=list(c("e1","rt1")),
                 age="agegroups",exposure="sex",data=D,standardize.to="f")
standardize.rate(x=list(c("e1","rt1")),
                 age="agegroups",exposure="sex",data=D,standardize.to="m")
standardize.rate(x=list(c("e1","rt1")),
                 age="agegroups",exposure="sex",data=D,standardize.to="mean")
standardize.rate(x=list("rate1"=c("e1","rt1"),"rate2"=c("e2","rt2")),
                 age="agegroups",exposure="sex",data=d,by="year")

# more than 2 exposures does not yet work!! workaround is to subset ...
## Not run: 
d[,groups:=factor(rep(paste0("G",1:4),rep(n/4,4)))]
D=d[,.(e1=sum(e1),rt1=sum(rt1),e2=sum(e2),rt2=sum(rt2)),by=c("groups","agegroups")]
D[groups=="G3",e1:=e1+rpois(.N,lambda=as.numeric(agegroups)*17)]
D[groups=="G3",rt1:=rt1-rpois(.N,lambda=as.numeric(agegroups)*1600)]
standardize.rate(x=list(c("e1","rt1")),
                 age="agegroups",exposure="groups",data=D,standardize.to="mean")

## End(Not run)

tagteam/heaven documentation built on Oct. 24, 2024, 7:40 p.m.