Colin, I can't fully debug or fix your code this moment, but thought a really quick reply with a few pointers might be helpful.
You're mixing up some of the concepts of "BUGS code to define the model", which defines the hierarchical model structure, and is passed as an argument to the function nimbleCode(), with "NIMBLE DSL (domain specific language) code" which is used to specify statistical algorithms in the form of nimbleFunctions, and appears as an argument to the function nimbleFunction().
It looks like you're trying to define a hierarchical model. Here are a few things that you're doing wrong:
If you use "pi", then you'll have to pass that in as a "constant" in the constants=list(pi = 3.14...).
Can't use identityMatrix(), or matrix() in BUGS model code; only in the NIMBLE DSL (to define algorithms). If those are fixed constant matrices, (as for W), then use W[1:2, 1:2] freely in the BUGS model code, but pass in the value of that constant matrix through the constants list constants = list(W =diag(2)). Same goes for your other matrix, G.
If the matrix elements might vary, then define them one at a time, e.g.:
A[1,1] <- [some expression of other elements]
A[1,2] <- [some expression of other elements]
etc...
No use of c(...) function allowed, not yet. (feature soon to come). Instead use either:
c0[1] <- 0
c0[2] <- 0
then use c0[1:2], and c0[1], and c0[2] freely in the model code.
Alternative to those two definitions above, is to pass in the constant list(c0 = c(0,0)).
Unfortunately, your "m" term will get you into trouble here. The definition you have:
m<-G%*%x0
defines "m" as a 2x1 matrix, not as a vector, since matrix multiplication produces a matrix. So that's ok, but instead, use "m" in your code as:
m[1:2, 1]
That's all I see offhand. Sorry I can't try making these changes right now, but let us know how it works.
A quick favour to ask. We'd love to make the User Manual so clear that these things are all apparent. If you read the User Manual, and found parts of it confusing, or that led you to some wrong conclusions, can you please email us what section(s) or specific paragraph(s) were confusing, or misleading? That would be really helpful for us to fix them up!
Thanks,
Daniel
NIMBLE development team