Cannot plot_posterior with several dimensions

Hello everyone!

I have a model which has two cases enconded in df[‘membrane_enc’], so this should give two indepently modelled likelyhoods and posteriors. I train the model in this fashion:

shape = df['membrane_enc'].unique().shape
with pm.Model() as my_model:
    tau = pm.HalfNormal('tau', sigma=1.,shape =shape)
    tau_0 = pm.TruncatedNormal('tau_0', mu = min_val, sigma = 1, lower = 0, upper = min_val, shape =shape)
    like = DensityDist('like', logp_exp_lag(tau_0[df['membrane_enc']],tau[df['membrane_enc']]), observed=df['tpore'], random=custom_random, shape = (2,180))
with my_model:
    my_model_trace = pm.sample(4000, tune=3000,  random_seed=RANDOM_SEED)
    ppc = pm.sample_posterior_predictive(my_model_trace, var_names = ['like'],  random_seed=RANDOM_SEED)
    my_model_trace = az.from_pymc3(trace=my_model_trace, model=my_model, posterior_predictive=ppc)
    my_model_trace.to_netcdf(model_path)

The model converges nicely and gives reasonable posteriors for the two encodings. The problem comes when I try to plot the posterior predictive. I cannot find the way to plot the two distinct ppc’s in two graphs:

az.plot_ppc(my_model_trace, random_seed=RANDOM_SEED, var_names = ['like'], flatten = [])

This code fails and I am not sure which dimension I should flatten since there is only one in my_model_trace, like_dim_0 and it doesn’t work. All this code works nicely if you only work with one dimension.

Can someone please help me make this plotting work?

Thank you very much in advance!
Best,
Sergio

1 Like

If I am not mistaken, this has been solved in Posterior predictive check (plot_ppc) with dataframe encoding. · Issue #1461 · arviz-devs/arviz · GitHub in case someone with the same issue finds his post instead of the issue.