I am trying to use Bayes theorem to estimate the probability of a binary event. To give a (simplified) example: Let's say our a priori guess of the probability of the event per trial is 0.3 (and the probability of no event is 0.7). We use the model parameter $\beta > 0$ to scale this a priori guess, so that the probability of an event can be expressed as $p=0.3^{\beta}$. The parameter $\beta$ is estimated in the Bayesian framework, hence the posterior distribution is calculated as $\pi(\beta\mid Y) \propto \pi(\beta) L(Y\mid\beta)$, where $L(Y\mid\beta)=\prod \left(0.3^{\beta}\right)^{Y_i} \left(1-0.3^{\beta}\right)^{1-Y_i} $ and $Y_i$ denotes the outcome of the $i$th trial. As (reasonably uninformative) prior distribution for $\beta$ I use $\pi(\beta)=Gamma(shape=1,rate=1)$. The median of the posterior distribution is going to be used as best estimate to scale the probability, but other quantiles may be of interest, too. I have implemented this simple model in OpenBUGS and checked it with an R package (bcrm) which uses RJags and the results were the same. For example, if we observed three trials, and no event occured, the posterior median of $\beta$ is $1.19$, corresponding to posterior probability $0.3^{1.19}=0.24$, which seems to be a reasonable conclusion.

So, here comes the issue: I would also like to express my prior belief with an informative prior distribution for $\beta$. I thought, a natural choice would be to use $Gamma(shape=20,rate=20)$, since the mean would be again at 1, while it is more centered around 1 compared to $Gamma(1,1)$. But with this prior distribution, the posterior distribution is totally misleading, at least if there are no events observed. If again, we have 3 trials but 0 events, the posterior median of $\beta$ is calculated to be $96.6$, corresponding to a probability of event $0.3^{96.6}=0.00000000$, which is not at all what I would have expected, since the prior distribution of the probability was more centered around 0.3? What is happening here?

I am pretty sure, I am missing basic properties of either the Gamma distribution or Bayesian inference (or both), so I would be glad if someone could point these out to me.

For visualization, I've added images of the histograms of random values from the distribution of both prior distribution and the corresponding prior scaled probabilities. enter image description here

enter image description here


One does not need packages to check the posterior: a simple call to curve and defining


shows that the outcome is correct:

enter image description here

Hence there is a mistake in the derivation of the posterior median.

| cite | improve this answer | |
  • 1
    $\begingroup$ Many thanks for pointing this out, Xi'an! With all these MCMC methods, sometimes I forget how simple the actual calculations can be... indeed, there was a simple mistake in my BUGS code, where rate and scale were confused. Funnily, the exact same mistake appears to be in the package that I used, so I was entirely sure, that my script must be correct. $\endgroup$ – LuckyPal Jul 27 '18 at 14:10
  • $\begingroup$ rate versus scale is the most common mistake with gammas! $\endgroup$ – Xi'an Jul 27 '18 at 16:31

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.