nlmixr2 / babelmixr2

The goal of babelmixr2 is to interface nlmixr2 with other pharmacometric tools
https://nlmixr2.github.io/babelmixr2/
8 stars 1 forks source link

Question: How do I create a new estimation method? #45

Closed billdenney closed 2 years ago

billdenney commented 2 years ago

I want to create a new estimation method that will give initial estimates for nlmixr2 using noncompartmental parameters from PKNCA.

For that, I know that I'll need to add some of the parts that are similar to what has been done for NONMEM and Monolix, but it will also likely be simpler than those since it can stay fully within R. I think that the main parts are the following, but I'd like to confirm:

I think that those are the only two required parts. Is that correct?

If yes, my plan is to make nlmixr2Est.pknca() change the initial estimates using the ini() function or possibly going directly to the ui$iniDf. Do you see any issues with doing that? Is one of ini() or ui$iniDf preferred?

And finally, I was planning to determine the correct model parameter and transformation from the ui$iniDf data.frame. The idea was to look for either ka or lka to find absorption rate and determine if it should be log-transformed or not, for example. I looked at ui$iniDf, and the backTransform column was all NA in a model that estimated log-transformed parameters. Is there a better way to detect the transform used for a parameter than the heuristic of looking for an "l" at the beginning for log transform?

mattfidler commented 2 years ago

I think this is fine, as discussed.

We didn't discuss this:

Is there a better way to detect the transform used for a parameter than the heuristic of looking for an "l" at the beginning for log transform?

Yes, the parsing information inside the ui object contains this information:

library(rxode2)
#> rxode2 2.0.8 using 4 threads (see ?getRxThreads)
one.cmt <- function() {
  ini({
    ## You may label each parameter with a comment
    tka <- 0.45 # 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) + dnorm()
  })
}

f <- rxode2(one.cmt)
#> ℹ parameter labels from comments will be replaced by 'label()'

f$muRefCurEval
#>   parameter curEval low hi
#> 1    eta.ka     exp  NA NA
#> 2       tka     exp  NA NA
#> 3    eta.cl     exp  NA NA
#> 4       tcl     exp  NA NA
#> 5     eta.v     exp  NA NA
#> 6        tv     exp  NA NA

Created on 2022-08-12 by the reprex package (v2.0.1)

The muRefCurEval == "exp" gives this information.

mattfidler commented 2 years ago

If yes, my plan is to make nlmixr2Est.pknca() change the initial estimates using the ini() function or possibly going directly to the ui$iniDf. Do you see any issues with doing that? Is one of ini() or ui$iniDf preferred?

I would prefer returning a composite object with the pknca parameters accessible as well as the new estimation routine.

billdenney commented 2 years ago

What is a "composite object"? Are you meaning that it would be best to tuck the PKNCA results into the nlmixr2 UI object?

mattfidler commented 2 years ago

I was thinking of a list with the first element being the pknca analysis object and the second being a UI object. That way you can print how to get both objects.

Although what you say can work too.

billdenney commented 2 years ago

By the time the nlmixr2Est.pknca() function is called, has the data been cleaned? More specifically, I'm using the env$data$CMT and other columns to compute NCA parameters. Is it a good assumption that the compartment name will always be CMT at this point, or might it be lower case, etc.?

mattfidler commented 2 years ago

Nope. No data cleaning. There is some cleaning if you use the dataSave routine from focei followed by rxode2::etTrans( ). You can keep the CMT variable so it has what you want.

You can send meeting invite for clarification or to ask more questions if you need to.

On Sun, Sep 18, 2022, 7:21 PM Bill Denney @.***> wrote:

By the time the nlmixr2Est.pknca() function is called, has the data been cleaned? More specifically, I'm using the env$data$CMT and other columns to compute NCA parameters. Is it a good assumption that the compartment name will always be CMT at this point, or might it be lower case, etc.?

— Reply to this email directly, view it on GitHub https://github.com/nlmixr2/babelmixr2/issues/45#issuecomment-1250421199, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD5VWTEFBTIJDZ2XIIK7OLV66WXXANCNFSM56IWBJDA . You are receiving this because you commented.Message ID: @.***>

mattfidler commented 2 years ago

You could also use the covert to nonmem dataset funtion too. It should give what you need.

On Sun, Sep 18, 2022, 9:39 PM Matthew Fidler @.***> wrote:

Nope. No data cleaning. There is some cleaning if you use the dataSave routine from focei followed by rxode2::etTrans( ). You can keep the CMT variable so it has what you want.

You can send meeting invite for clarification or to ask more questions if you need to.

On Sun, Sep 18, 2022, 7:21 PM Bill Denney @.***> wrote:

By the time the nlmixr2Est.pknca() function is called, has the data been cleaned? More specifically, I'm using the env$data$CMT and other columns to compute NCA parameters. Is it a good assumption that the compartment name will always be CMT at this point, or might it be lower case, etc.?

— Reply to this email directly, view it on GitHub https://github.com/nlmixr2/babelmixr2/issues/45#issuecomment-1250421199, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD5VWTEFBTIJDZ2XIIK7OLV66WXXANCNFSM56IWBJDA . You are receiving this because you commented.Message ID: @.***>

mattfidler commented 2 years ago

I think you know this, but documentation is needed. Probably in nlmixr2est

For now I am going to close this.