nlmixrdevelopment / nlmixr

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

Error in nlmixrUIModel(.model, ini, fun) : Mixed PK/ODEs #137

Closed EvanTarbell closed 5 years ago

EvanTarbell commented 5 years ago

I have a very complex, 64 compartment model that i am trying to fit. I tried getting the model into nlmixr format and tried checking it with nlmixr(model) and received the following error:

> nlmixr(pbpk)
Error in nlmixrUIModel(.model, ini, fun) : Mixed PK/ODEs
Error in nlmixrUI(object) : Error parsing model.

Reading through the code, it seems like the error is being thrown from this line in ui.R:

if (any(regexpr(rex::rex(or("d/dt(", group("(0)", any_spaces, or("=", "~")))), rx.txt[1:w]) != -1)){
            ## mixed PK parameters and ODEs
            stop("Mixed PK/ODEs")

This seems to be checking a subset of the model code for the regular expression: (?:d/dt\(|(?:\(0\)[[:space:]]*(?:=|~))) and if it finds any matches, then it throws the error (if im understanding the code).

It seems to imply that if the parameter assignments/declarations etc are with the ODE equations, then the error is thrown, but the parameters are listed first, followed by the ODE, followed by the concentration formulas, according to the nlmixr documentation. Im clearly formatting the model incorrectly but im not sure where or how. Any help is greatly appreciated. Thanks

mattfidler commented 5 years ago

nlmixr separates out a $PRED type record and an $ODE type record. The $PRED record contains the parameters defined in the initial estimates block ini. The $ODE record contains the differential equations. If some parameters in the ini block are in the $ODE block then this error is thrown.

I think I have a solution to fix this, that is allow $ODE to have estimates from the ini block directly listed, but I haven't implemented it yet.

mattfidler commented 5 years ago

I think I have fixed this in the github version.

If you want to try, I think you can update by the following:

.libPaths(.libPaths()[!grepl("Users",.libPaths()]) # I think this will take out the c:\Users\ libPath
.libPaths() # Check to make sure the Users path  isn't there

devtools::install_github("nlmixrdevelopment/RxODE")
devtools::install_gitbhub("nlmixrdevelopment/nlmixr")
EvanTarbell commented 5 years ago

thanks for that. i actually just renamed my parameters and was able to solve this issue. I will try this new version soon. thanks

mattfidler commented 5 years ago

You may wish to wait for the next CRAN release. We are moving toward that very soon.

EvanTarbell commented 5 years ago

Thanks, that sounds like a plan. And thanks for all your help!!