Error:"Multiple definitions of node" in OpenBUGS.

543 Views Asked by At

So I thought the following code would work in OpenBUGS, but instead it gives me a "Multiple definitions of node Z" error.

model
{
 Z <- round(X)
 X ~ dnorm(0,1)T(-2,2)
}

list(Z=0)

Even if I replace Z <- round(X) with Z <- X I continue to get the same error. From this fact we can deduce that the error is resulting from the use of a logical assignment for an observable variable and in particular, the error is not due to the round() operation.

Why does BUGS not allow this? Also, what is a good work-around in this case? Here is a more general version that I want to implement, which is essentially modeling a discrete Gaussian with walls (the truncation):

model
{
 for(i in 1:N){
   Z[i] <- round(X[i])
   X[i] ~ dnorm(mu,1)T(-2,2)
 }
mu ~ dunif(-2,2)
}

Essentially, I want Z to be distributed with something like a discrete Gaussian with "walls" (the truncation) and I want to estimate mu from data on Z. I suppose I can try to make Z into a categorical variable and estimate the parameters but this seems theoretically painful. Is there some BUGS trick I can use to get my intended model?

1

There are 1 best solutions below

0
On

WinBUGS and OpenBUGS don't allow observed data to be a deterministic function of an unobserved variable. As you suggest, you could use dcat() and express the probabilities in terms of the normal distribution.

Though you might prefer to switch to JAGS, which has a distribution dround() that deals with just this situation - data that are rounded to n significant digits, in your case n=0. Though this forum post suggests there's a bug in the current stable release for this case, and you might need to download the development version.