nlmixrdevelopment / nlmixr

nlmixr: an R package for population PKPD modeling
https://nlmixrdevelopment.github.io/nlmixr/
GNU General Public License v2.0
114 stars 45 forks source link

Reproducing problem- the example for delayed absorption #200 #577

Closed Lee21A closed 2 years ago

Lee21A commented 2 years ago

Dear @mattfidler Thanks for your package.

I tried to test the model, including Tlag and linCmt, listed in #200.

When I tested the example code (same as #200, Code 1), I met the error message below. (Error message 1)

According to the error message 1, I added the option into code (options(RxODE.syntax.require.ode.first = FALSE)) (Code 2). Then it looks like working until “> compiling EBE model...”, but failed after all. (Error message 2)

I used nlmixr version = 2.0.6 R version = 4.1.2 RStudio = 2021.09.01

The code and error messages can be found below.

Thanks in advance. YJ

Error message 1

RxODE  model syntax error:
================================================================================
:ERR: ODEs compartment 'd/dt(depot)' must be defined before changing/accessing its properties (f/alag/rate/dur/tad/tafd)
If you want to change this set 'options(RxODE.syntax.require.ode.first = FALSE).
Be warned this may number compartments based on first occurance of property or ODE:

:001:    ka <- exp(tka + eta.ka)
:002:     cl <- exp(tcl + eta.cl)
:003:     v <- exp(tv + eta.v)
:004:     lag(depot) <- exp(lagDepot + eta.lag)
:005:     nlmixr_pred <- nlmixr_lincmt_pred
:006: 
================================================================================
Error in rxModelVars_(obj) : Evaluation error: syntax errors (see above).

Error message 2

> compiling EBE model...
… 
…
Error : error building model
Error in .fitFun(.ret) : theta mismatch op_focei.ntheta 0, ntheta: 5

Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL,  : 
  Could not fit data.
Warning message:
In (function (uif, data, est = NULL, control = list(), ..., sum.prod = FALSE,  :
  Error calculating nlmixr object, return classic object
> print (fit)
THETA:
             th    log(th) se(log_th)
[1,] 0.08166747 -2.5050995 0.05772807
[2,] 0.03903146 -3.2433874 0.06642690
[3,] 0.01492448 -4.2047522 0.28857340
[4,] 2.29852176  0.8322662 2.59073696

OMEGA:
          [,1]       [,2]      [,3]     [,4]
[1,] 0.0126626 0.00000000 0.0000000 0.000000
[2,] 0.0000000 0.04382315 0.0000000 0.000000
[3,] 0.0000000 0.00000000 0.7708046 0.000000
[4,] 0.0000000 0.00000000 0.0000000 9.905189

ARES & BRES:
          [,1]
[1,] 0.2323477
>

Code 1

library(nlmixr)
theo_sd = readRDS("theo_sd.rds")
one.cmt <- function() {
  ini({
    tka <- 0.45 # Log Ka
    tcl <- 1 # Log Cl
    tv <- 3.45    # Log V
    lagDepot <- -3
    eta.ka ~ 0.6
    eta.cl ~ 0.3
    eta.v ~ 0.1
    eta.lag ~ 0.01
    add.err <- 0.7
  })
  model({
    ka <- exp(tka + eta.ka)
    cl <- exp(tcl + eta.cl)
    v <- exp(tv + eta.v)
    lag(depot) <- exp(lagDepot + eta.lag)
    linCmt() ~ add(add.err)
  })
}

fit <- nlmixr(one.cmt, theo_sd, est="saem", control=list(print=0))
print (fit)

Code 2

library(nlmixr)
theo_sd = readRDS("theo_sd.rds")
options(RxODE.syntax.require.ode.first = FALSE)
one.cmt <- function() {
  ini({
    tka <- 0.45 # Log Ka
    tcl <- 1 # Log Cl
    tv <- 3.45    # Log V
    lagDepot <- -3
    eta.ka ~ 0.6
    eta.cl ~ 0.3
    eta.v ~ 0.1
    eta.lag ~ 0.01
    add.err <- 0.7
  })
  model({
    ka <- exp(tka + eta.ka)
    cl <- exp(tcl + eta.cl)
    v <- exp(tv + eta.v)
    lag(depot) <- exp(lagDepot + eta.lag)
    linCmt() ~ add(add.err)
  })
}

fit <- nlmixr(one.cmt, theo_sd, est="saem", control=list(print=0))
print (fit)
mattfidler commented 2 years ago

Hi @Lee21A,

Thank you for reporting this issue.

The linCmt() family of models are the most complex parsing cases in the current nlmixr. In short it separates the model into 3 components: error model, parameter model, and main model block similar to how NONMEM handles the models.

This linCmt() piece is failing.

I am working toward moving these model functions to rxode2 where the separation should not happen at all.

In the mean time, you could use the slower ODEs to have a similar model.

Lee21A commented 2 years ago

Thanks @mattfidler

I understood. I will wait for the rxode2 version with pleasure.

YJ.

mattfidler commented 2 years ago

Great. rxode2 and nlmixr2 will both be released at the same time. This will have end to end simulation and estimation using the same model code.