View source: R/addDrug.Lexis.R
addDrug.Lexis | R Documentation |
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.
In some circumstances the result is a Lexis object with a very large
number of very small follow-up intervals. The function
coarse.Lexis
combines consecutive follow-up intervals using the
covariates from the first of the intervals.
## S3 method for class 'Lexis'
addDrug(Lx, # Lexis object
pdat, # list of data frames with drug purchase information
amt = "amt", # name of the variable with purchased amount
dpt = "dpt", # name of the variable with amount consumed per time
apt = NULL, # old name for dpt
method = "ext", # method use to compute exposure
maxt = NULL, # max duration for a purchase when using "fix"
grace = 0, # grace period to be added
tnam = setdiff(names(pdat[[1]]), c("lex.id", amt))[1],
# name of the time variable from Lx
prefix = TRUE, # should drug names prefix variable names
sepfix = ".", # what should the separator be when forming prefix/suffix
verbose = TRUE,
...)
coarse.Lexis(Lx, lim, keep = FALSE)
Lx |
A |
pdat |
Named list of data frames with drug |
amt |
Name of the variable in the data frames in |
dpt |
Name of the variable in the data frames in |
apt |
Name previously used for |
method |
Character. One of |
maxt |
Numerical. Maximal duration for a purchase when using
|
grace |
Numeric. Grace period to be added after last time of
computed drug coverage to define end of exposure, same units as
|
tnam |
Character. Name of the timescale used in the data frames
in |
prefix |
Logical. Should the names of |
sepfix |
Character, used to separate the |
verbose |
Logical. Should the function tell you about the choices you made? |
lim |
Numeric vector of length 2. Consecutive follow-up intervals
are combined if the first has |
keep |
Logical of length 1 or |
... |
Arguments passed on. Ignored. |
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 a variable
dpt
.
Three different methods for computing drug exposures from dates and
amounts of purchases are supported via the argument method
.
"ext"
: Extrapolation: the first drug purchase is assumed
consumed over the interval to the second purchase. Exposure
for subsequent purchases are assumed to last as long as it would have if
consumed at a speed corresponding to the previous purchase being
consumed over the time span between the previous and current purchase,
plus a period of length grace
.
"dos"
: Dosage: assumes that each purchase lasts
amt
/dpt
plus grace
.
"fix"
: Fixed time: assumes that each purchase lasts
maxt
.
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 period 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.
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 each drug
coverage. Further, for each drug (i.e. the data frame in the pdat
list) the name of the pdat
component determines the prefix for
the 4 variables that will be added. Supposing this is AA
for a
given drug, then 4 new variables will be:
AA.ex
: logical; is the person exposed in this interval
AA.tf
: numeric: time since first purchase, same units as
lex.dur
AA.ct
: numeric: cumulative time on the drug, same units
as lex.dur
AA.cd
: numeric: cumulative dose of the drug, same units
as amt
So if pdat
is a list of length 3 with names c("a","b","c")
the function will add variables
a.ex, a.tf, a.ct, a.cd,
b.ex, b.tf, b.ct, b.cd,
c.ex, c.tf, c.ct, c.cd
Bendix Carstensen, http://bendixcarstensen.com
gen.exp
,
addCov.Lexis
,
cutLexis
,
rcutLexis
,
mcutLexis
# Follow-up of 2 persons
clear()
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))
# drug purchases, one data frame for each drug
ra <- data.frame(per = c(2007 + runif(12,0,10)),
amt = sample(2:4, 12, r = TRUE),
lex.id = sample(1:2, 12, r = TRUE))
ra <- ra[order(ra$lex.id, ra$per),]
rb <- 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))
rb <- rb[order(rb$lex.id, rb$per),]
# put in a named list
pdat <- list(A = ra, B = rb)
pdat
ex1 <- addDrug.Lexis(Sx, pdat, method = "ext") # default
summary(ex1)
# collapsing some of the smaller intervals with the next
summary(coarse.Lexis(ex1, c(0.2,0.5)))
ex2 <- addDrug.Lexis(Sx, pdat, method = "ext", grace = 0.2)
dos <- addDrug.Lexis(Sx, pdat, method = "dos", dpt = 6)
fix <- addDrug.Lexis(Sx, pdat, method = "fix", maxt = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.