Hi everyone,
I am trying to understand the way that PyMC sampler draws from an observed random variable acting as a covariate in a regression. I am still a beginner in statistical modeling so I apologize if there are any terminological issues in my question.
Let’s say I have the following model, where I want to put priors (x_mu, x_sigma) on the observed data of the covariate (x) in order to account for potential measurement errors:
x_mu = pm.Normal("x_mu",0,1)
x_sigma = pm.HalfNormal("x_sigma",1)
x = pm.Normal("x",x_mu,x_sigma,observed=x_observed)
a = pm.Normal("alpha",0,1)
b = pm.Normal("beta",0,1)
y_mu = pm.Deterministic("y_mu",a+b*x)
y_sigma = pm.HalfNormal("y_sigma",1)
y = pm.Normal("y",y_mu,y_sigma,observed=y_observed)
My understanding is that, depending on the implementation, the sampler could:
-
use the observed data from X directly to compute the posterior of Y, essentially ignoring the mu and sigma terms for the downstream inference, while separately computing the posterior of X from the given prior/observed data combo. In this scenario, the posterior of X is the same regardless of the values of Y.
-
jointly compute the posterior distributions of both X and Y based on their observed data/priors. In this scenario, the posterior of X depends on the values of Y.
-
do something else that I have not understood.
While I have generally assumed that #2 is what is happening under the hood, I have empirically observed that when I run a model like the below code (computing X without actually doing the regression), the posterior of x is the same as in the model above which includes the regression, which to me indicates that something closer to #1 is happening under the hood.
x_mu = pm.Normal("x_mu",0,1)
x_sigma = pm.HalfNormal("x_sigma",1)
x = pm.Normal("x",x_mu,x_sigma,observed=x_observed)
If someone could help me to understand, or let me know whether my question is completely missing the point, it would be great! Also happy to read whatever documentation already exists that might give me a clue.