2.6 Summary
In this section we summarize the chapter by doing a simple example that can be solved by direct calculation.
In the 2020 season of the Swedish football league Allsvenskan there was 488 goals scored in 240 games. Assume that \(X_1, \ldots X_{488}\), the number of goals scored in each game, are i.i.d and distributed as \(\mathsf{Po}(\lambda)\). We wish to do Bayesian inference on the unknown parameter \(\lambda\).
First we find the likelihood. Since the probability function of a Poisson distributed random variable is \[ p(x) = \frac{\lambda^x e^{-\lambda}}{x!},~x = 0,1,2\ldots, \] if we denote the number of goals in game \(i\) by \(x_i\), the total likelihood is \[ L(\lambda) = \prod_{i=1}^{n} \frac{\lambda^{x_i} e^{-\lambda}}{x_i!} \propto \lambda^{\sum x_i}e^{-n\lambda}. \]
Then we decide on an appropriate prior distribution. Since \(\lambda >0\) we should choose a distribution with all probability on the positive real numbers. A convenient choice, it turns out, is the gamma distribution. Let us choose the parameters of the gamma distribution based on our subjective (prior) belief. As prior belief we will say that the mean of \(\lambda\) should be 3, and that it is unlikely that the average number of goals is larger than 5. Since \(\lambda \sim \mathsf{Gamma}(\alpha,\beta)\) implies that
\[ E\left[ \lambda \right] = \frac{\alpha}{\beta}, \]we will choose \(\beta = \alpha/3\). It remains to choose \(\alpha\). To do this we plot the density for different choices of \(\alpha\).
Figure 2.7: Density of the gamma distribution
Based on this picture we decide that \(\alpha = 20\) fits with our prior beliefs.
Now we shall calculate the posterior distribution. The prior distribution has the density (from a textbook) \[ p(\lambda) = \frac{\beta^\alpha}{\Gamma(\alpha)} \lambda^{\alpha-1} e^{-\beta\lambda}. \] Therefore the posterior distribution has density \[ p(\lambda \mid x) \propto L(\lambda)p(\lambda) \propto \lambda^{\sum x_i}e^{-n\lambda} \lambda^{\alpha-1} e^{-\beta\lambda} = \lambda^{\alpha + \sum x_i - 1}e^{-\lambda(\beta + n)}. \]That is, the posterior distribution is \(\mathsf{Gamma}(\alpha + \sum x_i, \beta + n)\). With our prior we therefore get the posterior \(\mathsf{Gamma}(518, 246.7)\), illustrated in the figure.
Figure 2.8: Density of the posterior distribution when prior is subjective
The mean of the posterior, and our point estimate of \(\lambda\) is \(518/246.7 \approx 2.1\) and a 95% credibility interval is given by
lower <- qgamma(0.025, shape = 518, 20/3 + 240)
upper <- qgamma(0.975, shape = 518, 20/3 + 240)
c( lower, upper )## [1] 1.923027 2.284652
We could instead use a flat prior \(p(\lambda) = c, \quad \lambda>0\). Note that this corresponds to a \(\mathsf{Gamma}(1,0)\) distribution. So we may recycle the above calculations which gives the posterior \(\mathsf{Gamma}(489,240)\).
Figure 2.9: Density of the posterior distribution when prior is flat
Now our point estimate of \(\lambda\) is \(489/240 \approx 2\) and a 95% credibility interval is given by
## [1] 1.860889 2.222002
We could also use Jeffreys prior which is proportional to the square root of the Fisher information. The Fisher information can be calculated, for example, as \[ I(\lambda) = Var(l'(\lambda)). \] The log-likelihod and its derivative is \[\begin{align} l(\lambda) &= \sum_{i=1}^n\left( -\ln x_i! + x_i\ln \lambda - \lambda \right)\\ l'(\lambda) &= \sum_{i=1}^n\left( \frac{x_i}{\lambda} -1 \right) = n\left( \frac{\bar x}{\lambda} -1 \right). \end{align}\] Which gives \[ I(\lambda) = Var\left(\frac{n\bar X}{\lambda} \right) = \frac{n^2}{\lambda} Var\left(\bar X\right) = \frac{n^2}{\lambda}\frac{\lambda}{n} = \frac{n}{\lambda}. \] Then, finally, Jeffreys prior is \(p(\lambda) \propto \lambda^{-1/2}\), corresponding to \(\mathsf{Gamma}(1/2,0)\) and then the procedure follows the same steps as above.