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.
2 TAD calculated in the model
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 ="")
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 ]capture tadose = self.tad();[ table]capture CP = CENT/V;
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 dose
specifically, tadose is -1 at the 2 hour observation record that occurs that the same time as the dose, but happens before the dose in record order
The 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.