addDrug.Lexis: Expand a Lexis object with information of drug exposure based...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/addDrug.Lexis.R

Description

A Lexis object will contain information on follow-up for a cohort of persons through time, each record containing information of one time interval, including the time at the beginning of each interval. If information on drug purchase is known for the persons via lex.id in a list of data frames, addDrug.Lexis will expand the Lexis object by cutting at all drug purchase dates, and compute the exposure status for any number of drugs, and add these as variables.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
addDrug.Lexis(Lx,  # Lexis object
            pdat,  # list of data frames with drug purchase information
             amt = "amt", # name of the variable with purchased amount
             apt = "apt", # name of the variable with amount consumed per time
          method = "ext", # method use to compute exposure 
            maxt = NULL,  # max duration for a purchase when using \code{method="fix"}
           grace = 0,     # grace  period to be added
            tnam = setdiff(names(pdat[[1]]), c("lex.id", amt))[1],
                          # name of the 
          prefix = NULL,  # character vector of length \code{length(pdat)}
          suffix = NULL,  # character vector of length \code{length(pdat)}
          sepfix = ".")   # what should the separator be when forming prefix/suffix

Arguments

Lx

A Lexis object.

pdat

Named list of data frames with drug purchase data.

amt

Name of the variable in the data frames in pdat with the purchased amount.

apt

Name of the variable in the data frames in pdat with the consumed amount per time. Must be given in units of units of amt per units of lex.dur in Lx.

method

Character. One of "ext" (default), "amt" or "fix", for a description, see details.

maxt

Numerical. Maximal duration for a purchase when using method="fix", same units as lex.dur.

grace

Numeric. Grace period to be added after last time of computed drug coverage to define end of exposure, same units as lex.dur.

tnam

Character. Name of the timescale used in the data frames in pdat.

prefix

Character vector of length length(pdat). Used to prefix the 4 generated exposure variables.

suffix

Character vector of length length(pdat). Used to suffix the 4 generated exposure variables.

sepfix

Character, used to separate the prefix and the name of the generated type of variable.

Details

This function internally uses addCov.Lexis to attach exposure status for several drugs (dispensed medicine) to follow-up in a Lexis object. Once that is done, the exposure measures are calculated at each time.

There is one input data frame per type of drug, each with variables lex.id, amt, a timescale variable and possibly apt.

Three different methods for computing drug exposures from dates and amounts of purchases are supported via the argument method.

So for each purchase we have defined an end of coverage (expiry date). If next purchase is before this, we assume that the amount purchased is consumed over the period between the two purchases, otherwise over the perido to the end of coverage. So the only difference between the methods is the determination of the coverage for each purchase.

Based on this, for each date in the resulting Lexis four exposure variables are computed, see next section.

Value

A Lexis object with the same risk time, states and events as Lx. The follow-up for each person has been cut at the purchase times of each of the drugs, as well as at the expiry times for drug coverage. Further for each drug (i.e. data frame in the pdat list) 4 variables have been added:

Author(s)

Bendix Carstensen, http://bendixcarstensen.com

See Also

addCov.Lexis, gen.exp, cutLexis, rcutLexis, mcutLexis

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Follow-up of 2 persons
fu <- data.frame(doe = c(2006, 2008),
                 dox = c(2015, 2018),
                 dob = c(1950, 1951),
                 xst = factor(c("A","D")))
Lx <- Lexis(entry = list(per = doe,
                         age = doe- dob),
             exit = list(per = dox),
      exit.status = xst,
             data = fu)
Lx <- subset(Lx, select = -c(doe, dob, dox, xst))

# split FU in 1 year intervals
Sx <- splitLexis(Lx, "per", breaks = seq(1990, 2020, 1.0))

rc <- data.frame(per = c(2007 + runif(12,0,10)),
                 amt = sample(2:4, 12, r = TRUE),
              lex.id = sample(1:2, 12, r = TRUE))
rc <- rc[order(rc$lex.id, rc$per),]

rd <- data.frame(per = c(2009 + runif(10, 0, 10)),
                 amt = sample(round(2:4/3,1), 10, r = TRUE),
              lex.id = sample(1:2, 10, r = TRUE))
rd <- rd[order(rd$lex.id, rd$per),]

pdat <- list(Joe = rc, Pat = rd)
pdat

addDrug.Lexis(Sx, pdat, method = "ext") # default
addDrug.Lexis(Sx, pdat, method = "ext", grace = 0.2)
addDrug.Lexis(Sx, pdat, method = "dos", apt = 6)
addDrug.Lexis(Sx, pdat, method = "fix", maxt = 1)

Epi documentation built on Feb. 28, 2021, 1:06 a.m.

Related to addDrug.Lexis in Epi...