Learn R Programming

dlnm (version 2.4.7)

exphist: Define Exposure Histories from an Exposure Profile

Description

This function builds a matrix of exposure histories given an exposure profile, the time points at which each exposure history is evaluated, and a lag period.

Usage

exphist(exp, times, lag, fill=0)

Arguments

exp

an exposure profile defined at equally-spaced time units, from time 1 on.

times

either a numeric scalar or vector of integer numbers specifying the time points at which each exposure history is evaluated. By default, all the time points of exp. See Details.

lag

either an integer scalar or vector of length 2, defining the the maximum lag or the lag range, respectively. By default, the lag period from 0 to length(exp)-1.

fill

value used to fill the exposure history. See Details.

Value

A numeric matrix of exposure histories, with named rows corresponding to the values in times and named columns corresponding to the lag period in lag.

Details

This function is used to define matrices of exposure histories (backward in time) given an exposure profile (forward in time). Among other uses, this can be applied to define specific exposure histories for obtaining predictions in crosspred.

The exposure profile in exp is assumed to represent a series of exposure events defined forward in time, starting from time 1 and on. An exposure history is then evaluated backward in time for each point defined by times (rounded to integers) on the lag period defined by lag.

Negative numbers in exp represent time points before the start of the exposure profile, with 0 as the time immediately before, -1 as two times before, and so on. If the values in times are higher than the length of exp, or negative, or if the lag period extends backward before the beginning of the exposure profile, the exposure history is padded with values defined by fill.

References

Gasparrini A. Modeling exposure-lag-response associations with distributed lag non-linear models. Statistics in Medicine. 2014;33(5):881-899. [freely available here]

See Also

crosspred to obtain predictions after model fitting.

See dlnm-package for an introduction to the package and for links to package vignettes providing more detailed information.

Examples

Run this code
# NOT RUN {
### an exposure history evaluated at a single time
(exp <- sample(1:10))
exphist(exp, 5, 3)
exphist(exp, 5, 12)
exphist(exp, 15, 3)

### use of argument lag
exphist(exp, 10, c(3,7))

### exposure histories evaluated at multiple times
exphist(exp, 3:5, 12)
exphist(exp, lag=12)

### fill with NA's
exphist(exp, lag=12, fill=NA)

### see the vignette dlnmExtended for further examples
# }

Run the code above in your browser using DataLab