In order to stratify a cohort by a time-dependent exposure covariate (aside from age and calendar period), a history file must be created and read in. This file contains one row per person per exposure period. An exposure period is a period of time in which all daily values/levels of an exposure variable are assumed to be constant.
Below are the required variables to be found within the history file:
|id||Unique identifier for each person|
|begin_dt||Beginning date of exposure period||character|
|end_dt||End date of exposure period||character|
|<daily exposure variables>||Exposure variable(s)||numeric|
Below is an example layout of a history file with multiple exposures:
The above example contains 3 persons with 2 exposure variables,
exposure_level. Person/id 1
contains 2 non-overlapping exposure periods in which
employed is 1 for both but
drops from 71 to 5 units per day.
LTASR comes with an example history file, called
history_example, that can be used in conjunction with
person_example for testing. Below reads in both example
files and formats dates appropriately:
<- person_example %>% person 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')) <- history_example %>% history mutate(begin_dt = as.Date(begin_dt, format='%m/%d/%Y'), end_dt = as.Date(end_dt, format='%m/%d/%Y')) %>% group_by(id)
For the remainder of this section, we will consider Person/id 1 to demonstrate how exposure is calculated over time. Below is the information found within the person file for person/id 1:
This example person’s follow-up starts on 12/21/1970 and continues
through 7/31/2016. Below plots their cumulative exposure for both
Both exposures start at 0, then
employed increases by 1
unit per day for both periods. This can therefore be thought of as a
duration variable (in days) of all periods. The
exposure_level increases rapidly (71 units per day) during
the first period and then increases slower (5 units per day).
NOTE: Any gaps within the history file and the follow-up times (for example, the period between the last exposure period within the history file and through the end of follow-up) is assumed to be 0. That is, exposure values do not change during these periods.
Once the person file and history file have been read in (see Demo
for basic stratification vignette for additional information on how
to read in files), information on how to stratify the exposure variables
must be defined using the
Below specifies which exposure variables to consider, what cut-points to use for stratification and any lag (in years) to apply to the cumulative exposure variable:
<- exp_strata(var = 'employed', exp1 cutpt = c(-Inf, 365, Inf), lag = 0) <- exp_strata(var = 'exposure_level', exp2 cutpt = c(-Inf, 0, 10000, 20000, Inf), lag = 10)
employed variable will contain 2 strata: (-Inf, 365]
and (365, Inf]. Or, put alternatively, ≤ 1 year and > 1 year.
exposure_level will contain 5 strata: (-Inf, 0], (0,
10000], (10000, 20000] and (20000, Inf). Therefore, the first category
defines unexposed person-time. Additionally, a 10 year lag will be
applied when defining strata.
Once the exposure strata have been defined, LTASR provides two
functions for stratifying the cohort. One is
get_table_history whose usage is:
<- get_table_history(persondf = person, py_table rateobj = us_119ucod_19602021, historydf = history, exps = list(exp1, exp2))
This creates the below table:
This function is very fast, and replicates how the original LTAS behaved. It also exactly stratifies the person-days into the appropriate strata. However, it may be desired to calculate mean exposure values for each strata to be used in a Poisson regression later. To implement this exactly is very slow.
Therefore, a separate function,
calculates these mean exposure values and also allows for a
step parameter to be specified defining the number of days
to calculate the cumulative exposure.
An example usage is:
<- get_table_history_est(persondf = person, py_table_est rateobj = us_119ucod_19602021, historydf = history, exps = list(exp1, exp2), step = 7)
step = 7, person time is considered every
7 days when allocating person-time to strata. This results in a
significant increase in speed at the cost of a (generally) trivial
amount of inaccuracy.
step = 1 will calculate strata
exactly for each individual day, but is significantly
Below is the result of this specification:
As can be seen, the
pday are slightly different than the
previous table. However, the effects on results will generally be
In addition, two additional variables are available:
exposure_level indicating the
person-time weighted mean values.
## Step Specifications
When specifying the step parameter, there is a trade-off between
computation speed and accuracy. Specifying
step = 1 will
result in the most accurate stratification, but can be extremely
To investigate this further, below plots the time (in minutes) taken
to stratify a cohort of 5,200 people with 2 exposure variables for
various specifications of the
There are dramatic savings in computation time when increasing the
step parameter in the low end. In this example, at about
step = 10, improvements in computation time diminishes. It
seems a step parameter of about 5-10 is a good compromise.
Exact times will depend upon:
An additional consideration is the level of detail of the exposure
variable. That is, if exposure is dramatically changing, relative to its
specified strata, the loss of accuracy will be more dramatic for small
increases of the step parameter. For example, age is stratified by
5-year increments, therefore, a
step value of 1-week
step = 7) will cause a trivial amount of inaccuracy.
One option is to use a crude step value during initial investigations, but when results are to be published/presented, the function can be run again with a smaller step value.