medicinMacro | R Documentation |
Processing function, to perform calculations according to the data and variables specified in preprocessing object.
medicinMacro(
drugs,
drugdb,
admdb,
datesdb,
type = "dynamic",
drugdb.datevar = "eksd",
admdb.datevars = c("first.indate", "last.outdate"),
datesdb.datevars,
method,
cap.values,
window,
pre.window,
id = "pnr",
strength.var = "strnum",
packsize.var = "packsize",
atc.var = "atc",
apk.var = "apk",
splitting = FALSE,
verbose = FALSE
)
drugs |
A named list of drugs. Each element of this list should be a list with the following elements:
(see examples). |
drugdb |
data.table with (subset of) medical drugs registry |
admdb |
data.table with (subset of) hospital admission registry. The data.table should be
prepared such that it contains only overnight hospital stay (i.e., pattype=2) and non-overlapping
hospital stay periods, i.e., as obtained with |
datesdb |
data.table with individual periods or time points of interest.
Only used when the |
type |
string, specifying which analysis to perform.
Can be |
drugdb.datevar |
name of the date variable in |
admdb.datevars |
names of the date variables in |
datesdb.datevars |
name(s) of the date variables in |
method |
Which method to use to estimate the daily dose. Can be |
cap.values |
Boolean, specifying whether or not to restrict the estimated daily dose to lie
within the specified minimum and maximum dose. Default is |
window |
Only used when the |
pre.window |
Only used when the |
id |
Name of variable to identify individuals. Default is
|
strength.var |
Name of variable to identify strength. Default
is |
packsize.var |
Name of variable to identify size of
packages. Default is |
atc.var |
Name of variable to identify drugs. Default is |
apk.var |
Name of variable to identify number of
packages. Default is |
splitting |
Split the data into 10 chunks to estimate remaining time (and possibly speed up computation). |
verbose |
bla bla? |
Helene Charlotte Rytgaard, Anders Munch and Thomas Alexander Gerds based on the famous SAS macro by Christian Tobias Torp-Pedersen
set.seed(05021992)
library(data.table)
N=20
packs = list("R03AK11"=list(c(750,75),c(500,200),c(400,200)),
"R03AL03"=list(c(750,75),c(500,200),c(400,200)),
"C01CA01"=list(c(200,100),c(750,30)))
lmdb=simPrescriptionData(N,packages=packs)
lpr=simAdmissionData(N)
lpr <- getAdmLimits(lpr,collapse=TRUE)
drug1 = list(atc=c("R03AK11","R03AL03","R03AC02","R03AC04","R03AC19",
"R03AL02","R03AA01","R03AC18","R03AL01"),
maxdepot=4000,
period=as.Date(c("1995-01-01", "2012-12-31")),
prescriptionwindow=2,
doses=list(value=c(750,500,400,200,75),
min = c(250,200,200,100,25),
max = c(1000,600,800,600,100),
def = c(750,500,400,200,75)))
drug2=list(atc=c("C01CA01","C01AA05"),
maxdepot=4000,
period=as.Date(c("1995-01-01", "2012-12-31")),
prescriptionwindow=2,
doses=list(value=c(200, 400, 500,750),
min = c(100, 200, 250,750),
max = c(300, 800, 1000,750),
def = c(200, 400, 500,750)))
x=medicinMacro(drugs=list("drug1"=drug1,"drug2"=drug2),drugdb=lmdb,admdb=lpr)
x$drug1
## without admdata
x1=medicinMacro(drugs=list("drug1"=drug1,"drug2"=drug2),drugdb=lmdb,admdb=NULL)
x1$drug1
## Examples with other types
## NB: Calculations with maxdepot>0 is not implemented yet for type different from "dynamic".
## Not specifying maxdepot is the same at setting maxdepot=0.
library(data.table)
drug1 = list(atc=c("R03AK11","R03AL03","R03AC02","R03AC04","R03AC19",
"R03AL02","R03AA01","R03AC18","R03AL01"),
doses=list(value=c(750,500,400,200,75),
min = c(250,200,200,100,25),
max = c(1000,600,800,600,100),
def = c(750,500,400,200,75)))
drug2=list(atc=c("C01CA01","C01AA05"),
doses=list(value=c(200, 400, 500,750),
min = c(100, 200, 250,750),
max = c(300, 800, 1000,750),
def = c(200, 400, 500,750)))
## Note that we define the periods separately, as they are now individual:
ind.periods <- data.table(pnr=1:N,
start=rep(as.Date("1996-01-01"), N)+floor(rnorm(N,sd=100)),
end=rep(as.Date("1998-05-30"), N)+floor(rnorm(N,sd=100)))
z=medicinMacro(drugs=list("drug1"=drug1,"drug2"=drug2),drugdb=lmdb,admdb=lpr,
type="period",datesdb=ind.periods)
z$drug1
## Using different method:
z=medicinMacro(drugs=list("drug1"=drug1,"drug2"=drug2),drugdb=lmdb,admdb=lpr,
type="period",datesdb=ind.periods, method="number.of.days")
z$drug1
## Using type = "cross-sectional" to check if individuals are exposed at a given time
## Note that we now only give one timepoint but then also need to supply the window argument
ind.periods2 <- copy(ind.periods)
ind.periods2[,time:=start][,c("start","end"):=NULL]
y=medicinMacro(drugs=list("drug1"=drug1,"drug2"=drug2),drugdb=lmdb,admdb=lpr,
type="cross-sectional",datesdb=ind.periods2, window=365.25)
y$drug1
## Changing the window size of course affects our estimates:
y=medicinMacro(drugs=list("drug1"=drug1,"drug2"=drug2),drugdb=lmdb,admdb=lpr,
type="cross-sectional",datesdb=ind.periods2, window=10)
y$drug1
## Above, we renamed the date variables before plugging it in, but we could also have used the
## datesdb.datevars argument:
y=medicinMacro(drugs=list("drug1"=drug1,"drug2"=drug2),drugdb=lmdb,admdb=lpr,
type="cross-sectional",datesdb=ind.periods, window=365.25,
datesdb.datevars="start")
y$drug1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.