#25 Can't initialize variable with a vector with all NAs

v1.0_(example)
open
nobody
None
1
2014-12-05
2012-11-22
No

While making an R function that runs a JAGS model for left censored data I discovered that it is not possible to initialize a variable with a vector with all NAs. Initializing using a vector where some elements are NA works and has the effect (if I understood it right) that the values corresponding to the NAs get initialized automatically. Therefore I was a bit surprised to to get an error message when initializing an variable with a vector with all NAs which I assumed would be the same as not initializing the variable at all.

The following R code replicates the error on JAGS 3.3.0, rjags version 3-7, Ubuntu 10.4.

library(rjags)
model_string <- "model{
for(i in 1:3) {
  y[i] ~ dnorm(0, 1)
}
}"

# Works
jags.model(textConnection(model_string), data=list(y=c(10, NA, NA)), inits=list(y = c(NA, NA, 5)))
# Works
jags.model(textConnection(model_string), data=list(y=c(10, NA, NA)))
# Reports "Invalid initial values"
jags.model(textConnection(model_string), data=list(y=c(10, NA, NA)), inits=list(y = c(NA, NA, NA)))

Discussion


Anonymous

Cancel  Add attachments