nlmixrdevelopment / RxODE

RxODE is an R package that facilitates easy simulations in R
https://nlmixrdevelopment.github.io/RxODE/
GNU General Public License v3.0
54 stars 14 forks source link

params changing with time #488

Closed sliao999 closed 1 year ago

sliao999 commented 1 year ago

Times = list(t1 = seq(0, 12, by = 0.1), t2 = seq(12, 24, by = 0.1)), out <- rxSolve(model = ode, params = params, inits = inits)

params has different values in t1, and t2. How can I use rxSolve to solve the PK model ode? if t1 params=param1, else if t2 params=param1,

Sam

mattfidler commented 1 year ago

Hi @sliao999 you can put the time-changing parameter as a covariate in the dataset, or you can use time in your model, whatever you prefer.

sliao999 commented 1 year ago

Thanks for your quick reply. We did try this as shown below, got error msg saying times is not an argument for rxSolve.

times <- list(t1 = seq(0, 12, by = 0.1), t2 = seq(12, 24, by = 0.1)) params <- list(t1 = c(param1 = 1, param2 = 2), t2 = c(param1 = 3, param2 = 4))

inits <- c(state1 = 0, state2 = 0) ode <- " dxdt1 = -param1 x1 dxdt2 = param1 x1 - param2 * x2 " out <- rxSolve(model = ode, times = times, params = params, inits = inits)

sliao999 commented 1 year ago

Can you please share an example?

Sam

sliao999 commented 1 year ago

How do you do this as a covariate? In our case, the covariate is the dose, and CL is a function of dose such as CL=12*(dose/300)^0.42. The dose can change in different treatment period such as: Times = list(t1 = seq(0, 12, by = 0.1), t2 = seq(12, 24, by = 0.1)),

mattfidler commented 1 year ago
library(rxode2)
#> rxode2 2.0.13.9000 using 8 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`

f <- function() {
  model({
    d/dt(x1) = -param1 * x1
    d/dt(x2) = param1 * x1 - param2 * x2
    x1(0) <- 10
    x2(0) <- 20
  })
}

e <- et(0, 12, by = 0.1) %>%
  as.data.frame()

e$param1 <- ifelse(e$time < 6, 0.5, 10)
e$param2 <- ifelse(e$time < 6, 0.5, 20)

out <- rxSolve(f, e)
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’

plot(out, log="y")
#> Warning in self$trans$transform(x): NaNs produced
#> Warning: Transformation introduced infinite values in continuous y-axis
#> Warning: Removed 38 rows containing missing values (`geom_line()`).

Created on 2023-08-16 with reprex v2.0.2

mattfidler commented 1 year ago

Like nonmem it is in the dataset.

sliao999 commented 1 year ago

I got it, thanks.

Sam

sliao999 commented 1 year ago

It works! Thanks a lot.

Sam

sliao999 commented 1 year ago

I was able to make the change in CL and V1 as time-dependent covariate in rxode. However, I found the bump in simulated PK profiles that seem to be corresponding to the change in CL and V1. Did anyone have this issue too? Any way to resolve this?

Sam

Doc1.docx

mattfidler commented 1 year ago

Hi @sliao999

This should be expected.

That being said, you can try different covariate interpolation methods, ie

sliao999 commented 1 year ago

Thanks a lot for your quick reply.

I tried "nocb" and "locf", and it still has this bump when CL changed.

mattfidler commented 1 year ago

The bump is likely when the time-varying covariate changes, and is likely expected. You could try linear.

sliao999 commented 1 year ago

Hi, For the same simulation, I got somewhat different results between NONMEM and rxode2. Is this expected? In NONMEM, I used ADVAN14 TOL=12 ATOL=12 to solve the PK model with Weibull-type input. Is there a similar method in rxode2?

Sam

mattfidler commented 1 year ago

ADVAN14 is a different solver (CVODES), so yes you should expect different outputs. rxode2 does not implement CVODEs at the present time

sliao999 commented 1 year ago

Thanks a lot for your quick reply. To match the results of rxode2, which NONMEM method can I used? ADVAN13 or ADVAN8?

Sam