For a while, you’ve been able to get time after dose in your simulated output
library(mrgsolve)
library(tidyverse)
<- modlib("pk1", req = "")
mod
%>%
mod ev(amt = 100, ii = 4, addl = 3, time = 2) %>%
mrgsim(tad = TRUE, add = c(3.888,5.91)) %>%
as_tibble() %>%
head(n = 10)
## # A tibble: 10 × 4
## ID time tad CP
## <dbl> <dbl> <dbl> <dbl>
## 1 1 0 -2 0
## 2 1 1 -1 0
## 3 1 2 0 0
## 4 1 2 0 0
## 5 1 3 1 3.07
## 6 1 3.89 1.89 3.99
## 7 1 4 2 4.05
## 8 1 5 3 4.27
## 9 1 5.91 3.91 4.22
## 10 1 6 0 4.21
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.
<- mread("time_after_dose.txt",req = "") mod
Looking at the [MAIN]
block:
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:
[ param ] CL = 1, V = 20, KA = 1
[ pkmodel ] cmt = "GUT,CENT", depot = TRUE
[ main ]
= self.tad();
capture tadose
[ table]
= CENT/V; capture CP
%>%
mod ev(amt = 100, ii = 4, addl = 3, time = 2) %>%
mrgsim(tad = TRUE, add = c(3.888,5.91)) %>%
as_tibble() %>%
head(n = 10)
## # A tibble: 10 × 5
## ID time tad tadose CP
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 0 -2 -1 0
## 2 1 1 -1 -1 0
## 3 1 2 0 -1 0
## 4 1 2 0 0 0
## 5 1 3 1 1 3.07
## 6 1 3.89 1.89 1.89 3.99
## 7 1 4 2 2 4.05
## 8 1 5 3 3 4.27
## 9 1 5.91 3.91 3.91 4.22
## 10 1 6 0 0 4.21
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.
mrgsolve: mrgsolve.github.io | metrum research group: metrumrg.com