nlmixr2 / nlmixr2est

nlmixr2 estimation routines
https://nlmixr2.github.io/nlmixr2est/
GNU General Public License v2.0
7 stars 3 forks source link

Test for compressed ui not really working #422

Open mattfidler opened 8 months ago

mattfidler commented 8 months ago

This seems to be an edge case; It doesn't follow a simple pattern

See

https://github.com/nlmixr2/rxode2/issues/661

But this still reproduces the error:

library(nlmixr2)
#> Loading required package: nlmixr2data
library(xpose)
#> Error in library(xpose): there is no package called 'xpose'
library(xpose.nlmixr2)
#> Error in library(xpose.nlmixr2): there is no package called 'xpose.nlmixr2'
library(ggplot2)

nimo <- function() {
ini({
    ## Note that the UI can take expressions
    ## Also note that these initial estimates should be provided on the log-scale
    tcl <- log(0.001)
    tv1 <- log(1.45)
    tQ <- log(0.004)
    tv2 <- log(44)
    tkss <- log(12)
    tkint <- log(0.3)
    tksyn <- log(1)
    tkdeg <- log(7)
    ## Initial estimates should be high for SAEM ETAs
    eta.cl  ~ 2
    eta.v1  ~ 2
    eta.kss ~ 2
    ##  Also true for additive error (also ignored in SAEM)
    add.err <- 10
    })
model({
      cl <- exp(tcl + eta.cl)
      v1 <- exp(tv1 + eta.v1)
      Q  <- exp(tQ)
      v2 <- exp(tv2)
      kss <- exp(tkss + eta.kss)
      kint <- exp(tkint)
      ksyn <- exp(tksyn)
      kdeg <- exp(tkdeg)

      k <- cl/v1
      k12 <- Q/v1
      k21 <- Q/v2

      eff(0) <- ksyn/kdeg ##initializing compartment

      ## Concentration is calculated
      conc = 0.5*(central/v1-eff-kss)+0.5*sqrt((central/v1-eff-kss)**2+4*kss*central/v1)

      d/dt(central)  = -(k+k12)*conc*v1+k21*peripheral-kint*eff*conc*v1/(kss+conc)
      d/dt(peripheral) = k12*conc*v1-k21*peripheral  ##Free Drug second compartment amount
      d/dt(eff) = ksyn - kdeg*eff - (kint-kdeg)*conc*eff/(kss+conc)

      IPRED=log(conc)

      IPRED ~ add(add.err)
      })
}

fit <- nlmixr(nimo, nimoData, est="saem", control=saemControl(print=0))
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> rxode2 2.1.2 using 8 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
#> Calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem predOnly model 0...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → finding duplicate expressions in saem predOnly model 1...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem predOnly model 1...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → finding duplicate expressions in saem predOnly model 2...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem predOnly model 2...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> → Calculating residuals/tables
#> ✔ done
#> → compress origData in nlmixr2 object, save 26920
#> → compress phiM in nlmixr2 object, save 207080
#> → compress parHistData in nlmixr2 object, save 19928
#> → compress saem0 in nlmixr2 object, save 14176
nimo_sim <- rxSolve(fit, nimoData)
#> Error in exists("meta", envir = ui): invalid 'envir' argument

