Hi Zhu,
It looks like this error is coming from pure R (i.e. nimble uncompiled) calculation of your model.
It is happening when m[i] is 1. In that case, (1+msum[i-1]):msum[i] is 1:1, or simply 1. Then your quadratic form,
E[(1+msum[i-1]):msum[i], 1:6] %*% Sigma[1:6, 1:6] %*% t(E[(1+msum[i-1]):msum[i], 1:6])
is not working correctly in R (or nimble). Here is an example:
E <- 1:6 # E[(1+msum[i-1]):msum[i], 1:6] returns a vector of length 6, so it is something of the same type as 1:6
Sigma <- diag(6)
E %*% Sigma %*% t(E) # error
The problem is R dynamically evaluates the types of inputs to the %*% function. When it sees a vector, it checks whether treating it as a one-row or one-column matrix will make it conformable. e.g. both of these work:
E %*% Sigma
Sigma %*% E
But the default matrix for E is a one-column matrix, so t(E) is a one-row matrix, and this is non-conformable: You are telling R which way you want it to handle E, and that way doesn't work.
Sigma %*% t(E)
Again, this error is occurring in R, but it is something you'll need to fix for nimble compilation to work as well.
There will also be an issue in nimble when you use extents like 1:m[i] that are simply 1:1. So for both reasons, I'd suggest separating the cases where the extent is 1:1. You could potentially pick those out separately and declare them in a for loop with scalar operations and a dnorm instead of dmnorm.
I also noticed nimbleModel is giving you a warning (at the end of its output) about multiple declarations of mu_tau. If that is indexed only by t, it should not be in a loop with i. You can make a separate loop over t to declare the mu_tau nodes.
I also noticed, in your R code for simulating inputs, the lines like
y[i,j] ~ rbinom(1, 1, 0.5)
are not doing anything. In R code, you'll want "<-" instead of "~".
HTH and good luck with it.
Perry