if-statementjagswinbugs

If-else condition in JAGS/BUGS


I've got large matrix of parameters.

The point is that among many parameters some parameters with arbitrary indexes induce value errors and I'd like to fix them.

The toy example is as follows:

foo[3, 2] <- mu[3, 2]    # mu is some (4,4) matrix from data input

for (r in 1:4) {
  for (c in 1:4) {
    foo[r, c] ~ dnorm( mu[r, c], .01 )
  }
}

I see some examples like 15414303 and 46730232, but I cannot wrap my head around the problem how to apply those tricks (or similar) in my case.

Is there a simple way to implement such a logic in JAGS / BUGS?


Solution

  • The simplest way would be to supply foo in the data where all entries beside foo[3,2] are missing and foo[3,2] is mu[3,2]. Then, the code you have above should work fine (if you remove the definition of foo[3,2] in your code). The alternative would be to define the loops around the fixed cell. For example:

    for(r in c(1,2,4)){
      for(c in 1:4){
        foo[r, c]  ~ dnorm( mu[r, c], .01 )
      }
    }
    for(c in c(1,3,4)){
      foo[3, c] ~ dnorm( mu[r, c], .01 )
    }