Difference between observed stochastic and fixed tensor in a hierarchical model

Hello everyone,

I am building a hierarchical model. When setting a distribution parameter either to an observed stochastic or to a fixed value (using option1 or option2 below), I get slightly different results.

#option1
obs_x = pm.Normal(‘obs_x’, mu=eta[:, 0], sd=meas_noise_x, shape=N, observed=x_noisy)
obs_y = pm.Normal(‘obs_y’, mu=eta[:, 1], sd=meas_noise_y, shape=N, observed=y_noisy)

#option2
x_noise_dist = pm.Uniform(‘x_noise_dist’, 0, 2, observed=meas_noise_x)
y_noise_dist = pm.Uniform(‘y_noise_dist’, 0, 2, observed=meas_noise_y)
#obs_x = pm.Normal(‘obs_x’, mu=eta[:, 0], sd=x_noise_dist, shape=N, observed=x_noisy)
#obs_y = pm.Normal(‘obs_y’, mu=eta[:, 1], sd=y_noise_dist, shape=N, observed=y_noisy)

The difference in the mean value for the different parameters is similar to mcse_mean and mcse_sd, but sometimes slightly larger. Could you please explain me what is the difference in assumptions between these two implementations?

Thank you for this great platform and the discussions!

Pedro

The two should be identical up to a constant, so the difference you observed is likely due to numerical and mcmc error.

For more detail, in option 2 x_noise_dist takes the value from observed, and added a constant to the log_prob since it has no dependence.

1 Like