get_table_history_est {LTASR} | R Documentation |
Stratify Person Table with Time Varying Co-variate
Description
get_table_history_est
reads in a data.frame/tibble (persondf
) containing basic demographic information for
each person of the cohort as well as a data.frame/tibble (historydf
) containing time varying exposure
information and stratifies the person-time and deaths into 5-year age, 5-year calendar period, race, sex and
exposure categories. Additionally, average cumulative exposure values for each strata and each exposure
variable are included. These strata are more crudely calculated by taking regular steps (such as every 7 days)
as opposed to evaluating every individual day. See Details
for information on how the person file and history file must be
formatted.
Usage
get_table_history_est(
persondf,
rateobj,
historydf,
exps,
strata = dplyr::vars(),
step = 7,
batch_size = 25 * step
)
Arguments
persondf |
data.frame like object containing one row per person with the required demographic information. |
rateobj |
a rate object created by the |
historydf |
data.frame like object containing one row per person and exposure period. An exposure period is a
period of time where exposure levels remain constant. See |
exps |
a list containing exp_strata objects created by |
strata |
any additional variables contained in persondf on which to stratify.
Must be wrapped in a |
step |
numeric defining number of days to jump when calculating cumulative exposure values. Exact stratification specifies a step of 1 day. |
batch_size |
a number specifying how many persons to stratify at a time. |
Details
The persondf tibble must contain the variables:
id,
gender (character: 'M'/'F'),
race (character: 'W'/'N'),
dob (date),
pybegin (date),
dlo (date),
rev (numeric: values 5-10),
code (character: ICD code)
The historydf tibble must contain the variables:
id,
begin_dt (date),
end_dt (date),
-
<daily exposure levels>
Value
A data.frame with a row for each strata containing the number of observed
deaths within each of the defined minors/outcomes (_o1
-_oxxx
) and the number of person days.
Examples
library(LTASR)
library(dplyr)
#Import example person file
person <- person_example %>%
mutate(dob = as.Date(dob, format='%m/%d/%Y'),
pybegin = as.Date(pybegin, format='%m/%d/%Y'),
dlo = as.Date(dlo, format='%m/%d/%Y'))
#Import example history file
history <- history_example %>%
mutate(begin_dt = as.Date(begin_dt, format='%m/%d/%Y'),
end_dt = as.Date(end_dt, format='%m/%d/%Y'))
#Import default rate object
rateobj <- us_119ucod_19602021
#Define exposure of interest. Create exp_strata object.The `employed` variable
#indicates (0/1) periods of employment and will be summed each day of each exposure
#period. Therefore, this calculates duration of employment in days. The cut-points
#used below will stratify by person-time with less than and greater than a
#year of employment (365 days of employment).
exp1 <- exp_strata(var = 'employed',
cutpt = c(-Inf, 365, Inf),
lag = 0)
#Stratify cohort by employed variable.
py_table <- get_table_history_est(persondf = person,
rateobj = rateobj,
historydf = history,
exps = list(exp1))
#Multiple exposures can be considered.
exp1 <- exp_strata(var = 'employed',
cutpt = c(-Inf, 365, Inf),
lag = 0)
exp2 <- exp_strata(var = 'exposure_level',
cutpt = c(-Inf, 0, 10000, 20000, Inf),
lag = 10)
#Stratify cohort by employed variable.
py_table <- get_table_history_est(persondf = person,
rateobj = rateobj,
historydf = history,
exps = list(exp1, exp2))