How to get the probabilities of this PyMC3 model?

I just started with pymc and I’ve been documenting myself for a weeks :slight_smile:
Maybe it’s a very stupid question but I can’t find how can I get the probabilities of
P(theta = '1'|y = '80')
P(y = '50'|theta = '3')
P(theta = '1', y = '80')

and get the graphic P(theta|y).
(Note that my prior is theta, my prior is discrete and my ‘y’ distribution is continuous, so for me it’s valid to find the range of 80.0 to 80.99 for example)

in this simple model:

import pymc3 as pm

num_people = 100

with pm.Model() as model:

theta = pm.BetaBinomial('θ', alpha=1., beta=1.,n=num_people)
y = pm.TruncatedNormal('y', mu=theta, sigma=15, lower=0.0, upper=101.0)
trace = pm.sample(10000, cores=1)

I’d appreciate any help,

Hi, John! Your post is a little confusedly worded - when you say you want P(theta = '1'|y = '80'), it sounds like estimating the probability of variable A \ \text{being} = 80, given variable B \ \text{being} = 1, which sounds like fitting the joint distribution, but then you say theta is your prior.

Could you clarify what you mean?

Hi Gon_F !
Yes ! It sounds like the first scenario you told me !
One of the probabilities I want to calculate is the probability of theta = ‘1’ (in the beta binomial) and y = ‘80’ (range 80-80.99 because it’s continuous ).
Maybe I have a misunderstanding with the concept of get the probabilities with pymc3.

You can use the samples from the posterior trace to do this numerically.


mask = np.logical_and(trace[‘y’]>80, trace[‘y’]<81)
np.mean(trace[‘theta’][mask]==1) ##equals 0.00


mask = trace[‘theta’]==3
np.logical_and(trace[‘y’][mask]>50, trace[‘y’][mask]<51).mean() ##equals 0.00


np.logical_and(np.logical_and(trace[‘theta’]==1, trace[‘y’]>80), trace[‘y’]<81).mean() ##equals 0.00

I’m not sure if you have the correct numbers though as all of these probabilities equal zero with my 20,000 samples. For the first question if y is 80 then for theta (mu of normal) to be only 1 would mean it’s over 5sd away, this is extremely unlikely in a Normal.