metrumresearchgroup / Torsten

library of C++ functions that support applications of Stan in Pharmacometrics
BSD 3-Clause "New" or "Revised" License
52 stars 11 forks source link

TAD time after dose #42

Closed csetraynor closed 2 years ago

csetraynor commented 2 years ago

Description

Hi, I wanted to know if it is possible to implement an example of how to use time after dose (TAD) in the ODE function with the pmx_solve utilities in Stan/Torsten.

Example

If I need to calculate a parameter that is a function of TAD for example:

FOO = 1 + FOO0 exp(-BETA TAD)

Expected Output

Something like the self.tad that can be used in mrgsolve would be just what's needed:

2.3.20 in https://mrgsolve.org/user_guide/model-specification.html

$MAIN

double TAD = self.tad();

Current Version:

v0.87.1

Thanks

billgillespie commented 2 years ago

The first way that comes to mind is to add a "time of most recent dose" variable (tod in the following code) for each event in the data set and then pass to the pmx_solve... function in the real data array (x_r in the Torsten documentation). That array is also passed to the user defined function specifying the ODE system. I illustrate this by modifying the twocpt_population example in the Torsten/example-models folder. I added a time-varying clearance that is a function of time after dose.

Here is the ODE function:

functions {
  // define ODE system for two compartmnt model
  vector twoCptModelODE(real t, vector x, array[] real parms,
                              array[] real tod, // time of most recent dose
                              array[] int idata) {
    // Parameters
    real CLinf = parms[1];
    real Q = parms[2];
    real V1 = parms[3];
    real V2 = parms[4];
    real ka = parms[5];
    real deltaCL0 = parms[6];
    real kCL = parms[7];

    // time-varying clearance
    real tad = t - tod[1];
    real CL = CLinf + deltaCL0 * exp(-kCL * tad);

    // Re-parametrization
    real k10 = CL / V1;
    real k12 = Q / V1;
    real k21 = Q / V2;

    // Return object (derivative)
    vector[3] y; // 1 element per compartment of
    // the model

    // PK component of the ODE system
    y[1] = -ka * x[1];
    y[2] = ka * x[1] - (k10 + k12) * x[2] + k21 * x[3];
    y[3] = k12 * x[2] - k21 * x[3];

    return y;
  }
}

The full model file and corresponding R scripts are attached. Let me know if that does or does not resolve the issue for you. twocpt_population_tad.zip

csetraynor commented 2 years ago

Perfect, Bill. That is what I needed—a top-notch solution. I appreciate your help.