Using traceplot to compare different posteriors?

Can I use traceplot to compare different posteriors rather than multiple samples from the same posterior?

From my favourite primer book (so far) we have something along the lines of:

with pm.Model() as our_first_model:
    theta = pm.Beta('theta', alpha=1, beta=1)
    y = pm.Bernoulli('y', p=theta, observed=data)
    start = pm.find_MAP()
    step = pm.Metropolis()
    multi_trace = pm.sample(1000, step=step, njobs=4)
    pm.traceplot(multi_trace, lines={'theta':theta_real});

What I’m effectively looking to do is create an equivalent to multi_trace from more than one model posterior. Is this possible?

I dont think it is generally advisable to compare posterior from different models, unless these models are nested together.
If they are nested together, and you want to compare the posterior density, it might be easier plot the density. For example, you can use density plot from seaborn:

_, ax=plt.subplots(1,1,figsize=(8,5))
sns.distplot(trace1['x'], ax=ax, label='model 1')
sns.distplot(trace2['x'], ax=ax, label='model 2')
1 Like

To my mind, it’s very useful to be able to compare the same model with different priors on an overlaid graph, especially when you’re new to the field and want to explore the effects of changing the prior.


Hi @DoctorRad

The last version of pm.forestplot() (from master) supports multiple traces. Also there is a new function pm.densityplot() that can be used to plot more than one trace. This is an example of how these plots looks like.