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

Error with VPC: Could not fit data. #571

Closed namtien0312 closed 2 years ago

namtien0312 commented 2 years ago

Dear nlmixr team,

I had an error when performing VPC like this:

Error in .fitFun(.ret) : NaN while evaluating initial objective function
Error in foceiFit.data.frame0(data = .dat, inits = .inits, PKpars = .uif$theta.pars,  : 
  Could not fit data.

Code is simply that (the error solely existed for fit.model 2 and 4 in the iteration? - The "fit task" was successful for all 5 models).

set.seed(123)
p = list()
for (i in 1:5){
  p[[i]] = vpc(fit.list[[i]], scales = "free_y")
}

Thank you for your help! Tien Nguyen.

mattfidler commented 2 years ago

What is in the fit list. Sometimes you may have a nlmixr object in the fit.list[[i]]

namtien0312 commented 2 years ago

Sorry Dr. Fidler for giving the incomplete code. The fit.list[[i]] was created by:

model.list = c(Model1, Model2, Model3, Model4, Model5)
fit.list = list()
for (i in 1:length(model.list)) {
  fit.list[[i]] = nlmixr(model.list[[i]], mydata, list(print=0), est="posthoc")
}

The "fit task" was successful for all 5 models.

Thank you for your help! Tien Nguyen.

mattfidler commented 2 years ago

Can you provide a reproducible example? Unfortunately, no matter how much I want to help, I cannot help unless It have a reproducible example.

In R this is often done by the helper package reprex:

https://reprex.tidyverse.org/

namtien0312 commented 2 years ago

Sorry Dr. Fidler for the late response due to the Time zone difference.

The error that I mentioned occurred with some data but didn't with another, so I think it may depend on the data which I had? So I need more time for giving you reproducible code with simulated data for which this error exists.

Thank you for your patience! Tien Nguyen.

namtien0312 commented 2 years ago

Thank Dr. Fidler for kindly support, but I found a stupid mistake in that I missed EVID variable in my dataset then the VPC task didn't work as I expected. But I wonder that why this error solely occurred for 2 models.

And by the way, Do the nlmixr offer VPC with time after dose instead of time?

Tien Nguyen.

mattfidler commented 2 years ago

But I wonder that why this error solely occurred for 2 models.

It is unclear without the models. It is fishy though.

And by the way, Do the nlmixr offer VPC with time after dose instead of time?

I am guessing you could by using:

obs_cols = list(
         dv = "dv",        
         idv = "tad")

This is taken from:

http://vpc.ronkeizer.com/continuous-data.html

I am unsure if the tad is retained, but if it isn't it could be at a later time.

namtien0312 commented 2 years ago

Thank Dr. Fidler for your help!

Tien Nguyen.

namtien0312 commented 2 years ago

Dear Dr. @mattfidler,

I don't know when I performed the tad oftition with a real-world example that did not work. Suppose I had a dataset like this.

df = tibble(
  ID = c(rep(1, 6), rep(2, 6)),
  TIME = c(0.00, 12.11, 18.41, 23.89, 36.00, 43.51, 0.00, 12.00, 20.00, 24.00, 36.80, 45.00),
  AMT = c(1000, 1000, NA, 1000, 1000, NA, 1000, 2000, NA, 1000, 1000, NA),
  DUR = c(2.5, 2.5, NA, 2.5, 2.5, NA, 2.5, 2.5, NA, 2.5, 2.5, NA),
  DV = c(NA, NA, 3.0, NA, NA, 9.6, NA, NA, 7.0, NA, NA, 2.8),
  WT = c(rep(55, 6), rep(48, 6))
) %>% 
  mutate(EVID = ifelse(is.na(DV), 1, 0))

model = function() {     
  ini({
    tvCl <- c(0, 4, Inf)
    tvVc <- c(0, 48, Inf)

    eta.Vc ~ 0.62
    prop.sd <- 0.051529     

  })
  model({
    Cl <- tvCl
    Vc <- tvVc*(WT/70)*exp(eta.Vc)

    # dynamical system
    linCmt() ~ prop(prop.sd) 
  })
}

fit = nlmixr(model, df, list(print=0), est="posthoc")

vpc(fit, pred_corr = TRUE, show = list(obs_dv = T),
    obs_cols = list(
      dv = "dv",                           
      idv = "tad"))

image

Sure that the fit object has tad. The x-axis also was time rather than tad

fit$tad
[1] 3.80 5.01 5.50 5.70

Thank you for your help! Tien.

dlonsdal commented 2 years ago

@namtien0312 did you find a solution to this? I think possibly same issue as feature request here https://github.com/nlmixrdevelopment/nlmixr/issues/483

namtien0312 commented 2 years ago

Thank @dlonsdal for your information!