nlmixr2 / rxode2parse

1 stars 0 forks source link

Cannot have text comparison as part of bioavailability with `linCmt()` #14

Closed billdenney closed 1 year ago

billdenney commented 1 year ago

In the example below, numeric comparisons work with the definition of f(), but text comparisons do not:

library(nlmixr2)
#> Warning: package 'nlmixr2' was built under R version 4.2.2
#> Loading required package: nlmixr2data

one.compartment <- function() {
  ini({
    tka <- 0.45
    tcl <- 1
    tv <- 3.45
    eta.ka ~ 0.6
    eta.cl ~ 0.3
    eta.v ~ 0.1
    add.sd <- 0.7
  })
  model({
    ka <- exp(tka + eta.ka)
    cl <- exp(tcl + eta.cl)
    v <- exp(tv + eta.v)
    cp <- linCmt()
    cp ~ add(add.sd)
  })
}

ui <- nlmixr2(one.compartment)
ui %>%
  model(
    f(central) <- 1 + f_study1*(STUDYID == 1),
    append = NA
  )
#> ℹ add residual parameter `f_study1` and set estimate to 1
#> ℹ add residual parameter `STUDYID` and set estimate to 1
#>  ── rxode2-based solved PK 1-compartment model with first-order absorption ────── 
#>  ── Initalization: ──  
#> Fixed Effects ($theta): 
#>      tka      tcl       tv   add.sd f_study1  STUDYID 
#>     0.45     1.00     3.45     0.70     1.00     1.00 
#> 
#> Omega ($omega): 
#>        eta.ka eta.cl eta.v
#> eta.ka    0.6    0.0   0.0
#> eta.cl    0.0    0.3   0.0
#> eta.v     0.0    0.0   0.1
#>  ── μ-referencing ($muRefTable): ──  
#>   theta    eta level
#> 1   tka eta.ka    id
#> 2   tcl eta.cl    id
#> 3    tv  eta.v    id
#> 
#>  ── Model (Normalized Syntax): ── 
#> function() {
#>     ini({
#>         tka <- 0.45
#>         tcl <- 1
#>         tv <- 3.45
#>         add.sd <- c(0, 0.7)
#>         f_study1 <- 1
#>         STUDYID <- 1
#>         eta.ka ~ 0.6
#>         eta.cl ~ 0.3
#>         eta.v ~ 0.1
#>     })
#>     model({
#>         f(central) <- 1 + f_study1 * (STUDYID == 1)
#>         ka <- exp(tka + eta.ka)
#>         cl <- exp(tcl + eta.cl)
#>         v <- exp(tv + eta.v)
#>         cp <- linCmt()
#>         cp ~ add(add.sd)
#>     })
#> }
ui %>%
  model(
    f(central) <- 1 + f_study1*(STUDYID == "Study 1"),
    append = NA
  )
#> ℹ add residual parameter `f_study1` and set estimate to 1
#> ℹ add residual parameter `STUDYID` and set estimate to 1
#> rxode2 model syntax error:
#> ================================================================================
#> :001: ka=exp(tka+eta.ka);
#> :002: cl=exp(tcl+eta.cl);
#> :003: v=exp(tv+eta.v);
#> 
#> rxode2 syntax error:
#> :004: cp=linCmtA(rx__PTR__, t, 0, 1, 1, cl, v, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, ka, 0.0, 1+f_study1*(_cmp2(STUDYID, "STUDYID", 1, "Study 1")), 0.0, 0.0);
#>                                                                                                             ^
#> :004: 
#> ================================================================================
#> Error in rxModelVars_(obj): Evaluation error: Evaluation error: rxode2 syntax error:
#> :004: cp=linCmtA(rx__PTR__, t, 0, 1, 1, cl, v, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, ka, 0.0, 1+f_study1*(_cmp2(STUDYID, "STUDYID", 1, "Study 1")), 0.0, 0.0);
#>                                                                                                             ^
#> more errors could be listed above..

Created on 2022-12-12 with reprex v2.0.2

mattfidler commented 1 year ago
> rxode2parse::rxode2parse('cp=linCmtA(rx__PTR__, t, 0, 1, 1, cl, v, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, ka, 0.0, 1+f_study1*(_cmp2(STUDYID, "STUDYID", 1, "Study 1")), 0.0, 0.0);')
rxode2 model syntax error:
================================================================================

rxode2 syntax error after 'Â:':
:001: cp=linCmtA(rx__PTR__, t, 0, 1, 1, cl, v, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, ka, 0.0, 1+f_study1*(_cmp2(STUDYID, "STUDYID", 1, "Study 1")), 0.0, 0.0);
                                                                                                            ^
================================================================================
Error: rxode2 syntax error after 'Â:':
:001: cp=linCmtA(rx__PTR__, t, 0, 1, 1, cl, v, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, ka, 0.0, 1+f_study1*(_cmp2(STUDYID, "STUDYID", 1, "Study 1")), 0.0, 0.0); 
mattfidler commented 1 year ago

Normalized model is OK:

> message(rxode2parse('c <- f_study1*(STUDYID == "Study 1")')$model)
c=f_study1*(STUDYID=="Study 1");