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

Make sure the UI is uncompressed before checking for meta information #661

Closed
mattfidler opened this issue Mar 7, 2024 · 1 comment · Fixed by #662
Closed

Make sure the UI is uncompressed before checking for meta information #661

mattfidler opened this issue Mar 7, 2024 · 1 comment · Fixed by #662

Comments

@mattfidler
Copy link
Contributor

Note I got the following:

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
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 nlmixr2/nlmixr2#208 (reply in thread)

@mattfidler
Copy link
Contributor Author

It seems that this is some sort of edge case because this works:

library(rxode2)
#> rxode2 2.1.2 using 8 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`

nimo <- function() {
  ini({
    tcl <- -6.20447388279654
    tv1 <- 0.191575008970249
    tQ <- -5.87988849322313
    tv2 <- 1.20088373795058
    tkss <- 2.05936091989241
    tkint <- -1.57948966650851
    tksyn <- 0.830859686356613
    tkdeg <- 2.38731427957655
    add.err <- c(0, 0.686603620607056)
    eta.cl ~ 0.91005447260584
    eta.v1 ~ 0.173555359121338
    eta.kss ~ 0.0114928866324284
  })
  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
    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
    d/dt(eff) = ksyn - kdeg * eff - (kint - kdeg) * conc * 
      eff/(kss + conc)
    IPRED = log(conc)
    IPRED ~ add(add.err)
  })
}

nimo <- nimo()

# should have raw in it because it is compressed not really an environment
print(class(nimo))
#> [1] "rxUi" "raw"

nimo_sim <- rxSolve(nimo, nlmixr2data::nimoData)

print(nimo_sim)
#> ── Solved rxode2 object ──
#> ── Parameters ($params): ──
#> # A tibble: 12 × 13
#>    id      tcl   tv1    tQ   tv2  tkss tkint tksyn tkdeg add.err   eta.cl eta.v1
#>    <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl>  <dbl>
#>  1 1     -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687 -0.975    0.166
#>  2 2     -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687 -1.32     0.318
#>  3 3     -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687  0.955   -0.448
#>  4 5     -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687  0.0768  -0.127
#>  5 6     -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687  0.00911  0.223
#>  6 7     -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687  0.799   -0.135
#>  7 8     -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687 -1.00    -0.168
#>  8 9     -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687  0.256   -0.453
#>  9 10    -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687 -0.160   -0.375
#> 10 11    -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687 -0.300   -0.396
#> 11 12    -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687 -0.364   -0.511
#> 12 13    -6.20 0.192 -5.88  1.20  2.06 -1.58 0.831  2.39   0.687  0.339    0.352
#> # ℹ 1 more variable: eta.kss <dbl>
#> ── Initial Conditions ($inits): ──
#>    central peripheral        eff 
#>          0          0          0 
#> ── First part of data (object): ──
#> # A tibble: 321 × 20
#>      id   time       cl    v1       Q    v2   kss  kint  ksyn  kdeg        k
#>   <int>  <dbl>    <dbl> <dbl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>    <dbl>
#> 1     1   1.28 0.000762  1.43 0.00280  3.32  9.50 0.206  2.30  10.9 0.000533
#> 2     1  23.2  0.000762  1.43 0.00280  3.32  9.50 0.206  2.30  10.9 0.000533
#> 3     1  46.9  0.000762  1.43 0.00280  3.32  9.50 0.206  2.30  10.9 0.000533
#> 4     1  95.2  0.000762  1.43 0.00280  3.32  9.50 0.206  2.30  10.9 0.000533
#> 5     1 144.   0.000762  1.43 0.00280  3.32  9.50 0.206  2.30  10.9 0.000533
#> 6     1 167.   0.000762  1.43 0.00280  3.32  9.50 0.206  2.30  10.9 0.000533
#> # ℹ 315 more rows
#> # ℹ 9 more variables: k12 <dbl>, k21 <dbl>, conc <dbl>, IPRED <dbl>,
#> #   ipredSim <dbl>, sim <dbl>, central <dbl>, peripheral <dbl>, eff <dbl>

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

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.

1 participant