Probability of a certain value in a discrete distribution

Hi Eduardo

The error is due to the fact that you are asking for the logp of the model yet you only supply one input. The model has two distributions: ‘x’ and ‘id’, so your logp request needs two inputs. A further complication is that PyMC3 has transformed your ‘id’ behind the scenes within the model. I’m not sure if accessing the model’s logp is the best approach for you. It might help if you further explain what you want to achieve.

In any case from the code you have presented there is no link between ‘x’ and ‘id’, so they are independent. You can get the logp of ‘x’ separately from ‘id’. You could construct two different models.

I usually extract stats from either the posterior or prior depending on what I want. In your case you could do

np.mean(trace['x']==36) #equals 0.0084

and for continuous distributions you can look at ranges

np.mean( np.logical_and(trace['id']>(13e6-500e3), trace['id']<(13e6+500e3)) ) #equals 0.0123

A further point is that PyMC3 works best with smaller absolute numbers. ID values should start at zero and increment by 1 as integers. A common approach is to standarise both x and y. So subtract means and divide by standard deviations.
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html

2 Likes