source("global.R") set.seed(10072)
TAD
stands for time after dose. In mrgsolve, any time TAD
is calculated
automatically, a dose is a record in the input data set where EVID
is set to
either 1 or 4.
For a while, you've been able to get time after dose in your simulated output
library(mrgsolve) library(dplyr) mod <- modlib("pk1", req = "") mod %>% ev(amt = 100, ii = 4, addl = 3, time = 2) %>% mrgsim(tad = TRUE, add = c(3.888,5.91)) %>% as_tibble() %>% head(n = 10)
This is convenient because you can choose the output at run time, we give you the negative numbers prior to the first dose etc. This sort of calculation is possible because we let mrgsolve know ahead of time that we want this calculation done and mrgsolve makes an extra pass through the records to find when is the first dose for each individual.
Sometimes you would like to work with time after dose in your model. This isn't super-complicated to do but does require some programming and setup and all of that. As of mrgsolve 0.9.1, there is a special function to do these calculations for you.
mod <- mread("time-after-dose.txt",req = "")
x <- readLines("time-after-dose.txt",warn=FALSE) %>% modelparse()
Looking at the [MAIN]
block:
```{c,eval=FALSE, code = x$MAIN}
When you call `self.tad()` you will get the time after dose. It's important that this gets called on every record ... specifically every dosing record. It will not work properly if it is not called every record and there is no check at this time to make sure you follow that rule. So please follow the rule. To see an example: ```{c, eval=FALSE, code = mod@code}
mod %>% ev(amt = 100, ii = 4, addl = 3, time = 2) %>% mrgsim(tad = TRUE, add = c(3.888, 5.91)) %>% as_tibble() %>% head(n = 10)
You will notice two differences between tad
(output requested at
run time) and tadose
(values calculated in the model itself) in the
output listing above:
tadose
is -1 before the first dosetadose
is -1 at the 2 hour observation record
that occurs that the same time as the dose, but happens before
the dose in record orderThe main point if this is that you can easily obtain time after dose in the problem (model) itself to use as you program the model and also output the number into the simulated output.
Version 0.10.7 adds a new plugin with the ability to calculate time after dose in any compartment.
We write a model using the tad
plugin to track time after dose in
compartments one
and two
. We create tadose
objects to track
this and we can call the tad()
method on these objects, passing
in the self
data item.
code <- ' [plugin] tad [ global ] mrg::tadose tad_cmt_1(1); mrg::tadose tad_cmt_2(2); [ pkmodel ] cmt = "GUT,CENT", depot = TRUE [ param ] CL = 1, V = 20, KA = 1 [ main ] capture tad1 = tad_cmt_1.tad(self); capture tad2 = tad_cmt_2.tad(self); ' mod <- mcode("tad", code, soloc = '.') data <- c( ev(amt = 100, cmt = 1, time = 1), ev(amt = 200, cmt = 2, time = 3) ) mrgsim(mod, data)
Note that time after dose is -1 until a dose is administered.
Recall also that time after dose can be calculated more simply if there is
only one dose type by passing the tad
argument:
data1 <- filter(data, cmt ==1) %>% mutate(time = 3) mod %>% mrgsim(data1, tad = TRUE)
This is a little nicer because it will fill in negative tad
values for you.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.