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

Inter-occasion variability (IOV) #93

Open amaisahmad opened 5 years ago

amaisahmad commented 5 years ago

Hi, Is there any other way to implement inter-occasion variability in the model? As for current version i am getting this error when converting nonmem data using nmDataConvert. There is resent-and-dose event given by EVID = 4.

"Error in nmDataConvert(data) : A reset of the ODE system is not currently supported." Thanks,

mattfidler commented 5 years ago

Hi @amaisahmad

Currently there is not a way to code inter-occasion variability, it is on our todo list

Also RxODE does not currently support EVIDs>=2.

rfaelens commented 5 years ago

The missing feature is a way to specify SAME in nlmixr. All the rest is possible, by using a time-varying covariate: I think you can code IOV in the nonmem-standard way, by considering "OCC" as a time-varying covariate OCC and then selecting the appropriate ETA.

OCC1=0;
if(OCC==1) OCC1=1;
OCC2=0;
if(OCC==2) OCC2=1;
CL = TVCL * exp(ECL + ECL_IOV1*OCC1 + ECL_IOV2*OCC2);

But the nlmixr eventTable could allow an "OCC" column, allowing an IOV-marked ETA to be swapped in/out automatically, that is probably even better.

mattfidler commented 5 years ago

Time varying covariates are supported by FOCEi and nlme. SAEM does not yet support time-varying covariates.

However, we are working toward IOV and possibly other levels of random effects. I am leaning toward the UI swapping out the IOV-marked ETA.

I have focused on some model-based event changes (like bioavailability, lag-time, modeled zero-order infusion etc) currently in RxODE. Once that gets done FIXED omegas in FOCEi and SAME omegas in FOCEi would be the next step in nlmixr development.

FabiWinter commented 2 years ago

Hi,

it's been a while since this topic was discussed but I was wondering if there has been any updates since then. Is it now possible to simulate inter occasion variability in nlmixr since RxODE now also supports EVID => 2?

mattfidler commented 2 years ago

You can simulate IOV in RxODE, but cannot model it in nlmixr yet:

https://nlmixrdevelopment.github.io/RxODE/articles/RxODE-nesting.html

mattfidler commented 2 years ago

You can use the same evids in nlmixr and RxODE. I am unsure how this is related to iov.

Martin-Umpierrez commented 7 months ago

Hello again on this topic! I'm revisiting it because I'm keen to find out if it's now possible to model IOV (not just simulate it). I'm interested in assessing the predictive performance of certain models, including those that exhibit IOV. Consequently, I'll need to estimate individual parameters that are described by a certain interoccasion variability.

Thank you in advance!

mattfidler commented 7 months ago

Not yet, and not yet in nlmixr2 either.

hainiwen commented 4 months ago

I think my question is related to this issue, therefore I'll put it here:

In omega block, can we write something similar as in NONMEM: $ omega SAME

If this is doable maybe we can work around IOVs in some cases I think...

Martin-Umpierrez commented 4 months ago

Hi everyone: Here is a model for Tacrolimus with IOV that i coded that maybe can work trough IOV. Maybe if someone can confirm that this makes sense would be amazing. I tried to run with my data set and actually run it ok. Since this model was developed in Monolix and i had to make some changes in the data from Monolix to nlmixer i think i may have some errores there, but..,. i. think the model could actually work. Here is the example:

two.compartment.tacro.test.Polimorf <- function() {
  ini({
    ### Umpierrez_etal_model
    #### FIXED PARAMETERS
    tka <- log(2.49); label("Ka")
    tcl <- log(19.84); label("Cl")
    tvc <- log(330.4) ; label("Vc")
    tvp <- log(118.2) ; label ("Vp")
    tvq <- log(35.44); label ("Q")
    ### VARIABILITY
    eta.ka ~ 0.82 ; label("IIV Ka")
    eta.cl ~ 0.358 ;label("IIV Cl")
    eta.vc ~ 1.186  ;label("IIV Vc")
    eta.q  ~ 0.58  ;label("IIV q")
    theta.iov.cl <- c(0, 0.25) ; label ("IOV CL")  
    iov.cl1 <- fix(1) ; label("IOV OCC1")
    iov.cl2 <- fix(1) ; label("IOV OCC2")
    iov.cl3 <- fix (1) ; label("IOV OCC3") ###  as much as occasions 
    ##COVARIATES
    ascl <- fix(0.75) ; label("Alometric Scaling for CL")
    asv   <- fix(1) ; label("Alometric Scaling for V")
    beta.hct  <- fix(-1.0) ; label("Effect of HCT on Cl")
    beta.CYP3A5.1  <- fix(0.91)  ; label("Effect of CYP3A5*1*1 on CL")
    beta.CYP3A5.2  <- fix(0.63)  ; label("Effect of CYP3A5*1*3 on CL")
    ####ERROR MODEL###
    prop.sd <- 0.204
  })
  model({
    iov <- theta.iov.cl * (OCC1 * iov.cl1 + OCC2 * iov.cl2 + OCC3 * iov.cl3) 
    cov.cl <- ascl*log(LBW/55) + beta.hct*log(HCT/33.5) 
    if (CYP3A5 == 1){
      cl = exp(tcl + beta.CYP3A5.1 + eta.cl + iov + cov.cl) 
    } else if (CYP3A5 == 2){
      cl = exp(tcl + beta.CYP3A5.2 + eta.cl + iov + cov.cl) 
    } else {
      cl = exp(tcl+ eta.cl + iov + cov.cl)
    }
    ka <- exp(tka + eta.ka)
    vc <- exp(tvc + eta.vc + asv*log(LBW/55))
    vp <- exp(tvp + asv*log(LBW/55))
    q <- exp(tvq + eta.q + ascl*log(LBW/55))
    d/dt(depot) <- -ka * depot
    d/dt(center) <- ka * depot - cl / vc * center
    d/dt(periph) <- q / vc * depot  - q/vp * periph
    cp <- center / vc
    cp ~ prop(prop.sd)
  })
}
mattfidler commented 4 months ago

