Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running a model changes the source object #199

Closed
billdenney opened this issue Aug 31, 2022 · 1 comment · Fixed by #204
Closed

Running a model changes the source object #199

billdenney opened this issue Aug 31, 2022 · 1 comment · Fixed by #204
Assignees

Comments

@billdenney
Copy link
Contributor

I'm iteratively working within a similar set of models making some minor modifications and trying to improve the model fits. With that, I am sometimes running a model multiple times.

The issue that I have is that the object that I'm passing to nlmixr2 to try to estimate the model changes when I try to rerun it. More specifically, I would have assumed that the pheno_prep$iniDf would be unchanged before vs. after the fit while the fit object would have the new $iniDf:

library(nlmixr2)
#> Loading required package: nlmixr2data
library(tidyverse)
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
    add.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 ~ add(add.err)       # define error model
  })
}

pheno_prep <-
  # make an nlmixr2est object
  nlmixr(pheno)
#> ℹ parameter labels from comments will be replaced by 'label()'
pheno_prep$iniDf
#>   ntheta neta1 neta2           name lower        est upper   fix
#> 1      1    NA    NA            tcl  -Inf -4.8283137   Inf FALSE
#> 2      2    NA    NA             tv  -Inf -0.5108256   Inf FALSE
#> 3      3    NA    NA        add.err     0  0.1000000   Inf FALSE
#> 4     NA     1     1         eta.cl  -Inf  1.0000000   Inf FALSE
#> 5     NA     2     1 (eta.cl,eta.v)  -Inf  0.0100000   Inf FALSE
#> 6     NA     2     2          eta.v  -Inf  1.0000000   Inf FALSE
#>                        label backTransform condition  err
#> 1 typical value of clearance          <NA>      <NA> <NA>
#> 2    typical value of volume          <NA>      <NA> <NA>
#> 3       residual variability          <NA>        cp  add
#> 4                       <NA>          <NA>        id <NA>
#> 5                       <NA>          <NA>        id <NA>
#> 6                       <NA>          <NA>        id <NA>
fit <- nlmixr(pheno_prep, pheno_sd, "focei", control=list(print=0))
#> rxode2 2.0.7 using 8 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
#> calculating covariance matrix
#> done
#> → Calculating residuals/tables
#> ✔ done
#> → compress origData in nlmixr2 object, save 33192
#> → compress parHist in nlmixr2 object, save 2960
#> Warning: gradient problems with initial estimate and covariance; see $scaleInfo
#> Warning: last objective function was not at minimum, possible problems in
#> optimization
#> Warning: ETAs were reset to zero during optimization; (Can control by
#> foceiControl(resetEtaP=.))
#> Warning: initial ETAs were nudged; (can control by foceiControl(etaNudge=.,
#> etaNudge2=))
pheno_prep$iniDf
#>   ntheta neta1 neta2           name lower        est upper   fix
#> 1      1    NA    NA            tcl  -Inf -5.0001418   Inf FALSE
#> 2      2    NA    NA             tv  -Inf  0.3341971   Inf FALSE
#> 3      3    NA    NA        add.err     0  2.8356874   Inf FALSE
#> 4     NA     1     1         eta.cl  -Inf  0.2529083   Inf FALSE
#> 5     NA     2     1 (eta.cl,eta.v)  -Inf  0.1942066   Inf FALSE
#> 6     NA     2     2          eta.v  -Inf  0.1552687   Inf FALSE
#>                        label backTransform condition  err
#> 1 typical value of clearance          <NA>      <NA> <NA>
#> 2    typical value of volume          <NA>      <NA> <NA>
#> 3       residual variability          <NA>        cp  add
#> 4                       <NA>          <NA>        id <NA>
#> 5                       <NA>          <NA>        id <NA>
#> 6                       <NA>          <NA>        id <NA>

Created on 2022-08-31 by the reprex package (v2.0.1)

@mattfidler
Copy link
Contributor

This probably needs the ui object to be cloned.

@mattfidler mattfidler self-assigned this Sep 1, 2022
@mattfidler mattfidler linked a pull request Sep 1, 2022 that will close this issue
mattfidler added a commit that referenced this issue Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants