ggPMXdevelopment / ggPMX

ggPMX R package
37 stars 11 forks source link

Missing data-section in ggPMX controller created from nlmixr-object #174

Closed braemd closed 2 years ago

braemd commented 3 years ago

Hi,

I tried to reproduce the theophyllin example using nlmixr but I have some trouble creating a working controller. The "param" and the "plot" section in the controller are created correctly but the "data" section is missing. And when I want to plot e.g. a vpc, no plot appears and NULL is given as output.

There is a warning when compiling the model and I'm not sure whether this is related to ggPMX or rather to nlmixr itself. (I have not used nlmixr for a while)

But using the theophyllin()-function, I can create a controller correctly with "param", "data" and "plot" section.

I have following code and outputs:

library(ggplot2)
library(nlmixr)
library(ggPMX)

one.cmt <- function() {
  ini({
    ## You may label each parameter with a comment
    tka <- 0.45 # Log Ka
    tcl <- log(c(0, 2.7, 100)) # Log Cl
    ## This works with interactive models
    ## You may also label the preceding line with label("label text")
    tv <- 3.45; label("log V")
    ## the label("Label name") works with all models
    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)
    linCmt() ~ add(add.sd)
  })
}

fit <- nlmixr(one.cmt, theo_sd, est="saem", list(print=0))

ctr <- pmx_nlmixr(fit)
add npde
Compiling NPDE model...done
done
Compiling model...rx_a52911068df0162e01d1fa05ed7138f6_x64.c: In function 'rx_a52911068df0162e01d1fa05ed7138f6_x64_Rate':
rx_a52911068df0162e01d1fa05ed7138f6_x64.c:611:7: warning: 'rx_pred_' is used uninitialized in this function [-Wuninitialized]
   pred=rx_pred_;

done
Compiling VPC model...done
done (1.27 sec)
print(ctr)
pmx object:

|PARAM                |VALUE |
|:--------------------|:-----|
|working directory    |      |
|Modelling input file |      |
|dv                   |DV    |
|dvid                 |      |

|plot_name       |plot_type |
|:---------------|:---------|
|abs_iwres_ipred |SCATTER   |
|iwres_ipred     |SCATTER   |
|iwres_time      |SCATTER   |
|iwres_dens      |PMX_DENS  |
|iwres_qq        |PMX_QQ    |
|npde_time       |SCATTER   |
|npde_pred       |SCATTER   |
|npde_qq         |PMX_QQ    |
|dv_pred         |SCATTER   |
|dv_ipred        |SCATTER   |
|individual      |IND       |
|eta_hist        |DIS       |
|eta_box         |DIS       |
|eta_matrix      |ETA_PAIRS |
|eta_qq          |PMX_QQ    |
ctr %>% pmx_plot_vpc

NULL
ctr <- theophylline()

print(ctr)

pmx object:

|PARAM                |VALUE        |
|:--------------------|:------------|
|working directory    |theophylline |
|Modelling input file |data_pk.csv  |
|dv                   |Y            |
|dvid                 |dvid         |
|cats                 |SEX          |
|conts                |WT0,AGE0     |
|strats               |STUD         |

|data_name   |data_file       |data_label                                |
|:-----------|:---------------|:-----------------------------------------|
|predictions |predictions.txt |model predictions file                    |
|estimates   |estimates.txt   |parameter estimates file                  |
|eta         |indiv_eta.txt   |invidual estimates of random effects file |
|finegrid    |finegrid.txt    |finegrid file                             |
|input       |data_pk.csv     |modelling input                           |

|plot_name       |plot_type |
|:---------------|:---------|
|abs_iwres_ipred |SCATTER   |
|iwres_ipred     |SCATTER   |
|iwres_time      |SCATTER   |
|iwres_dens      |PMX_DENS  |
|iwres_qq        |PMX_QQ    |
|npde_time       |SCATTER   |
|npde_pred       |SCATTER   |
|npde_qq         |PMX_QQ    |
|dv_pred         |SCATTER   |
|dv_ipred        |SCATTER   |
|individual      |IND       |
|eta_hist        |DIS       |
|eta_box         |DIS       |
|eta_matrix      |ETA_PAIRS |
|eta_cats        |ETA_COV   |
|eta_conts       |ETA_COV   |
|eta_qq          |PMX_QQ    |
|pmx_vpc         |VPC       |

Packages and platform

Do you see, where the error might be?

Many thanks in advance!

mattfidler commented 3 years ago

Hi @braemd,

I'm unsure if it is ggPMX or nlmixr. You can see by trying something like:

library(ggplot2)
library(nlmixr)
library(ggPMX)

one.cmt <- function() {
  ini({
    ## You may label each parameter with a comment
    tka <- 0.45 # Log Ka
    tcl <- log(c(0, 2.7, 100)) # Log Cl
    ## This works with interactive models
    ## You may also label the preceding line with label("label text")
    tv <- 3.45; label("log V")
    ## the label("Label name") works with all models
    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)
    linCmt() ~ add(add.sd)
  })
}

