Andrew, thanks for your interest in NIMBLE! We'll be curious to hear how it works out for you, so I hope we can get your model running soon. I'll admit upfront I have not taken the time to fully process the structure of the full model you're trying to run. But I can point out a few errors in usage, which fixing may get you up & running.
First, one type-o, I imagine just introduced when you copied / modified your code to provide a reproducible example. The code you emailed has:
There's no variable 'Knots'. I assume you meant the lower case version:
inits <- list(intMu=0, betaMu=0, alpha=rep(0,knots)),
which is defined.
I believe your problems are coming from incorrect usage of vectors vs. arrays, or essentially indexing, as you pointed out. Let me explain what's happening behind the scenes, and maybe you can correct the input and/or model specification.
'alpha' is being defined as a length-4 vector in your for-loop. That's all fine, just bear in mind that 'alpha' is a *vector*, not a matrix.
'K' is specified as a length-20 vector. Likewise, another vector.
In the line:
eta <- K%*%asCol(alpha)
you cast 'alpha' as a *column matrix*. That is, asCol(alpha) represents a 4x1 column matrix. This 4x1 matrix is then used in matrix multiplication against a length-20 vector. It's important to explain, we have tried to make NIMBLE processing mimic that of R, to the extent possible. So NIMBLE will try to "promote" the length-20 vector (K) into a matrix, such that it can be used for matrix multiplication. However, either way it promotes it (into a 20x1 matrix, or a 1x20 matrix), it's not conformable for multiplication by a 4x1 matrix. That's probably the root of your problem.
For using matrix multiplication, I would suggest either making certain the both arguments to %*% are in fact matricies, or equivalently, row- or column-matrices which result from applying either asRow() or asCol() to vectors. Then we can be certain the dimensions match, and the appropriate matrix multiplication takes place. Does that make sense?
One more trick I'll mention, once A and B are conformable matricies, you can either allow the multiplication to take place, then end up indexing the resulting matrix (as you've done):
eta <- A %*% B ## eta is a matrix
...
.... + eta[ id[i], 1] ## index eta as a matrix
Or, perhaps more simply, you can directly subset the result of the matrix multiplication, which will automatically demote the resulting matrix into a vector, then eta can later be indexed as the vector it actually is:
eta <- (A %*% B)[ 1:10, 1] ## now eta is a vector.... the value 10 should probably be something else
...
... + eta[ id[i] ] ## eta is indexed as a vector
Does this make sense? Let me know if not. And I'm sorry I didn't take the time to fully understand your model, but I thought I'd take a minute to explain these nuances of NIMBLE. Perhaps you'll be up & running before the Superbowl starts =)
Cheers,
Daniel
NIMBLE Development Team