I am pretty new to bayesian statistics and PyMC3. I am doing a hierarchical model where the output variable I am trying to predict is a percentage with a maximum of 100%. My problem is that my posterior distribution includes values greater than 100% which is impossible in my situation. I configured my Y values as being Normally distributed. Here is some part of my code, not including the prior definitions to make it briefer.

a = pm.Normal('alpha', mu=mu_a, sd=sigma_a, shape=len(uniqueStores)) b = pm.Normal('Shift1Score', mu=mu_b, sd=sigma_b, shape=len(uniqueStores)) score_est = a[storeIDX] + (b[storeIDX] * audits.Shift1Score.values)

y_like = pm.Normal('y_like', mu=score_est, sd=eps, observed=audits.FinalScore)

I get posterior distributions like thoses: Posterior

I was wondering if there some other distribution I could use to force a maximum of 100%. Maybe use a HalfNormal somehow. The problem with Half Normal is that I can't control the mean, it is at 0.

I was thinking that I could maybe us 1 - audits.FinalScore which would make the scores start from 0 but then I still can't change the mean of that distribution.

Thank you!

  • 1
    $\begingroup$ Usually, you specify this sort of thing by defining bounds on parameters, then using the truncated distribution. I know this is possible in Stan, and googling suggests that you can use Bound to do this in pymc3: docs.pymc.io/api/bounds.html $\endgroup$
    – AJK
    Dec 24, 2017 at 2:47
  • $\begingroup$ Oh thanks this helps! But I cant specify observed data in a bounded distribution though which is what I was trying to do. $\endgroup$
    – EtienneT
    Dec 24, 2017 at 3:33

1 Answer 1


While there are more general approaches to handling bounded parameters like AJK mentioned, in your case you can try some distributions that are designed to describe probability of probabilities, such as Beta distribution, or use sigmoid function as your output.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.