medicinMacro: Medicin macro to estimate prescription lengths and averages

View source: R/medicinMacro.R

medicinMacroR Documentation

Medicin macro to estimate prescription lengths and averages

Description

Processing function, to perform calculations according to the data and variables specified in preprocessing object.

Usage

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
)

Arguments

drugs

A named list of drugs. Each element of this list should be a list with the following elements:

  • atcA vector of ATC codes which should match the components of the drug exactly.

  • maxdepot The maximum total dose that a single patient can possibly stack.

  • period A vector of dates to limit the period in which to estimate the daily dose.

  • prescriptionwindow Default is 2.

  • doses A named list with the elements value, min, max and def. Here value is a vector of strengths of one unit (e.g., pill) of the drug. The vector should have one such strength for each of the different packages that occur in the data. min is a vector of the same length as value where each element is the assumed minimum total dosis that a patient can consume on one day. For example, if the value is 50 mg and the pills of this strength can be cut (in halves) the minimum total dosis is 25 mg. max is a vector of the same length as value where each element is the assumed maximum total dosis that a patient can consume on one day. For example, if the value is 50 mg and one can at most consume 4 pills a day the maximum total dosis is 200 mg. def is a vector of the same length as value where each element is the assumed default dosis that an average patient would consume on one day. For example, if the value is 50 mg and usually a patient would consume 2 pills the default is 100 mg.

(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 getAdmLimits (SAS-AKA: code-from-hell).

datesdb

data.table with individual periods or time points of interest. Only used when the type argument is different from "dynamic". Should contain one start and end date for each individual when type equal to "period" and just one date for each individual when type equal to "cross-sectional" (see examples).

type

string, specifying which analysis to perform. Can be "dynamic", "period", or "cross-sectional". Default is "dynamic". (see examples).

drugdb.datevar

name of the date variable in drugdb. Default is "eksd".

admdb.datevars

names of the date variables in admdb. Default is c("inddto","uddto").

datesdb.datevars

name(s) of the date variables in datesdb. Should be a single string when type="cross-sectional" and a vector of two string when type="period". Default is "time" in the first case and c("start", "end") in the second.

method

Which method to use to estimate the daily dose. Can be "default.doses" or "number.of.days". Default is "default.doses". See documentation for more details. Only used when the type is different from "dynamic".

cap.values

Boolean, specifying whether or not to restrict the estimated daily dose to lie within the specified minimum and maximum dose. Default is TRUE Only used when the type is different from "dynamic".

window

Only used when the type = "cross-sectional". Specify how many days back from the given time point we should go to find purchases to estimate the daily dose.

pre.window

Only used when the type = "period". Specify how many days back from the individual end periods we should go to find purchases to estimate the daily dose for the first part of the periods.

id

Name of variable to identify individuals. Default is "pnr".

strength.var

Name of variable to identify strength. Default is "strnum".

packsize.var

Name of variable to identify size of packages. Default is "packsize".

atc.var

Name of variable to identify drugs. Default is "atc".

apk.var

Name of variable to identify number of packages. Default is "apk".

splitting

Split the data into 10 chunks to estimate remaining time (and possibly speed up computation).

verbose

bla bla?

Author(s)

Helene Charlotte Rytgaard, Anders Munch and Thomas Alexander Gerds based on the famous SAS macro by Christian Tobias Torp-Pedersen

Examples

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

tagteam/heaven documentation built on March 24, 2024, 7:58 a.m.