How to specify initial mass in the central compartment in Torsten

I would like to have the initial mass in the central compartment as a parameter to be estimated. Maybe @billg, @yizhang, or @charlesm93 could help.
Thanks a lot.

Torsten is from Metrum, not from the Stan project. You’ve pinged the right people who work on both projects. I couldn’t find a mailing list or forum for Torsten itself, in which case, it feels like fair game to open an issue:

Hi linas,
It doesn’t look like there is a straightforward way of specifying the initial mass in the central compartment, as in you can’t pass the initial condition to a Torsten function.

One way would be to specify a “dosing” event at time t=0, which sets an initial drug mass in the central compartment. However, I’m not sure if we support passing a dosing event as a parameter (I think it has to be data but not 100% certain). This is definitely a feature we can change. I agree with @Bob_Carpenter creating the issue is the right move.

It might also be possible to change the ODE itself, with a condition at time t=0 or close to 0.

@billg and @yizhang may know another approach. If not, we need to add a feature to Torsten.

Hi Linas,

Non-zero initial conditions are readily handled by changing the variables in the ODEs from the original scale to difference from initial value. For example if dx/dt = f(x) where x(0) = x0, rewrite the ODE in terms of z = x - x0. Then the new ODE system becomes dz/dt = f(z + x0) where z(0) = 0. This approach allows you to make x0 a parameter in your Stan model.

Feel free to contact me at Metrum Research Group if you would like a worked example of this method.

Cheers,
Bill Gillespie

1 Like

Also as a follow up to @charlesm93 's reply, the amt argument may be passed as a parameter, so you can specify an initial mass in any compartment by setting amt at time = 0 for the desired compartment (the cmt argument) to that initial mass. That is probably the best way to handle it with Torsten functions that use analytic solutions, e.g., pmx_solve_onecpt and pmx_solve_twocpt. I prefer the approach I mentioned above with Torsten functions that numerically solve the ODEs and require the user to specify the system of ODEs as a function.

1 Like

I like to use analytic solutions because they are faster. Can you please give me an example of this approach? I don’t understand how amt[1] can be a parameter while remaining amt elements are data.

See: 3.2 Partially known parameters | Stan User’s Guide

The section about partially missing data is 3.2.

Hi Linas,

Here’s a worked example. I constructed it by modifying the pk2cpt example provided in the example_models folder of the Torsten distribution. It’s just a simple 2 compartment model with first order absorption fit to data from a single individual. The same approach works for a population data set, but requires a bit more data bookkeeping. I modify the data set by adding a record prior to the first record in the original data set. It is a dosing record for dosing into compartment 2 (the central compartment). The model is then modified by copying the data array called amt into a parameter array called amt_par and then making the assignment amt_par[1] = amt[1] + x2_init. This is consistent with Stan User’s Guide section that @Bob_Carpenter cited.

pk2cpt.stan (1.9 KB)
run.R (6.4 KB)

1 Like

Thanks, @billg! Always nice to get a real expert involved.

Fantastic!!! Thanks a lot.