Dear all,

I am trying to rewrite code that was written in WinBUGS to JAGS code.

The code I want to use is the following:

model{ for( i in 1 : nmz ){ g2mz[i, 1:N] ~ dmnorm(mu[1:N],tau.g[1:N, 1:N]) g1mz[i, 1:N] ~ dmnorm(g2mz[i, 1:N],tau.g[1:N, 1:N]) esmz[i] <- g1mz[i, 2] eemz[i] <- g1mz[i, 1] for(j in 1:2){ ermz[i, j] <- g1mz[i, 3] + esmz[i] * emz[i, j] emz[i, j] ~ dnorm(eemz[i],tau.e) rmz[i, j] ~ dnorm(ermz[i, j],tau.r) smz[i, j] ~ dnorm(esinmz[i],tau.s) esinmz[i] <- beta[1] + beta[2] * esmz[i] } } for (k in 1:N){ for (l in 1:N){ sigma2.g[k,l] <- inverse(tau.g[,],k,l)*2 # sigma2.g is genetic covariance matrix } } #Priors tau.g[1:N, 1:N] ~ dwish(omega.g[,], N) mu[1:N] ~ dmnorm(mean[],precis[,]) tau.e ~ dgamma(0.001,0.001) tau.s ~ dgamma(0.001,0.001) tau.r ~ dgamma(0.001,0.001) beta[1:2] ~ dmnorm(mbeta[],prbeta[ , ]) }

The code is adapted from the article 'Markov chain Monte Carlo Approaches to Analysis of Genetic and Environmental Components of Human Development and G x E Interaction' by Eaves and Erkanli (2003, Behavior Genetics). However, when I try to run the code, I am getting the following error message:

Compilation error on line 3.

Unable to resolve node mu[1:3]

This may be due to an undefined ancestor node or a directed cycle in the graph

While searching the internet for any helpful resources, I found out that in JAGS, the multivariate normal distribution has to be specified as dmnorm(mu, Omega) (http://www.jrnold.me/blog/jagsopenbugs-to-stan-distributions.html), so I changed the code to the following:

model{ for( i in 1 : nmz ){ g2mz[i, 1:N] ~ dmnorm(mu,tau.g) ## CHANGED CODE ! g1mz[i, 1:N] ~ dmnorm(g2mz, tau.g) ## CHANGED CODE ! esmz[i] <- g1mz[i, 2] eemz[i] <- g1mz[i, 1] for(j in 1:2){ ermz[i, j] <- g1mz[i, 3] + esmz[i] * emz[i, j] emz[i, j] ~ dnorm(eemz[i],tau.e) rmz[i, j] ~ dnorm(ermz[i, j],tau.r) smz[i, j] ~ dnorm(esinmz[i],tau.s) esinmz[i] <- beta[1] + beta[2] * esmz[i] } } for (k in 1:N){ for (l in 1:N){ sigma2.g[k,l] <- inverse(tau.g[,],k,l)*2 # sigma2.g is genetic covariance matrix } } #Priors tau.g[1:N, 1:N] ~ dwish(omega.g[,], N) mu[1:N] ~ dmnorm(0, .1) # ## CHANGED CODE ! tau.e ~ dgamma(0.001,0.001) tau.s ~ dgamma(0.001,0.001) tau.r ~ dgamma(0.001,0.001) beta[1:2] ~ dmnorm(mbeta[],prbeta[ , ]) }

However, I am still getting the same error. I have no experience in using multivariate distributions in JAGS, could anyone point me to the error?

I believe that the error is somewhere in the specification of the distribution. However, if it is helpful to have any example R code to run the model, please let me know!

Many thanks,

Inga Schwabe