Linear model where predictor also being sampled?

I dont think this could be done straightforwardly, as you are trying to generate random sample from one of the node in the Bayesian model and use the sample as observed. A similar discussion come to mind which you can have a look: Call MvNormal.random() method inside model

In your case, since a_i and b_i are observed, which means x_i are observed as well (no stochastic), which means the model becomes 3 separate one: y_i ~ N( , ), a_i ~ MN(), and b_i ~ MN().
What I think you should do, is x_i = |\mu_{ai}-\mu_{bi}|, or x_i = |a_i'-b_i'| with a_i \sim N(a_i', sd) (sd could be a small value). Now that all the unknowns are latent, you can do whatever computation with them within a model and assign observation, and just let the sampler take care of the sampling part. A similar idea see the first part of https://junpenglao.xyz/Blogs/posts/2017-10-23-OOS_missing.html

1 Like