nlmixr2 / nlmixr2extra

Extra utilities for nlmixr objects
https://nlmixr2.github.io/nlmixr2extra/
GNU General Public License v3.0
3 stars 1 forks source link

Covariate search issue, it seems for backward search it has to look for "fit" object #51

Open snailittle opened 1 year ago

snailittle commented 1 year ago

### Noticed the following error with the example model:

library(nlmixr2) library(rxode2) library(vpc) library(xpose) library(xpose.nlmixr2) library(ggplot2)

pheno <- function() { ini({ tcl <- log(0.008) # typical value of clearance tv <- log(0.6) # typical value of volume

var(eta.cl)

eta.cl + eta.v ~ c(1, 
                   0.01, 1) ## cov(eta.cl, eta.v), var(eta.v)
# interindividual variability on clearance and volume
prop.err <- 0.1    # residual variability

}) model({ cl <- exp(tcl + eta.cl) # individual value of clearance v <- exp(tv + eta.v) # individual value of volume ke <- cl / v # elimination rate constant d/dt(A1) = - ke * A1 # model differential equation cp = A1 / v # concentration in plasma cp ~ prop(prop.err) # define error model }) }

fit_saem <- nlmixr(pheno, pheno_sd, "saem", control=list(print=0), table=list(cwres=TRUE, npde=TRUE))

rxode2::.rxWithWd(tempdir(), {# with temporary directory

auto3 <- covarSearchAuto(fit_saem, varsVec = c("v", "cl"), covarsVec = c("WT"), catvarsVec = c("APGR"), restart = TRUE, searchType = "backward", pVal=list(fwd=0.01,bck=0.001)) }) Error in inherits(fit, "nlmixr2FitCore") : object 'fit' not found

_However When I rename fit_saem to fit it seems to bypass this error. Is it a possible bug? This however ran into another error of "matrix multiplication: problem with matrix inverse;" So it seems whenever a model failed (probably due to over parameterization, an inherent process with most of covariate search models), the covariate search can not go on? _

fit=fit_saem rxode2::.rxWithWd(tempdir(), {# with temporary directory

auto3 <- covarSearchAuto(fit, varsVec = c("v", "cl"), covarsVec = c("WT"), catvarsVec = c("APGR"), restart = TRUE, searchType = "backward", pVal=list(fwd=0.01,bck=0.001)) })

── starting backward search... ──────────────────────────────────────── ℹ use control from pipeline → loading into symengine environment... → pruning branches (if/else) of saem model... ✔ done → finding duplicate expressions in saem model... [====|====|====|====|====|====|====|====|====|====] 0:00:00

✔ done Error in .model$saem_mod(.cfg) : matrix multiplication: problem with matrix inverse; suggest to use solve() instead Error: matrix multiplication: problem with matrix inverse; suggest to use solve() instead

mattfidler commented 1 year ago

Looks like a couple of issues here.

I will transfer the large one to nlmixr2extra where the covariate search is found.

mattfidler commented 1 year ago

Thanks for the issue, I will look at it when I get a moment.