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

Development Idea: Library of model snippets and model expansion #541

Closed billdenney closed 3 years ago

billdenney commented 3 years ago

Somewhat related to #540

To be very clear from the outset, I think that this would likely reside in another package than nlmixr, but it would be very tightly related. One common naming syntax for packages like this is something like nlmixrExtra.

My thought here is something like an nlmixr_tran() function that would perform pre-processing of models to expand commonly-used model structures.

library(nlmixrExtra)
onecmt <- function() {
  ini({
    lCl <- 1.6
    lVc <- log(18)
    lVmax <- log(0.1)
    lC50 <- log(100)
    eta_Cl ~ 0.1
    prop_err <- c(0, 0.2, 1)
  })
  model({
    Cl <- exp(lCl + eta_Cl)
    Vc <- exp(lVc)
    Vmax <- exp(lVmax)
    mm_c50 <- exp(lC50)
    cp <- TMDD_Michaelis_Menten(CL=Cl, Vc=Vc, Vmax=Vmax, C50=mm_c50, compartment=central)
    cp ~ prop(prop_err)
  })
}
onecmt_expanded <- nlmixr_tran(onecmt)

nlmixr_tran() would modify the model and return that modified model (or perhaps go ahead and call nlmixr with that modified model if estimate=TRUE or something like that).

The output of onecmt_expanded would expand out the linear_pk() function to look like:

function() {
  ini({
    lCl <- 1.6
    lVc <- log(18)
    lVmax <- log(0.1)
    lC50 <- log(100)
    eta_Cl ~ 0.1
    prop_err <- c(0, 0.2, 1)
  })
  model({
    Cl <- exp(lCl + eta_Cl)
    Vc <- exp(lVc)
    Vmax <- exp(lVmax)
    mm_c50 <- exp(lC50)
    d/dt(central) = -central*Cl/Vc - central*Vmax/(central/Vc + mm_c50)
    cp <- central/Vc
    cp ~ prop(prop_err)
  })
}

With an expansion mechanism (as suggested with nlmixr_trans()), it would be comparatively straight-forward to make the substitution functions like TMDD_Michaelis_Menten().

mattfidler commented 3 years ago

I think this is a fine idea!

billdenney commented 3 years ago

Great! Do you think it's reasonable to create an nlmixrExtra package under the nlmixrdevelopment aegis here on GitHub?

mattfidler commented 3 years ago

Sounds fine to me. Created it.

billdenney commented 3 years ago

And, now it's there! https://github.com/nlmixrdevelopment/nlmixrExtra