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

Names error with focei #514

Open billdenney opened 3 years ago

billdenney commented 3 years ago

This looks really similar to #502.

library(nlmixr)

d_sim <-
  data.frame(
    concentration=1:1000
  )
# Simulate
e0 <- 100
emax <- 100
ec50 <- 200
d_sim$effect_pred <-
  e0 + emax*d_sim$concentration/(ec50 + d_sim$concentration)
# Add some exponential and additive error
d_sim$dv <-
  d_sim$effect_pred * exp(rnorm(n=nrow(d_sim), sd=0.2)) + rnorm(n=nrow(d_sim))

model <- function() {
  ini({
    e0 <- 100
    emax <- 100
    ec50 <- log(200)
    prop_err <- 0.2
    add_err <- 1
  })
  model({
    effect <- e0 + emax*concentration/(exp(ec50) + concentration)
    effect ~ prop(prop_err) + add(add_err)
  })
}

fit <- nlmixr(object=model, data=d_sim, est="focei")
#> Error in nlmixrUIModel(.model, ini, fun): 'names' attribute [22] must be the same length as the vector [21]
#> bad parsed model (cached C:\Users\BILLDE~1\AppData\Local\R\cache\R\RxODE/ui-5aa9ad5be14ec77da76fd2f6dfcefdf1.bad)

Created on 2021-04-27 by the reprex package (v2.0.0)

The nlmixr and RxODE versions were just installed moments ago from GitHub.

billdenney commented 3 years ago

I thought that the problem was that I may not have defined a CMT column (and I do think that is probably part of the issue), so I tried defining an unused CMT, but that got a zero-byte .bad file. The zero-byte .bad file appears to come up only some of the time, and I don't understand why it is created or not. But regardless, here is a similar test case.

library(nlmixr)
#> detected new version of RxODE, cleaning cache

d_sim <-
  data.frame(
    concentration=1:1000,
    CMT="EFFECT"
  )
# Simulate
e0 <- 100
emax <- 100
ec50 <- 200
d_sim$effect_pred <-
  e0 + emax*d_sim$concentration/(ec50 + d_sim$concentration)
# Add some exponential and additive error
d_sim$dv <-
  d_sim$effect_pred * exp(rnorm(n=nrow(d_sim), sd=0.2)) + rnorm(n=nrow(d_sim))

test_model <- function() {
  ini({
    e0 <- 100
    emax <- 100
    ec50 <- log(200)
    prop_err <- 0.2
    add_err <- 1
  })
  model({
    effect <- e0 + emax*concentration/(exp(ec50) + concentration)
    effect ~ prop(prop_err) + add(add_err)
  })
}

fit <- nlmixr(object=test_model, data=d_sim, est="focei")
#> Error in RxODE::rxState(rxode): 'names' attribute [22] must be the same length as the vector [21]

Created on 2021-04-27 by the reprex package (v2.0.0)

mattfidler commented 3 years ago

Perhaps a note that the model requires time or d/dt at this point may be sufficient to circumvent a strange error.

billdenney commented 3 years ago

I think a clear error message that the model requires a time column would clear it up.