Hi Daniel,
until that point everything is fine but the problem comes later when compiling the model.
So, I run the following lines and I get an error when creating "Cmodel" object:
# Nimble model
Rmodel <- nimbleModel(code=occupancy_static, constants=constants, data=win.data, inits = inits)
# Nimble model
Rmodel$initializeInfo()
# mcmc
conf <- configureMCMC(Rmodel, print = F)
conf$addMonitors(c("f","f.new"))
Rmcmc <- buildMCMC(conf)
# Compile the model and MCMC algorithm
Cmodel <- compileNimble(Rmodel)
At this point I get this error message:
> Cmodel <- compileNimble(Rmodel)
Compiling
[Note] This may take a minute.
[Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Error in eigenizeNameStrided(code, symTab, typeEnv, workEnv) :
Error, cannot eigenize a map of dimensions > 2
Error: There is some problem at the Eigen processing step for this code:
{
model$f.sum[1] <<- sum(model$f[1:150, 1:8, 1:2])
}
I don't know how to interpret this message.
Besides this, I also tried Matt's suggestion to sum over J[i,k].
Because the observational model is built as following, there are some non existing nodes, and this might be the reason for the original error message.
# Observation model
for (i in 1:nsite){
for(k in 1:nyears){
for(j in 1:J[i,k]){
muy[i,j,k] <- z[i,k]*p[i,j,k]
logit(p[i,j,k]) <- p_int
y[i,j,k] ~ dbern(muy[i,j,k])
# Goodness of Fit
f[i,j,k] <- abs(y[i,j,k] - p[i,j,k]) # Discrepancy for real data
y.new[i,j,k] ~ dbern(muy[i,j,k]) # Simulate data
f.new[i,j,k] <- abs(y.new[i,j,k] - p[i,j,k]) # Discrepancy for simulated data
} #j
} #k
} #i
So, I tried to sum indexing by J, as suggested by Matt:
f.sum <- sum(f[1:nsite, 1:J[i,k], 1:nyears])
but I still get error message:
> Rmodel <- nimbleModel(code=occupancy_static, constants=constants, data=win.data, inits = inits)
Defining model
Error in getSymbolicParentNodesRecurse(x, constNames, indexNames, nimbleFunctionNames, :
getSymbolicParentNodesRecurse: dynamic indexing of constants is not allowed in J[i, k]. Try adding the dynamically-indexed constant as data instead (using the data argument of nimbleModel).
Forgive me if anything is a bit confusing.
I will try to look into it again in the next few days.