How to get all values from a PyMC3 parameter of shape > 1?

have built an unpooled model in PyMC3:

with pm.Model() as unpooled:

  alpha = pm.Uniform('alpha',lower=-5,upper=5, shape=len(set(Y.values)))
  beta = pm.Normal('beta',mu=0,sd=1, shape=len(set(Y.values)))
  sigma = pm.Uniform('sigma',lower=0.01,upper=3)

  e = X['flavanoids'].values * beta[Y.values.astype(int)] + alpha[Y.values.astype(int)]
  y = pm.Normal('y',mu=e, sd=sigma, observed=Y.values)

  trace = pm.sample(2000)

I know that if the shape of beta was 1, I could have gotten the max probability estimate using:

ppc = pm.fast_sample_posterior_predictive(trace, samples=1_0000, var_names=['beta'])
preds = ppc['beta'].mean(0)

but since the shape is more than 1, I should get more the 1 value for it. how can I extract that value?

Welcome. Sorry for the delayed response! Try this:

index = 0

If you instead work with an inferencedata object (e.g., pm.sample(return_inferencedata=True)) then you index things slightly differently. But the above work for the default MultiTrace object.

1 Like

I’m not sure but I think we have changed the default return_inferencedata as True and a warning is shown if True or False isn’t given already. Although I don’t remember if that’s a case of development version or v3