nlmixrdevelopment / nlmixr

nlmixr: an R package for population PKPD modeling
https://nlmixrdevelopment.github.io/nlmixr/
GNU General Public License v2.0
114 stars 45 forks source link

linCmt() Detection Issue? #537

Closed billdenney closed 3 years ago

billdenney commented 3 years ago

I just tried to make a 2-compartment linear compartmental model using linCmt(), but when I looked at the summary output, it said that it was a 1-compartment model. Am I doing something wrong or is there a typo in the printout for the model?

The specific line below is "RxODE-based 1-compartment model with first-order absorption" which I thought should say "2-compartment" instead of "1-compartment".

library(nlmixr)
twocmt <- function() {
  ini({
    lKA <- 0.1      ; label("Ka (1/hr)")
    lCl <- 1.6      ; label("Cl (L/hr)")
    lVc <- log(18)  ; label("Vc (L)")
    lVp <- log(22)  ; label("Vp (L)")
    lQ  <- log(2)   ; label("Q (L/hr)")
    eta_KA ~ 0.1 ; label("BSV Ka")
    eta_Cl ~ 0.1 ; label("BSV Cl")
    eta_Vc ~ 0.1 ; label("BSV Vc")
    prop.err <- c(0, 0.2, 1)
  })
  model({
    KA <- exp(lKA + eta_KA)
    Cl <- exp(lCl + eta_Cl)
    Vc <- exp(lVc + eta_Vc)
    Vp <- exp(lVp)
    Q <- exp(lQ)
    linCmt() ~ prop(prop.err)
  })
}

nlmixr(twocmt)
#> __ RxODE-based 1-compartment model with first-order absorption _________________ 
#> -- Initialization: ------------------------------------------------------------- 
#> Fixed Effects ($theta): 
#>       lKA       lCl       lVc       lVp        lQ 
#> 0.1000000 1.6000000 2.8903718 3.0910425 0.6931472 
#> 
#> Omega ($omega): 
#>        eta_KA eta_Cl eta_Vc
#> eta_KA    0.1    0.0    0.0
#> eta_Cl    0.0    0.1    0.0
#> eta_Vc    0.0    0.0    0.1
#> -- mu-referencing ($muRefTable): ----------------------------------------------- 
#>   theta    eta
#> 1   lKA eta_KA
#> 2   lCl eta_Cl
#> 3   lVc eta_Vc
#> 
#> -- Model: ---------------------------------------------------------------------- 
#>     KA <- exp(lKA + eta_KA)
#>     Cl <- exp(lCl + eta_Cl)
#>     Vc <- exp(lVc + eta_Vc)
#>     Vp <- exp(lVp)
#>     Q <- exp(lQ)
#>     linCmt() ~ prop(prop.err) 
#> ________________________________________________________________________________

Created on 2021-06-28 by the reprex package (v2.0.0)

mattfidler commented 3 years ago

I think there is a bug. In RxODE, I can checkout the parameters by putting them in rxDerived() which uses the same detection algorithm as the linCmt()

Here we have:

library(RxODE)
#> RxODE 1.1.0 using 4 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
rxDerived(KA=exp(0.1), Cl=exp(1.6), Vc=18, Vp=22, Q=2)
#>   vc       kel       k12        k21 vp vss       cl q t12alpha  t12beta
#> 1 18 0.2751685 0.1111111 0.09090909 22  40 4.953032 2 1.661293 11.56109
#>       alpha      beta          A           B     fracA      fracB
#> 1 0.4172335 0.0599552 0.05074233 0.004813225 0.9133619 0.08663805

Created on 2021-06-29 by the reprex package (v2.0.0)

mattfidler commented 3 years ago

Fixes

library(nlmixr)
twocmt <- function() {
  ini({
    lKA <- 0.1      ; label("Ka (1/hr)")
    lCl <- 1.6      ; label("Cl (L/hr)")
    lVc <- log(18)  ; label("Vc (L)")
    lVp <- log(22)  ; label("Vp (L)")
    lQ  <- log(2)   ; label("Q (L/hr)")
    eta_KA ~ 0.1 ; label("BSV Ka")
    eta_Cl ~ 0.1 ; label("BSV Cl")
    eta_Vc ~ 0.1 ; label("BSV Vc")
    prop.err <- c(0, 0.2, 1)
  })
  model({
    KA <- exp(lKA + eta_KA)
    Cl <- exp(lCl + eta_Cl)
    Vc <- exp(lVc + eta_Vc)
    Vp <- exp(lVp)
    Q <- exp(lQ)
    linCmt() ~ prop(prop.err)
  })
}

nlmixr(twocmt)
#> ▂▂ RxODE-based 2-compartment model with first-order absorption ▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ 
#> ── Initialization: ───────────────────────────────────────────────────────────── 
#> Fixed Effects ($theta): 
#>       lKA       lCl       lVc       lVp        lQ 
#> 0.1000000 1.6000000 2.8903718 3.0910425 0.6931472 
#> 
#> Omega ($omega): 
#>        eta_KA eta_Cl eta_Vc
#> eta_KA    0.1    0.0    0.0
#> eta_Cl    0.0    0.1    0.0
#> eta_Vc    0.0    0.0    0.1
#> ── μ-referencing ($muRefTable): ──────────────────────────────────────────────── 
#>                              ┌─────────┬─────────┐
#>                              │ theta   │ eta     │
#>                              ├─────────┼─────────┤
#>                              │ lKA     │ eta_KA  │
#>                              ├─────────┼─────────┤
#>                              │ lCl     │ eta_Cl  │
#>                              ├─────────┼─────────┤
#>                              │ lVc     │ eta_Vc  │
#>                              └─────────┴─────────┘
#> 
#> ── Model: ────────────────────────────────────────────────────────────────────── 
#>     KA <- exp(lKA + eta_KA)
#>     Cl <- exp(lCl + eta_Cl)
#>     Vc <- exp(lVc + eta_Vc)
#>     Vp <- exp(lVp)
#>     Q <- exp(lQ)
#>     linCmt() ~ prop(prop.err) 
#> ▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂

Created on 2021-06-29 by the reprex package (v2.0.0)

This was an oversight; The linCmt() information was changed with the new focei-compatible linCmt()

Thank you for reporting this.

billdenney commented 3 years ago

Thanks!