nlmixrdevelopment / nlmixr

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

Zero Order Absorption using nlmixr #172

Closed mattfidler closed 5 years ago

mattfidler commented 5 years ago

Hello! How to handle zero order absorption using nlmixR? I added a column RATE= -2, because I need to estimate a Tk0 Is it possible with limCmt()? This model has one-compartment with zero-order absorption for while. I got this error message Error in RxODE::rxState(rxode) : attempt to use zero-length variable name Thanks! I am a new user...

Originally posted by @08Larry1989 in https://github.com/nlmixrdevelopment/nlmixr/issues/171#issuecomment-491400169

mattfidler commented 5 years ago

This is a new issue, so I'm opening a new issue.

Please post your session information sessionInfo() and the code you used so I can figure out where your bug is. It seems there is something broken in what you are trying.

08Larry1989 commented 5 years ago
M2 <- function() {
 ini({
     tD1 <- log(0.8)
     tcl <- log(51.2)
     tv <- log(344)
     eta.D1 ~ 0.4
     eta.cl ~ 0.4
     eta.v ~ 0.4
     add.err <- 1
     prop.err <- 0.2
   })
   model({
     D1 <- exp(tD1 + eta.D1)
     cl <- exp(tcl + eta.cl)
     v <- exp(tv + eta.v)
    limCmt() ~ add(add.err) + prop(prop.err)
   })
 }
 nlmixr(M2)
Error in RxODE::rxState(rxode) : attempt to use zero-length variable name
 sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RxODE_0.9.0-4      gridExtra_2.3      vpc_1.1.0         
[4] xpose.nlmixr_0.1.4 xpose_0.4.4        ggplot2_3.1.1     
[7] nlmixr_1.1.0-7    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1                pillar_1.3.1             
 [3] compiler_3.5.3            plyr_1.8.4               
 [5] PreciseSums_0.3           tools_3.5.3              
 [7] mvnfast_0.2.5             digest_0.6.18            
 [9] nlme_3.1-139              lattice_0.20-38          
[11] memoise_1.1.0             tibble_2.1.1             
[13] gtable_0.3.0              pkgconfig_2.0.2          
[15] rlang_0.3.4               rex_1.1.2                
[17] rstudioapi_0.10           parallel_3.5.3           
[19] RcppArmadillo_0.9.400.2.0 n1qn1_6.0.1-3            
[21] stringr_1.4.0             withr_2.1.2              
[23] dplyr_0.8.0.1             lbfgs_1.2.1              
[25] generics_0.0.2            grid_3.5.3               
[27] tidyselect_0.2.5          glue_1.3.1               
[29] R6_2.4.0                  polyclip_1.10-0          
[31] tidyr_0.8.3               purrr_0.3.2              
[33] tweenr_1.0.1              farver_1.1.0             
[35] dparser_0.1.8             magrittr_1.5             
[37] scales_1.0.0              MASS_7.3-51.4            
[39] units_0.6-3               assertthat_0.2.1         
[41] ggforce_0.2.2             colorspace_1.4-1         
[43] brew_1.0-6                stringi_1.4.3            
[45] lazyeval_0.2.2            munsell_0.5.0            
[47] crayon_1.3.4
mattfidler commented 5 years ago

Current error

I can reproduce on the latest github; The error is not very informative and should be changed.

``` r library(nlmixr) M2 <- function() { ini({ tD1 <- log(0.8) tcl <- log(51.2) tv <- log(344) eta.D1 ~ 0.4 eta.cl ~ 0.4 eta.v ~ 0.4 add.err <- 1 prop.err <- 0.2 }) model({ D1 <- exp(tD1 + eta.D1) cl <- exp(tcl + eta.cl) v <- exp(tv + eta.v) limCmt() ~ add(add.err) + prop(prop.err) }) } nlmixr(M2) #> Error in RxODE::rxState(rxode): attempt to use zero-length variable name ``` Created on 2019-05-10 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)

Correct way for linCmt() not working right now

In theory the duration should specified by dur(central). Currently there is some issue with the github version of this (I think it is in RxODE so I will open an issue there).

It gives the same error with the ODE specification.

This dur() modeling feature is new so thank you for your patience.

``` r library(nlmixr); library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union d <- theo_sd %>% mutate(RATE=ifelse(AMT==0,0,-2)) %>% select(-CMT) one.cmt.dur <- function() { ini({ tdur <- 0.45 # Log Ka tcl <- 1 # Log Cl tv <- 3.45 # Log V eta.dur ~ 0.06 eta.cl ~ 0.3 eta.v ~ 0.1 add.err <- 0.7 }) model({ d1 <- exp(tdur + eta.dur) cl <- exp(tcl + eta.cl) v <- exp(tv + eta.v) dur(central) <- d1 linCmt() ~ add(add.err) }) } mod.zero <- nlmixr(one.cmt.dur, d, "saem", control=list(print=0)) #> Compiling RxODE equations... #> done. #> Building SAEM model...done #> Error in cur.fn(a): Data Error -6 ``` Created on 2019-05-10 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)
08Larry1989 commented 5 years ago

Thanks for your attention Matthew! I look foward to use the dur() without problems!

