Simple way to obtain posterior probability of slope >

I know that this is likely a very simple (stupid) beginner’s question, but is there a simple way to obtain the posterior probability that a slope is above or below some specific number (e.g., posterior probability that slope>25)? I assumed it was a possible option along with the HDI in pm.summary or az.summary, but do not see it. [I’m migrating from Bayes in Stata where this is a very simple “bayestest interval” command, and am sure it is equally simple here, but I am just not seeing it]
Thanks in advance for any direction.

Welcome! There very well may be a way to perform such operations via arviz, but they are also simple enough that you can just dig into the trace and ask your questions directly.

If you’re working with a MultiTrace object (what pm.sample() currently returns by default), then you can do something like this:

trace = pm.sample()
pgt25 = (trace['paramName'] > 25).mean()

If you are working with an inferenceData object (what pm.sample(return_inferencedata=True) returns, and all calls to pm.sample() will soon return by default), then you can do something like this:

trace = pm.sample(return_inferencedata=True)
pgt25 = (trace['posterior']['paramName'] > 25).mean(dim=['draw','chain'])

In both cases, you are simply converting all sampled values of paramName into a 0 or 1 depending on the truth value of the > 25 inequality. Taking the mean of these gives you the proportion of samples for which the inequality is true.

1 Like