Created on 2024-03-07 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.3 (2024-02-29) #> os Pop!_OS 22.04 LTS #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2024-03-07 #> pandoc 2.9.2.1 @ /usr/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> backports 1.4.1 2021-12-13 [3] RSPM (R 4.2.0) #> cachem 1.0.8 2023-05-01 [3] RSPM (R 4.2.0) #> checkmate 2.3.1 2023-12-04 [3] RSPM (R 4.3.0) #> cli 3.6.2 2023-12-11 [3] RSPM (R 4.3.0) #> colorspace 2.1-0 2023-01-23 [3] RSPM (R 4.2.0) #> crayon 1.5.2 2022-09-29 [3] RSPM (R 4.2.0) #> data.table 1.15.2 2024-02-29 [3] RSPM (R 4.3.0) #> digest 0.6.34 2024-01-11 [3] RSPM (R 4.3.0) #> dparser 1.3.1-11 2023-12-08 [3] RSPM (R 4.3.0) #> dplyr 1.1.4 2023-11-17 [3] RSPM (R 4.3.0) #> evaluate 0.23 2023-11-01 [3] RSPM (R 4.3.0) #> fansi 1.0.6 2023-12-08 [3] RSPM (R 4.3.0) #> fastmap 1.1.1 2023-02-24 [3] RSPM (R 4.2.0) #> fs 1.6.3 2023-07-20 [3] RSPM (R 4.2.0) #> generics 0.1.3 2022-07-05 [3] RSPM (R 4.2.0) #> ggplot2 * 3.5.0 2024-02-23 [3] RSPM (R 4.3.0) #> glue 1.7.0 2024-01-09 [3] RSPM (R 4.3.0) #> gtable 0.3.4 2023-08-21 [3] RSPM (R 4.2.0) #> htmltools 0.5.7 2023-11-03 [3] RSPM (R 4.3.0) #> knitr 1.45 2023-10-30 [3] RSPM (R 4.3.0) #> lattice 0.22-5 2023-10-24 [3] RSPM (R 4.3.0) #> lazyeval 0.2.2 2019-03-15 [3] RSPM (R 4.2.0) #> lbfgsb3c 2020-3.3 2023-11-28 [3] RSPM (R 4.3.0) #> lifecycle 1.0.4 2023-11-07 [3] RSPM (R 4.3.0) #> lotri 0.4.3 2023-03-20 [3] RSPM (R 4.2.0) #> magrittr 2.0.3 2022-03-30 [3] RSPM (R 4.2.0) #> Matrix 1.6-5 2024-01-11 [3] RSPM (R 4.3.0) #> memoise 2.0.1 2021-11-26 [3] RSPM (R 4.2.0) #> munsell 0.5.0 2018-06-12 [3] RSPM (R 4.2.0) #> n1qn1 6.0.1-11 2022-10-18 [3] RSPM (R 4.2.0) #> nlme 3.1-164 2023-11-27 [3] RSPM (R 4.3.0) #> nlmixr2 * 2.1.1 2024-02-01 [3] RSPM (R 4.3.0) #> nlmixr2data * 2.0.9 2024-01-31 [3] RSPM (R 4.3.0) #> nlmixr2est 2.2.1 2024-01-31 [3] RSPM (R 4.3.0) #> nlmixr2plot 2.0.8 2024-01-31 [3] RSPM (R 4.3.0) #> pillar 1.9.0 2023-03-22 [3] RSPM (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [3] RSPM (R 4.2.0) #> PreciseSums 0.6 2023-04-22 [3] RSPM (R 4.2.0) #> purrr 1.0.2 2023-08-10 [3] RSPM (R 4.2.0) #> qs 0.25.7 2023-12-06 [3] RSPM (R 4.3.0) #> R.cache 0.16.0 2022-07-21 [3] RSPM (R 4.2.0) #> R.methodsS3 1.8.2 2022-06-13 [3] RSPM (R 4.2.0) #> R.oo 1.26.0 2024-01-24 [3] RSPM (R 4.3.0) #> R.utils 2.12.3 2023-11-18 [3] RSPM (R 4.3.0) #> R6 2.5.1 2021-08-19 [3] RSPM (R 4.2.0) #> RApiSerialize 0.1.2 2022-08-25 [3] RSPM (R 4.2.0) #> Rcpp 1.0.12 2024-01-09 [3] RSPM (R 4.3.0) #> RcppParallel 5.1.7 2023-02-27 [3] RSPM (R 4.2.0) #> reprex 2.1.0 2024-01-11 [3] RSPM (R 4.3.0) #> rex 1.2.1 2021-11-26 [3] RSPM (R 4.2.0) #> rlang 1.1.3 2024-01-10 [3] RSPM (R 4.3.0) #> rmarkdown 2.26 2024-03-05 [3] RSPM (R 4.3.0) #> rxode2 * 2.1.2 2024-01-30 [3] RSPM (R 4.3.0) #> rxode2et 2.0.12 2024-01-30 [3] RSPM (R 4.3.0) #> rxode2ll 2.0.11 2023-03-17 [3] RSPM (R 4.2.0) #> rxode2parse 2.0.18 2024-01-30 [3] RSPM (R 4.3.0) #> rxode2random 2.0.13 2024-01-30 [3] RSPM (R 4.3.0) #> scales 1.3.0 2023-11-28 [3] RSPM (R 4.3.0) #> sessioninfo 1.2.2 2021-12-06 [3] RSPM (R 4.2.0) #> stringfish 0.16.0 2023-11-28 [3] RSPM (R 4.3.0) #> styler 1.10.2 2023-08-29 [3] RSPM (R 4.2.0) #> symengine 0.2.6 2024-02-25 [3] RSPM (R 4.3.0) #> sys 3.4.2 2023-05-23 [3] RSPM (R 4.2.0) #> tibble 3.2.1 2023-03-20 [3] RSPM (R 4.3.0) #> tidyselect 1.2.0 2022-10-10 [3] RSPM (R 4.2.0) #> units 0.8-5 2023-11-28 [3] RSPM (R 4.3.0) #> utf8 1.2.4 2023-10-22 [3] RSPM (R 4.3.0) #> vctrs 0.6.5 2023-12-01 [3] RSPM (R 4.3.0) #> withr 3.0.0 2024-01-16 [3] RSPM (R 4.3.2) #> xfun 0.42 2024-02-08 [3] RSPM (R 4.3.0) #> yaml 2.3.8 2023-12-11 [3] RSPM (R 4.3.0) #> #> [1] /home/matt/R/x86_64-pc-linux-gnu-library/4.3 #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```

Originally posted by @mattfidler in https://github.com/nlmixr2/nlmixr2/discussions/208#discussioncomment-8712266