fit <- nlmixr(one.cmt, theo_sd, est="saem", list(print=0))

addNpde(fit)

nlmixr::vpc(fit)

If one of these seem to be problematic you can say the problem is with nlmixr; Otherwise it is with ggPMX.

mattfidler commented 3 years ago

Note that the data section in the ggPMX controller is missing for nlmixr since it doesn't actually read data files to produce the controller like NONMEM and Monolix, so this information is not in the nlmixr style controller

braemd commented 3 years ago

Thanks, in the example without ggPMX, everything worked and I could create the vpc plot using nlmixr::vpc(fit). So it seems to be related to ggPMX.?

And thanks for clarifying the lack of the data section, makes sense.

mattfidler commented 3 years ago

It may be. Perhaps you can submit the code so that we can check what is going on here?

Thanks for reporting the issue.

Lee21A commented 2 years ago

@mattfidler

I also have a similar problem. Interestingly, If I used the function “theophylline()” for quick reference, it is OK. I can see an excellent vpc plot. ctr <- theophylline()

However, if I test using the sample code listed in ggPMX-guide.pdf, I can see only “NULL” output.

I used nlmixr version = 2.0.6 ggPMX=1.2.4 R version = 4.1.2 Rstudio = 2021.09.1

YJ

library(RxODE)
library(nlmixr)
library(ggPMX)

one.cmt <- function() {
  ini({
    ## You may label each parameter with a comment
    tka <- 0.45 # Log Ka
    tcl <- 1 # Log Cl
    ## This works with interactive models
    ## You may also label the preceding line with label("label text")
    tv <- 3.45; label("log V")
    ## the label("Label name") works with all models
    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)
    linCmt() ~ add(add.sd)
  })
}
fit <- nlmixr(one.cmt, theo_sd, est="saem", control=list(print=0))
## The fit object is a nlmixr fit; You can read it into the nlmixr controller by:
ctr <- pmx_nlmixr(fit)
ctr %>% pmx_plot_vpc()

output

> library(RxODE)
RxODE 1.1.2 using 4 threads (see ?getRxThreads)
  no cache: create with `rxCreateCache()`
> library(nlmixr)
> library(ggPMX)
Registered S3 method overwritten by 'GGally':
  method from   
  +.gg   ggplot2
> 
> one.cmt <- function() {
+   ini({
+     ## You may label each parameter with a comment
+     tka <- 0.45 # Log Ka
+     tcl <- 1 # Log Cl
+     ## This works with interactive models
+     ## You may also label the preceding line with label("label text")
+     tv <- 3.45; label("log V")
+     ## the label("Label name") works with all models
+     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)
+     linCmt() ~ add(add.sd)
+   })
+ }
> fit <- nlmixr(one.cmt, theo_sd, est="saem", control=list(print=0))
i parameter labels from comments will be replaced by 'label()'
> generate SAEM model
√ done
Calculating covariance matrix
[====|====|====|====|====|====|====|====|====|====] 0:00:00 

> creating full model...
> pruning branches (`if`/`else`)...
√ done
> loading into symengine environment...
√ done
> compiling EBE model...
√ done
Calculating residuals/tables
done
> ## The fit object is a nlmixr fit; You can read it into the nlmixr controller by:
> ctr <- pmx_nlmixr(fit)
add npde
Compiling NPDE model...done
done
Compiling model...rx_5b58d2719a7cc24ad8f4f3b24f728965_x64.c: In function 'rx_5b58d2719a7cc24ad8f4f3b24f728965_x64_Rate':
rx_5b58d2719a7cc24ad8f4f3b24f728965_x64.c:611:7: warning: 'rx_pred_' is used uninitialized in this function [-Wuninitialized]
   pred=rx_pred_;
   ~~~~^~~~~~~~~

done
Compiling VPC model...done
done (2.24 sec)
>                   
> ctr %>% pmx_plot_vpc()
NULL
> 
> 
> ```
Error: attempt to use zero-length variable name
> 

Lee21A commented 2 years ago

Of course, the nlmixr VPC command works well using the fit data set.

nlmixr::vpc(fit,nsim=500)
mattfidler commented 2 years ago

Sorry It didn't see this. I think something happened with the nlmixr vpc in ggPMX. I will look into it with nlmixr2

Lee21A commented 2 years ago

Thanks. I understood.

If vpc.ui can show a nice legend in VPC plots like ggPMX, many users will be satisfied with just using nlmixr. Are there any other tips? I mean the way to show a legend in VPC plots using vpc.ui. VPC

mattfidler commented 2 years ago

I agree that the VPC has a nice legend with ggPMX.

As for now, the legend would be a function of adding the proper arguments to the vpc function.

I am unsure why this broke in the first place, I need to add some tests on the ggPMX side so this doesn't break in the future. This shouldn't have an issue for testing in the future since nlmixr no longer requires python.

Lee21A commented 2 years ago

Thank you. @mattfidler

mattfidler commented 2 years ago

This has been fixed in the master branch of ggPMX