Closed audrey-b closed 4 years ago
Will do when I get a moment unless you want to tackle?
@audrey-b It's more complicated than simply removing this assertion. I don't have time to address for the foreseeable future. Feel free to explore in a branch!
Removing chk_not_any_na(parameters)
causes the error
The following variable nodes are defined in parameters: 'N'.
If we relax as well then we are allowing parameters to be monitored. I'm not sure if this is a good idea.
You can achieve using the following which I think is clearer about intent.
library(sims)
code = "
x[1] <- N
for(t in 2:K){
x[t] ~ dbin(1-phi, x[t-1])
}
"
sims <- sims::sims_simulate(code=code,
constants=nlist(K=4),
parameters=nlist(phi=0.95, N=100))
sims
#> $x
#> [1] 100 7 0 0
#>
#> $K
#> [1] 4
#>
#> an nlists object of an nlist object with 2 numeric elements
Created on 2020-07-08 by the reprex package (v0.3.0)
State-space model
code = " for(t in 2:K){ N[t] ~ dbin(1-phi, N[t-1]) } " sims <- sims::sims_simulate(code=code, constants=nlist(K=4), parameters=nlist(phi=0.95, N=c(100, rep(NA, 4))) )
chk_not_any_na(parameters) should be removed so an error is not thrown
As a comparison, the following is valid:
jags.model(textConnection(" model{for(t in 2:K){ N[t] ~ dbin(1-phi, N[t-1]) }}"), data=list(phi=0.95, N=c(100, rep(NA, 3)), K=4))