nlmixr2 / rxode2

rxode2
https://nlmixr2.github.io/rxode2/
GNU General Public License v3.0
28 stars 8 forks source link

`binom` simulation requires items to be in the model #663

Open mattfidler opened 6 months ago

mattfidler commented 6 months ago

If there is a number in the binom() simulation it fails:

library(nlmixr2)
#> Loading required package: nlmixr2data

set.seed(42)

lr.mod <- function() {
  ini({
    tb0 <- 0.9 
    tb1 <- 0.1
    eta ~ 0.01
  })
  model({
    intercept<-tb0
    slope<-tb1
    p <- expit(intercept + slope * time + eta)
    err ~ dbinom(1, p) 
  })
}

d <- et(10, 100, by=0.5) %>%
  et(id=1:1000)

d <- rxSolve(lr.mod, d)
#> rxode2 model syntax error:
#> ================================================================================
#> :001:     params(tb0, tb1, eta)
#> :002:     intercept <- tb0
#> :003:     slope <- tb1
#> :004:     p <- expit(intercept + slope * time + eta)
#> :005:     rx_yj_ ~ 22
#> :006:     rx_lambda_ ~ 1
#> :007:     rx_low_ ~ 0
#> :008:     rx_hi_ ~ 1
#> :009:     rx_r_ ~ 0
#> :010: 'llikBinom' takes 3 arguments, supplied 2:
#>           rx_pred_ ~ llikBinom(DV, p)
#>                      ^~~~~~~~~
#> :010:     rx_pred_ ~ llikBinom(DV, p)
#> :011: 'ribinom'/'rbinom'/'rxbinom' takes 2 arguments 'rxbinom(size, prob)':
#>           sim <- rbinom(p)
#>                  ^~~~~~
#> :011:     cmt(err)
#> :012:     dvid(1)
#> ================================================================================
#> Error: syntax errors (see above)

Created on 2024-03-11 with reprex v2.1.0

But this works:

library(nlmixr2)
#> Loading required package: nlmixr2data

set.seed(42)

lr.mod <- function() {
  ini({
    tb0 <- 0.9 
    tb1 <- 0.1
    eta ~ 0.01
  })
  model({
    intercept<-tb0
    slope<-tb1
    p <- expit(intercept + slope * time + eta)
    n <- 1
    err ~ dbinom(n, p) 
  })
}

d <- et(10, 100, by=0.5) %>%
  et(id=1:1000)

d <- rxSolve(lr.mod, d)
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’

Created on 2024-03-11 with reprex v2.1.0