pkpd library discussions

65 views
Skip to first unread message

Sebastian Weber

unread,
Jul 18, 2016, 4:36:06 AM7/18/16
to stan development mailing list
Hi!

Triggered by the large Torsten thread it would make sense to discuss as to how to move forward. Discussing this during a stan meeting maybe too specific on a single topic, so how about putting this topic on the stan meeting agenda with the intention to find a way to move forward (i.e. schedule a meeting among interested people or whatever appears appropriate).

If that makes sense, I put it on the agenda.

Best,
Sebastian

Sebastian Weber

unread,
Jul 19, 2016, 5:52:32 AM7/19/16
to stan development mailing list
Hi!

I finally managed to polish my own Stan codes which handle PK systems. I placed these in the example-models repo:

https://github.com/stan-dev/example-models/tree/feature/issue-72-stan-pkpdlib/misc/pkpd

See the README there for details. Comments are very much welcome!

The design is kept general an extensible; yet the user of these tools only needs to modify very few things. To make things user convenient I chose to take advantage of the include functionality offered by rstan; I hope that was ok.

Best,
Sebastian

Bob Carpenter

unread,
Jul 19, 2016, 5:42:41 PM7/19/16
to stan...@googlegroups.com
Thanks!

- Bob
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Sebastian Weber

unread,
Jul 20, 2016, 9:02:43 AM7/20/16
to stan development mailing list
Sure. It was a good occasion for me to clean and brush the code somewhat.

Going over the code once more I noticed that regular dosing patterns (addl dose coding) should not be used with ODE based systems. Maybe I should try to add a ODE based PK system?

I always try hard when modeling in Stan to stay with analytical solutions.

If things don't make sense to you, let me know. If you go into details, you will notice that a few operations are repeated over and over again (repeated length coding aka rle and blocked evaluation of things). Should there be more clever (faster) Stan solutions, I would be very interested.

Sebastian

On Tuesday, July 19, 2016 at 11:42:41 PM UTC+2, Bob Carpenter wrote:
> Thanks!
>
> - Bob
>
> > On Jul 19, 2016, at 5:52 AM, Sebastian Weber
> >

Devin Pastoor

unread,
Jul 20, 2016, 12:44:35 PM7/20/16
to stan development mailing list
What do you mean by regular dosing patterns (addl) shouldn't be used with ODE based systems? Wouldn't that "just" be a preprocessing step to expand the actual dosing information before entering the system?

Using an R-based example,

ID time dose addl ii
<int> <dbl> <dbl> <dbl> <dbl>
1 1 0 100 8 12
2 2 0 100 8 12

then given a method addl_to_doses() the data going into the ODE system might look like

Source: local data frame [18 x 4]

ID time dose ii
<int> <dbl> <dbl> <dbl>
1 1 0 100 12
2 1 12 100 12
3 1 24 100 12
4 1 36 100 12
5 1 48 100 12
6 1 60 100 12
7 1 72 100 12
8 1 84 100 12
9 1 96 100 12
10 2 0 100 12
11 2 12 100 12
12 2 24 100 12
13 2 36 100 12
14 2 48 100 12
15 2 60 100 12
16 2 72 100 12
17 2 84 100 12
18 2 96 100 12

R-based example code (not that I would necessarily envision pre-processing in R, just something easy to make a quick example)

library(purrr)
library(dplyr)
library(tibble)
id_addl <- data_frame(ID = 1:2, time = 0, dose = 100, addl = 8, ii = 12)

addl_to_doses <- function(df) {
df %>% by_row(function(row) {
data_frame(DNUM = 0:(row$addl))
}, .collate="rows") %>%
mutate(time = time + ii*DNUM) %>%
select(-.row, -addl, -DNUM)
}
addl_to_doses(id_addl)


Would something like that feasible for expanding out the dosing events?

At least from my end, though analytical solutions are almost always preferable when possible, given the "complexity" of many of the projects I've worked on (tmdd, complex dosage forms, PD models) I rarely get the pleasure of analytical solutions.

Sebastian Weber

unread,
Jul 20, 2016, 4:21:26 PM7/20/16
to stan development mailing list
Regular dosing patterns allow huge optimizations when you have an analytically solvable system. However, I am not aware of any optimization you can do for the case of ODEs when you subject them to regular dosing.

Finally, my little programs would run very inefficient if you use ODEs and addl dose coding - so yes, for ODEs I would strongly advise to do what you coded in R (that is "unpack" those addl records).

Best,
Sebastian

PS: To me ODEs are only a convenient facility to express a kinetic system, but solving it doesn't mean you have to use an ODE. You can use analytic things far more often than most people think at least this is my experience so far. Since I have seen running times of 3 days with an ODE and 4h without (same result), I have a clear preference...

Reply all
Reply to author
Forward
0 new messages