Hi everyone: Here is a model for Tacrolimus with IOV that i coded that maybe can work trough IOV. Maybe if someone can confirm that this makes sense would be amazing. I tried to run with my data set and actually run it ok. Since this model was developed in Monolix and i had to make some changes in the data from Monolix to nlmixer i think i may have some errores there, but..,. i. think the model could actually work. Here is the example:

two.compartment.tacro.test.Polimorf <- function() {
  ini({
    ### Umpierrez_etal_model
    #### FIXED PARAMETERS
    tka <- log(2.49); label("Ka")
    tcl <- log(19.84); label("Cl")
    tvc <- log(330.4) ; label("Vc")
    tvp <- log(118.2) ; label ("Vp")
    tvq <- log(35.44); label ("Q")
    ### VARIABILITY
    eta.ka ~ 0.82 ; label("IIV Ka")
    eta.cl ~ 0.358 ;label("IIV Cl")
    eta.vc ~ 1.186  ;label("IIV Vc")
    eta.q  ~ 0.58  ;label("IIV q")
    theta.iov.cl <- c(0, 0.25) ; label ("IOV CL")  
    iov.cl1 <- fix(1) ; label("IOV OCC1")
    iov.cl2 <- fix(1) ; label("IOV OCC2")
    iov.cl3 <- fix (1) ; label("IOV OCC3") ###  as much as occasions 
    ##COVARIATES
    ascl <- fix(0.75) ; label("Alometric Scaling for CL")
    asv   <- fix(1) ; label("Alometric Scaling for V")
    beta.hct  <- fix(-1.0) ; label("Effect of HCT on Cl")
    beta.CYP3A5.1  <- fix(0.91)  ; label("Effect of CYP3A5*1*1 on CL")
    beta.CYP3A5.2  <- fix(0.63)  ; label("Effect of CYP3A5*1*3 on CL")
    ####ERROR MODEL###
    prop.sd <- 0.204
  })
  model({
    iov <- theta.iov.cl * (OCC1 * iov.cl1 + OCC2 * iov.cl2 + OCC3 * iov.cl3) 
    cov.cl <- ascl*log(LBW/55) + beta.hct*log(HCT/33.5) 
    if (CYP3A5 == 1){
      cl = exp(tcl + beta.CYP3A5.1 + eta.cl + iov + cov.cl) 
    } else if (CYP3A5 == 2){
      cl = exp(tcl + beta.CYP3A5.2 + eta.cl + iov + cov.cl) 
    } else {
      cl = exp(tcl+ eta.cl + iov + cov.cl)
    }
    ka <- exp(tka + eta.ka)
    vc <- exp(tvc + eta.vc + asv*log(LBW/55))
    vp <- exp(tvp + asv*log(LBW/55))
    q <- exp(tvq + eta.q + ascl*log(LBW/55))
    d/dt(depot) <- -ka * depot
    d/dt(center) <- ka * depot - cl / vc * center
    d/dt(periph) <- q / vc * depot  - q/vp * periph
    cp <- center / vc
    cp ~ prop(prop.sd)
  })
}

This should work, though I have not tested it myself. Mats Karlsson suggested this approach to handling iov in the nlmixr2 advisory meeting last week.

I have not posted it yet since it haven't tested it. If it is working, then it should be fine. It should also simulate IOV as well.

mattfidler commented 2 months ago

One thing to mention in this approach the iovs are modeled as standard deviations not variances. Just something to keep in mind.