Hello,
I ran into a problem in my model that appeared related to expression like x[1:N[1]] <- r[]. So I created a toy example that mimics the problem. See the full code appended. The error is
Error in addMissingIndexingRecurse(code[[i]], dimensionsList) :
inconsistent dimensionality provided for node 'N'
I would like to use the expression
x[1:N[1]] because my data could have one or more datasets and 'N' length will vary from a scalar to a vector, such as N = 100, N = c(100, 200), and so on. I believe NIMBLE should be able to accommodate the code like "x[1:N[t]] <- r[]
" for t = 1, 2, ...
Will NIMBLE accept this expression in the future or do we have a workaround to solve this problem?
Many thanks!
library("nimble")
code <- nimbleCode({
for (n in 1:N[1]){
r[n] ~ dnorm(mu,sd=sd)
}
nu ~ dnorm(0,0.01)
sd ~ dunif(0.01,5)
x[1:N[1]] <- r[]
})
constants <- list(N=100)
data <- list(r=rnorm(n=100))
inits <- list(mu=0,sd=2)
monitors = c("mu","sd")
MODEL <- nimbleModel(code = code, name = "MODEL", constants = constants,data = data, inits = inits)
cmodel <- compileNimble(MODEL)
conf <- configureMCMC(MODEL, monitors = monitors
,useConjugacy=TRUE ,print = FALSE
,enableWAIC=TRUE
,onlySlice=FALSE
)
modelMCMC <- buildMCMC(conf)
cmodelMCMC <- compileNimble(modelMCMC, project = MODEL ,resetFunctions = TRUE)
burnin = 1000
keep = 1000
nchains = 1
rand.seed = 1
niter = burnin + keep
out <- system.time(samples <- runMCMC(cmodelMCMC, niter = niter, nburnin = burnin, nchains=nchains
,samplesAsCodaMCMC=TRUE
,samples= TRUE
,summary=TRUE
,WAIC = TRUE
,setSeed = rand.seed))
print(samples$summary)