# Time after dose (TAD)

time after dose

In this post, we’ll look at different ways you can bring time after dose into your simulated outputs.

Author

Kyle Baron

Published

06/01/2019

# 1 TAD calculated as runtime argument

For a while, you’ve been able to get time after dose in your simulated output

``````library(mrgsolve)
library(tidyverse)

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() %>%
``````# 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.

# 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: ::: {.cell}

:::

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 ]

[ 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() %>%
``````# A tibble: 10 × 5
<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:

1. `tadose` is -1 before the first dose
2. 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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.89273286,"math_prob":0.9745673,"size":1288,"snap":"2022-40-2023-06","text_gpt3_token_len":341,"char_repetition_ratio":0.09501558,"word_repetition_ratio":0.0,"special_character_ratio":0.27795032,"punctuation_ratio":0.14181818,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97366023,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-27T15:09:11Z\",\"WARC-Record-ID\":\"<urn:uuid:1fe1c183-840a-47f7-a2f5-622bfa3f0019>\",\"Content-Length\":\"23319\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:fbee7330-fc6a-487d-a72f-06b7d4143d41>\",\"WARC-Concurrent-To\":\"<urn:uuid:41457339-000d-4c85-bdf0-8977a33317b0>\",\"WARC-IP-Address\":\"185.199.109.153\",\"WARC-Target-URI\":\"https://mrgsolve.org/blog/posts/time_after_dose.html\",\"WARC-Payload-Digest\":\"sha1:J3XDEWKQ725WSOQ2K2IWQZ3SBBWOQAX4\",\"WARC-Block-Digest\":\"sha1:H6G2DAN2X5WJHVBDB2GPDI3R3ID4J4RM\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030335034.61_warc_CC-MAIN-20220927131111-20220927161111-00772.warc.gz\"}"}