mattfidler commented 5 years ago

You could try the dur directly. I have examples where it works. It could just be the theo example.

Get Outlook for Androidhttps://aka.ms/ghei36


From: 08Larry1989 notifications@github.com Sent: Saturday, May 11, 2019 11:22:18 AM To: nlmixrdevelopment/nlmixr Cc: Matthew Fidler; Author Subject: Re: [nlmixrdevelopment/nlmixr] Zero Order Absorption using nlmixr (#172)

Thanks for your attention Matthew! I look foward to use the dur() function without error...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/nlmixrdevelopment/nlmixr/issues/172#issuecomment-491524703, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAD5VWSIIL3M32AR3ENCG7DPU3XDVANCNFSM4HMGBQSA.

mattfidler commented 5 years ago

More informative error

``` r library(nlmixr); M2 <- function() { ini({ tD1 <- log(0.8) tcl <- log(51.2) tv <- log(344) eta.D1 ~ 0.4 eta.cl ~ 0.4 eta.v ~ 0.4 add.err <- 1 prop.err <- 0.2 }) model({ D1 <- exp(tD1 + eta.D1) cl <- exp(tcl + eta.cl) v <- exp(tv + eta.v) limCmt() ~ add(add.err) + prop(prop.err) }) } nlmixr(M2) #> Error in .nlmixrUIModel(fun, ini, bigmodel): You used `limCmt`, did you mean `linCmt`? ``` Created on 2019-05-13 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)
mattfidler commented 5 years ago

Hi @08Larry1989

In fact the dur() worked correctly with the linCmt(). There were two errors on this thread:

  1. You accidently used limCmt instead of linCmt
  2. I accidentally used classic RxODE while trying to specify RATE in the NONMEM style.

The model indeed does work with the linCmt once these errors are corrected.

``` r library(nlmixr) library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union d <- theo_sd %>% mutate(RATE=ifelse(AMT==0,0,-2), EVID=ifelse(AMT==0,0,1)) %>% select(-CMT) one.cmt.dur <- function() { ini({ td1 <- 0.1 # Log Ka tcl <- 1 # Log Cl tv <- 3.45 # Log V eta.d1 ~ 0.06 eta.cl ~ 0.3 eta.v ~ 0.1 add.err <- 0.7 }) model({ d1 <- exp(td1 + eta.d1) v <- exp(tv + eta.v) cl <- exp(tcl + eta.cl) d/dt(center) = - cl / v * center dur(center) = d1 cp = center / v cp ~ add(add.err) }) } mod.zero <- nlmixr(one.cmt.dur, d, "saem", control=list(print=0)) #> Compiling RxODE equations... #> done. #> Calculating covariance matrix #> [====|====|====|====|====|====|====|====|====|==== #> Calculating residuals/tables #> done. print(mod.zero) #> ── nlmixr SAEM(ODE); OBJF not calculated fit ────────────────────────────── #> Gaussian/Laplacian Likelihoods: AIC() or $objf etc. #> FOCEi CWRES & Likelihoods: addCwres() #> #> ── Time (sec; $time): ───────────────────────────────────────────────────── #> saem setup table covariance other #> elapsed 3.141 0.719466 0.007 0.006 0.215534 #> #> ── Population Parameters ($parFixed or $parFixedDf): ────────────────────── #> Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) #> td1 Log Ka -0.0863 0.144 167 0.917 (0.692, 1.22) 52.2 #> tcl Log Cl 0.938 0.0829 8.83 2.56 (2.17, 3.01) 27.6 #> tv Log V 3.54 0.0422 1.19 34.4 (31.7, 37.4) 13.8 #> add.err 0.54 0.54 #> Shrink(SD)% #> td1 -2.29% #> tcl 0.419% #> tv 1.96% #> add.err #> #> Covariance Type ($covMethod): linFim #> No correlations in between subject variability (BSV) matrix #> Full BSV covariance ($omega) or correlation ($omegaR; diagonals=SDs) #> Distribution stats (mean/skewness/kurtosis/p-value) available in $shrink #> #> ── Fit Data (object is a modified tibble): ──────────────────────────────── #> # A tibble: 132 x 17 #> ID TIME DV EVID PRED RES IPRED IRES IWRES eta.d1 eta.cl #> #> 1 1 0 0.74 0 0 0.74 0 0.74 1.37 -0.00504 -0.485 #> 2 1 0.25 2.84 0 2.51 0.329 2.87 -0.0254 -0.0471 -0.00504 -0.485 #> 3 1 0.570 6.57 0 5.66 0.912 6.48 0.0905 0.168 -0.00504 -0.485 #> # … with 129 more rows, and 6 more variables: eta.v , d1 , #> # v , cl , cp , center ``` Created on 2019-05-13 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)
mattfidler commented 5 years ago

Please let me know if this works for you.

As a note, at the time of the writing FOCEi only handles rate, F dur and lag when there is no ETA dependence on the parameters themselves.

08Larry1989 commented 5 years ago

Hi Matthew, I had not realized the typing error with linCmt(), sorry. Now everything works perfectly! Thanks for helping me

mattfidler commented 5 years ago

No problem. Obviously I made a mistake too.

Best

Matt