There is a priors
argument in traceplot
, but it isn’t intuitive to use at all. Currently I call the function as pm.traceplot(trace, varnames, priors=[getattr(model[n], 'distribution', None) for n in varnames], combined=True)
, and it provides expected results for my cases (visually). But as I couldn’t find anything like this neither in documentation nor in discussion, I’m not sure if that’s always correct and will not give some nonsense results sometime? Or maybe there is a more straightforward method for this, as plotting priors taken from a model looks like the most common usecase for priors
argument?
2 Likes
Yeah I dont think many ppl is using it, as it gets quite confusing with multi-chain and/or multivariate RVs. It is great for demonstration purpose in low dimension toy problems, a use case is something like this:
with pm.Model() as m:
mu = pm.Normal('mu', 0, 1)
sd = pm.HalfCauchy('sd', 1.5)
obs = pm.Normal('obs', mu, sd, observed=np.random.randn(10)*2.5+1)
trace = pm.sample()
pm.traceplot(trace,
combined=True,
priors=[pm.Normal.dist(0., 1), pm.HalfCauchy.dist(2.5)]);
# this is also allow
pm.traceplot(trace,
combined=True,
priors=[mu.distribution, sd.distribution]);
So yes I think what you are doing is correct at least in univariate cases.
Ok, thanks for confirmation
And I personally often use such prior-plots when I suspect that the prior may have a strong influence. Multi-chain doesn’t look like a problem, as combined=True
is needed even without prior-plots when there are multivariate RVs: otherwise the plots are way to messy.
2 Likes