Shark Attack – Episode 2

We have created the background on the Shark attack problem to explain how Bayesian inference operates for updating knowledge of an event, in this case, a rare one. Let’s have a quick recap first. We chose Poisson distribution to describe the likelihood (the chances of that data on attacks, given a particular set of occurrences) because we knew these were rare and uncorrelated events. And the Gamma for describing the prior probability of occurrences as it can give a continuous set of instances ranging from zero to infinity.

And if you like to know how those two functions work, see the following two plots.

The first plot gives the probability of one occurrence, two occurrences, 3, 4, 5, 6 …, when the mean occurrence is five. The value the X-axis take is discrete: you can not have the probability of 1.8 episodes of a shark attack!

The second plot provides the probability of the parameter (occurrence or episode) through the gamma pdf using those two hyperparameters, alpha and beta.

Bayesian Inference

The form of Bayes’ theorem now becomes.

P(\lambda|Data) = \frac{P(Data|\lambda) P(\lambda)}{\int P(Data|\lambda) P(\lambda) d\lambda}

Then the magic happens, and the complicated looking equation solves into a Gamma distribution function. You will now realise the choice of Gamma as the prior was not an accident, but it was because of its conjugacy with the Poisson. But we have seen that before.

The Posterior

The posterior is a Gamma pdf with the following hyperparameters.

\\ \alpha_{posterior} = \alpha_{prior} + \sum\limits_{i=1}^{n}} x_i \\ \\ \beta_{posterior} = \beta_{prior} + n  \\ \\ \text{n is the number of ovservations and } x_i \text{ are the observations} \\ \\ \text{in our case}, n = 1 \text{ and } x_1 = 10, \text{ the only observation, and therefore, } \\ \\ \alpha_{posterior} = 5 + 10 = 15\\ \\ \beta_{posterior} = 1 + 1 = 2\\ \\ \text{Remember, we have chosen } \alpha = 5 \text{ and } \beta = 1 \text{ as priors (see previous post)}.

And, if you want to see the shift of the hypothesis from prior to posterior after the evidence,