How to keep dimensions in a posterior predictive sample?

Thanks again. Here’s what I came up with:

plausible_counts = dict()
fig, axs = plt.subplots(1,2)
for i, (etype, mus) in enumerate(trace.posterior.groupby('Event Types')): 
    mus_for_type = mus.stack(n=('chain', 'draw'))
    num_mus = 100
    num_samples = 200
    possible_mus = gaussian_kde(mus_for_type['mu']).resample(num_mus)
    plausible_counts[etype] = poisson(possible_mus).rvs([num_samples, num_mus]).reshape(num_mus * num_samples)
    axs[i].hist(plausible_counts[etype], bins=30, density=True, stacked=True)
    axs[i].axvline(plausible_counts[etype].mean(),color='red')
    axs[i].set_xlabel(f"Event type: {etype}")
    
    
for etype, counts in plausible_counts.items():
    print(f"{etype} | Mean: {counts.mean()}, 15%: {np.quantile(counts, 0.15)}, 85%: {np.quantile(counts, 0.85)}")

And the results look alright to me -
image

Thanks for the help!

1 Like