# Introducing observation errors in jags code

I want to introduce observations errors around my data in Jags, but I face some trouble coding it without having a double definition error on node Y3

So far I have :

log_Y1_real[y]~dnorm(log(Y1[y]),prec_obs_Y1)     #Y1 is one variable
log_Y2_real[y]~dnorm(log(Y2[y]),prec_obs_Y2)     #Y2 is another variable
Y1_real[y]<-exp(log_Y1_real[y])
Y2_real[y]<-exp(log_Y2_real[y])

Y3_real<-log(Y1_real/Y2_real)     # My model is fit on Y3,defined as log(Y1/Y2), which should integrate obs error from Y1 and Y2

Y3_real~dnorm(mu_Y3,prec_Y3)           #then the model..
muY3~model....


Thanks a lot for your insights !

• Hi Ben and welcome to the site! If you can, please post a reproducible example of your code, including data (so that we can reproduce your error). In this case, the error is clear: You define Y3_real as a stochastic node with the tilde ~ and you define it as fixed node above <-. This is why you get a double definition error. Further: You may want to expand your question a little and explain what you exactly mean by "introducing observation errors". – COOLSerdash Jul 9 '13 at 12:53
• Thanks for the answer @COOLSerdash, posting code and data might be a hassle right now as this is a small part of a bigger code. Y1 and Y2 are observed variables, we know there are some observation error on them (e.g. CV 20 %) and we want to integrate the idea our observations aren't exactly the "true" value. So the Y3 (which is a combination of Y1 and Y2, Y3= log(Y1/Y2)) to which the model is fitted should itself be a stochastic node, and I don't know how to work around it without facing the double definition you mention. – Ben Jul 9 '13 at 13:07
• Thanks for the explanations. A few comments: 1) Why do Y1_real and Y2_real not have indices when calculating Y3_real? 2) Y3_real can't itself be a stochastic node if it depends on Y1_real and Y2_real 3) I'm not sure, but I think the bayesian model takes the observation uncertainty into account without the need to specify it specifically. – COOLSerdash Jul 9 '13 at 13:23
• I took of the indices to make it clear but that's all within a loop on observations. For the second point observation error should be added specifically (and the level of this error as well) – Ben Jul 9 '13 at 13:48
• A really good guide to doing exactly what you want in BUGS/JAGS can be found here: mbjoseph.github.io/blog/2013/05/27/typeII . – Rasmus Bååth Jul 26 '13 at 19:31