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

PD model error: Error in if (.retl > 5) #651

Open fbroccatelli opened 6 days ago

fbroccatelli commented 6 days ago

Thanks for the awesome package and support. I am trying a simple PD model based on internal data, and I finding an error, which I am able to reproduce with the warfarin dataset.

Model below, as well as error:

######

pk_iv_2_PD <- function() {
  ini({
    tke <- log((20))
    tk12 <- log((1))
    tk21 <- log((2))
    tvc <- log((0.1))
    tkdeg <- log(0.1)
    tkinact <- log(1)
    prop.err <- (0.1)
    add.err <- 1
    proppd.err <- (0.1)
    addpd.err <- 1

  })
  model({
    ke <- exp(tke)
    k12 <- exp(tk12)
    k21 <- exp(tk21)
    vc <- exp(tvc)
    kdeg <- exp(tkdeg)
    kinact <- exp(tkinact)

    periphereal(0)<-0
    pd(0)<-100

    d/dt(central)  = -central*ke - central * k12 + periphereal * k21
    d/dt(periphereal)  =  central * k12 - periphereal * k21
    d/dt(pca)  =  100*kdeg - kdeg * pca - kinact * central * pca

    cp =  central / vc   
    cp ~ prop(prop.err) + add(add.err)
    pca ~ prop(proppd.err) + add(addpd.err) 
  })
}

fit <- nlmixr2(pk_iv_2_PD, warfarin,  "focei",control=foceiControl(print=100000, outerOpt="bobyqa"))

########error:

→ loading into symengine environment... → pruning branches (if/else) of full model... ✔ done Error in if (.retl > 5) { : the condition has length > 1 Error: the condition has length > 1

mattfidler commented 4 days ago

Hi @fbroccatelli

I cannot reproduce your error. For me, the model runs successfully:

library(nlmixr2est)
#> Warning: package 'nlmixr2est' was built under R version 4.3.3
#> Loading required package: nlmixr2data
#> Warning: package 'nlmixr2data' was built under R version 4.3.3

pk_iv_2_PD <- function() {
  ini({
    tke <- log((20))
    tk12 <- log((1))
    tk21 <- log((2))
    tvc <- log((0.1))
    tkdeg <- log(0.1)
    tkinact <- log(1)
    prop.err <- (0.1)
    add.err <- 1
    proppd.err <- (0.1)
    addpd.err <- 1

  })
  model({
    ke <- exp(tke)
    k12 <- exp(tk12)
    k21 <- exp(tk21)
    vc <- exp(tvc)
    kdeg <- exp(tkdeg)
    kinact <- exp(tkinact)

    periphereal(0)<-0
    pd(0)<-100

    d/dt(central)  = -central*ke - central * k12 + periphereal * k21
    d/dt(periphereal)  =  central * k12 - periphereal * k21
    d/dt(pca)  =  100*kdeg - kdeg * pca - kinact * central * pca

    cp =  central / vc   
    cp ~ prop(prop.err) + add(add.err)
    pca ~ prop(proppd.err) + add(addpd.err) 
  })
}

fit <- nlmixr2(pk_iv_2_PD, nlmixr2data::warfarin,  "focei",control=foceiControl(print=0, outerOpt="bobyqa"))
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of full model...
#> ✔ done
#> → finding duplicate expressions in EBE model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in EBE model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → compiling EBE model...
#> using C compiler: 'gcc.exe (GCC) 12.3.0'
#> ✔ done
#> rxode2 2.1.3 using 4 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done
#> → Calculating residuals/tables
#> ✔ done
#> → compress origData in nlmixr2 object, save 27560
#> → compress parHistData in nlmixr2 object, save 84704

Created on 2024-06-29 with reprex v2.1.0

Can you provide a backtrace with traceback(). You can also see if your nlmixr2 is outdated by running the nlmixr2CheckInstall() function.