How to get posterior of mixture components?

Hello,

This is a basic mixture example : 2 beta components to estimate the rate of an observed binomial. It samples well, and the posterior of the rate (r) looks ok.

Now I’d like to see the individual component posterior (c), but they are not in the trace.

How can I see or produce them ?

with pm.Model() as model:
    n = 2
    c = pm.Beta.dist(alpha=1,beta=1,shape=n)
    w = [1/2,1/2]
    r = pm.Mixture('r',w=w,comp_dists=c)
    
    obs = pm.Binomial('obs',n=[10000],p=r,observed=[5000])
    idata = pm.sample()
    az.plot_trace(idata)

Any help will be appreciated.

You would need to recover the posterior mixture indexes (which where marginalized by Mixture) and then resample the posterior of (r) with those indexes.

I don’t know if it was just for the sake of the example, but your components are completely symmetrical, so my guess is they look just like the (r). Furthermore your model does not even need the Mixture. You would have the same result just using one of the (c) directly.