I’m trying the set up a multilevel model so that prior samples from a child variable have a standard deviation of 1 (taking into account the dispersion of the parent variable). For example, in the below:
with pm.Model() as my_model:
parent = pm.Normal('parent', mu=0.0, sigma=shared_sd)
child = pm.Normal('child', mu=parent, sigma=shared_sd)
I want to set shared_sd
such that the prior samples from child
have an SD of 1. I couldn’t figure out a simple way to calculate shared_sd
in closed form, so I tried to use pymc to estimate it for me as follows:
with pm.Model() as my_model:
shared_sd = pm.HalfNormal('shared_sd', sigma=1.0)
parent = pm.Normal('parent', mu=0, sigma=shared_sd)
child = pm.Normal(
'child', mu=parent, sigma=shared_sd,
observed=np.random.normal(0, 1, 10000)
)
idata = pm.sample()
Sampling looks fine but I’m getting unexpected posteriors:
Shouldn’t the posterior variance of parent
be dictated by shared_sd
here?