general.haz: Extract general population hazard

View source: R/general.haz.R

general.hazR Documentation

Extract general population hazard

Description

Yearly general population hazards matched on age, gender, and calendar year is extracted from a ratetable.

Usage

general.haz(
  time,
  rmap,
  data = NULL,
  ratetable = cuRe::survexp.dk,
  scale = 365.24
)

Arguments

time

Either a numeric vector of follow-up times (in days) or a character indicating the variable containing the follow-up times in the data.

rmap

A named list. The names must match the dimension names of the ratetable input. The elements should be given as vectors containing the relevant variables in the data or a character indicating the name of the variable in the data. Elements in the list named 'age' and 'year' are transformed such that the age and year of the event/censoring time is used. 'age' must be a numeric vector given as age in days or a character indicating the variable containing the patient ages in the data. 'year' must be of class Date with the calendar time points or a character indicating the variable containing the calendar times in the data. Other variables should be coded as characters in the data.

data

The data from which to extract variables from. If time, age, sex, or year are not characters, this will not be used.

ratetable

Object of class ratetable to extract background hazards from. Defaults to survexp.dk.

scale

Numeric to adjust the scale of the outputted hazard values. If the ratetable provides daily hazards and scale = 365.24 (default), the outputted hazard values are yearly.

Value

An object of class numeric containing the yearly expected hazards.

Examples

##Use data cleaned version of the colon cancer data from the rstpm2 package
data("colonDC")
set.seed(2)
colonDC <- colonDC[sample(1:nrow(colonDC), 1000), ]

##Extract general population hazards
bhaz1 <- general.haz(time = "FU",
                     rmap = list(age = "agedays", sex = "sex", year= "dx"),
                     data = colonDC,
                     ratetable = survexp.dk)

bhaz2 <- general.haz(time = colonDC$FU,
                     rmap = list(age = colonDC$agedays, sex = colonDC$sex, year = colonDC$dx),
                     data = colonDC,
                     ratetable = survexp.dk)

all(bhaz2 == bhaz1)

LasseHjort/cuRe documentation built on July 6, 2023, 1:08 p.m.