Question

I am trying to fit an ANOVA model into rjags. The model is like this

for (r in 1:nE){
  for ( j in 1:nP){
    for ( i in 1:nA){
      logit(p[i,j,r]) <- mu[r] + theta[i,r] + varphi[j,r] + psi[(nA-i)+j,r]
    }
  }
}

And I need to fit in the constraints that

for (r in 1:nE){
  theta[nA,r] <- 0 - sum(theta[1:(nA-1), r])
  varphi[nP,r] <- 0 - sum(varphi[1:(nP-1), r])
  psi[nK,r] <- 0 - sum(psi[1:(nK-1), r])
}

which is the sum to zero constraints for this model. However, rjags gives me the message

"Compilation error on line 14. Attempt to redefine node varphi[16,1]"

If I delete the constraint part, the model compiled just fine but will not converge. In BUGS, the model is accepted.

How can I implement these constraints in rjags?

Was it helpful?

Solution

You have two options:

  1. Make new zero sum variables (don't redefine the old ones) and monitor them instead.

  2. Reparameterize the model to use a corner constraint rather than summing to zero.

1 is the better option since the new variables will probably converge faster. See Ntzoufras' book, (ch.5), sec. 5.4.2 for a discussion and also the relevant bugs code. This should also work for jags, although I haven't checked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top