Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request (maybe?): allow nlmixrSim to work on models that have not been solved #442

Open
billdenney opened this issue Jul 26, 2021 · 1 comment

Comments

@billdenney
Copy link
Contributor

I'm trying to generate the dataset for a reprex for a different issue, and for that, I'm trying to simulate a dataset. When trying to simulate the dataset, I thought that I would try using nlmixrSim(), but that doesn't seem to work. I think that the right answer is: "Bill, you're supposed to use RxODE for simulations like that." But, it would be handy if I could just use nlmixrSim() since I think it has most of the machinery built-in.

Here is the reprex of what I want to do. Ideally, either of the paths to get to simulation at the bottom would work:

library(nlmixr)

linear_twocmt_iiv_growth <- function() {
  ini({
    tcl <- fixed(log(0.01)) ; label("Clearance (L/kg/hr)")
    tq <- fixed(log(0.05)) ; label("Intercompartmental clearance (L/kg/hr)")
    tv <- fixed(log(1.5)) ; label("Volume central (L/kg)")
    tv1 <- fixed(log(2)) ; label("Volume peripheral (L/kg)")
    
    tktr <- log(c(0.00001, 0.03, 3)) ; label("Transit compartment rate (1/hr)")
    slope <- c(-2, -0.02, 2) ; label("Slope on growth rate ((ng/mL)/hr)")
    ltumorgrowth <- log(c(0.0001, 0.01, 1)) ; label("Baseline tumor exponential growth rate (1/hr)")

    iiv_tumorgrowth ~ 0.1 ; label("Inter-individual variability in baseline tumor exponential growth rate")

    prop_sd <- 0.2 ; label("Proportional error for tumor volume (fraction)")
    add_sd <- 100 ; label("Additive error for tumor volume (mm^3)")
  })
  drake::no_deps(model({
    cl <- exp(tcl)
    q <- exp(tq)
    v <- exp(tv)
    v1 <- exp(tv1)
    kcp <- q/v
    kpc <- q/v1
    ktr <- exp(tktr)
    TUMOR(0) <- TUMORBL
    
    d/dt(CENTRAL) = -cl/v * CENTRAL - kcp*CENTRAL + kpc*PERIPH1
    d/dt(PERIPH1) = kcp*CENTRAL - kpc*PERIPH1
    # unit conversion
    cp <- CENTRAL/v*1000
    d/dt(TRANSIT) = ktr*(cp - TRANSIT)
    tumorgrowth <- exp(ltumorgrowth + iiv_tumorgrowth)
    ktumor <- tumorgrowth + slope*TRANSIT
    d/dt(TUMOR) = ktumor*TUMOR
    TUMOR ~ add(add_sd) + prop(prop_sd)
  }))
}

sim_dose <-
  data.frame(
    ID=1:50,
    time=0,
    amt=rep(seq(0, 20, by=5), each=10),
    evid=1,
    cmt="CENTRAL",
    mdv=1,
    TUMORBL=100
  )

sim_obs <-
  expand.grid(
    ID=1:50,
    time=(0:60)*24,
    amt=0,
    evid=0,
    cmt="TUMOR",
    mdv=0,
    TUMORBL=100
  )

sim_data <- rbind(sim_dose, sim_obs)
sim_data <- sim_data[order(sim_data$ID, sim_data$time), ]

simulation <- nlmixrSim(linear_twocmt_iiv_growth, events=sim_data)
#> Error: object of type 'closure' is not subsettable
model <- nlmixr(linear_twocmt_iiv_growth)
simulation <- nlmixrSim(model, events=sim_data)
#> Error: object of type 'closure' is not subsettable

Created on 2021-07-26 by the reprex package (v2.0.0)

@mattfidler
Copy link
Collaborator

I am moving the UI to RxODE to allow the UI functions to be solved with RxODE alone.

So I agree and am already working on this in RxODE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants