3 Bayesian Parameter Estimation
Learning Objectives
After studying this chapter, you should be able to:
Apply Bayes’ theorem to update prior beliefs with observed data
Identify and use conjugate priors for common likelihood functions and interpret hyperparameters as pseudo-observations
Compute Bayesian point estimates (mean, median, mode) and identify the loss functions they minimize
Derive posterior predictive distributions for future observations
Compare Bayesian and frequentist estimators from both perspectives
Recognize exponential family distributions and their sufficient statistics
3.1 From Prior to Posterior
In the Bayesian philosophy, unknown parameters are viewed as random. So, our knowledge about the parameter can be encoded as a distribution. The distribution representing our belief before observing the data is called the prior distribution. After we observe the data, our belief changes, resulting in the posterior distribution.
Specifically, the components of a Bayesian estimation problem are:
Data \({{\boldsymbol{x}}}\): The data is a realization of a random variable \({{\boldsymbol{X}}}\). The distribution of \({{\boldsymbol{X}}}\) depends on a parameter \(\Theta\).
Parameter \(\Theta\): The parameter of the distribution of \({{\boldsymbol{X}}}\), which is unknown, and hence a random variable in the Bayesian framework.
Joint and marginal distributions \(p\): A joint distribution \(p_{{{\boldsymbol{X}}},\Theta}\) and its marginals \(p_{{{\boldsymbol{X}}}}\) and \(p_\Theta\).
The steps of Bayesian estimation of a parameter \(\theta\) are:
Identifying the prior distribution, \(p_\Theta(\theta)\). This is called the prior because it encodes our beliefs about \(\Theta\) before seeing any data.
Collecting data \({{\boldsymbol{x}}}\) and forming the likelihood: \(p_{{{\boldsymbol{X}}}|\Theta}({{\boldsymbol{x}}}|\theta)\)
Finding the posterior distribution \(p_{\Theta|{{\boldsymbol{X}}}}(\theta|{{\boldsymbol{x}}})\) as \[\begin{equation} \begin{split} p_{\Theta|{{\boldsymbol{X}}}}(\theta|{{\boldsymbol{x}}}) & = \frac{p_\Theta(\theta)p_{{{\boldsymbol{X}}}|\Theta}({{\boldsymbol{x}}}|\theta)}{p_{{\boldsymbol{X}}}({{\boldsymbol{x}}})}, \end{split} \end{equation}\] The distribution \(p_{\Theta|{{\boldsymbol{X}}}}\) is called the posterior distribution since it encodes our knowledge about the parameter after observing the data. Usually, since the distribution is clear from the argument, we drop the subscripts of \(p\), writing the above equation as \[\begin{equation} \begin{split} p(\theta|{{\boldsymbol{x}}}) & = \frac{p(\theta)p({{\boldsymbol{x}}}|\theta)}{p({{\boldsymbol{x}}})}, \end{split} \end{equation}\]
Normalizing distributions. Finding the posterior distribution requires computing the integral \(p({{\boldsymbol{x}}}) = \int_{\theta} p(\theta)p({{\boldsymbol{x}}}|\theta)d\theta\). Since we have to compute an integral anyway, we might as well drop all multiplicative terms that are constant in \(\theta\) and then normalize the final distribution. In particular, \(p({{\boldsymbol{x}}})\) is one such term. So we often first find a function proportional to \(p(\theta|{{\boldsymbol{x}}})\) as \[\begin{equation} p(\theta|{{\boldsymbol{x}}})\propto p(\theta)p({{\boldsymbol{x}}}|\theta), \end{equation}\] where we can also drop constant terms in \(\theta\) from \(p(\theta)\) and \(p({{\boldsymbol{x}}}|\theta)\). We can then normalize the result by integration. This is often difficult to do. Sometimes, given this function, we can identify the distribution. More generally, we can use computational methods, such as Markov Chain Monte Carlo, or approximation methods, such as variational inference, as we will see later. Finally, in certain cases, we can find what we need without any integration. For example, if our goal is to find the value of \(\theta\) maximizing \(p(\theta|{{\boldsymbol{x}}})\).
Example 3.1 Estimating a geometric parameter
Let \(\Theta\) denote the unknown parameter of a geometric random variable \(X\), where \[p_{X|\Theta}(x|\theta)=\theta(1-\theta)^{x-1}.\] Suppose we observe \(X=x\). We would like to estimate \(\Theta\) based on this observation. If all possible values of \(\Theta\) are equally likely, we may choose \(\Theta\sim\mathop{\mathrm{\mathrm{Uni}}}(0,1)\). We then have \[\begin{align} p(\theta) &=1\\ p(x|\theta) &=\theta(1-\theta)^{x-1}\\ p(\theta|x) &\propto p(\theta)p(x|\theta)\propto\theta(1-\theta)^{x-1} \end{align}\] The expression \(\theta(1-\theta)^{x-1}\) as a function of \(x\) is the geometric distribution. But as a function of \(\theta\), it is proportional to \(\mathop{\mathrm{\mathrm{Beta}}}(2,x)\). As an example, if \(x=3\), then \(\Theta|x\sim\mathop{\mathrm{\mathrm{Beta}}}(2,3)\):
Exercise 3.2 One Bernoulli trial
The probability of 1 (success) in a Bernoulli experiment (e.g., flipping a coin, a system working or not working, etc) is \(\Theta\), which we would like to estimate. Suppose that the experiment is performed once and the outcome \(x\) is observed to be \(x=1\). Assuming a uniform prior, find the posterior distribution of \(\Theta\), i.e., \(p_{\Theta|X}(\theta|1)\).
Example 3.3 Bernoulli trials, beta posterior
The probability of success in a Bernoulli experiment is \(\Theta\), which we would like to estimate. We show success in the \(i\)th trial with \(y_i=1\) and failure by \(y_i=0\).
Prior distribution: Assuming that a priori we do not know anything about \(\Theta\), it is appropriate to choose \(p_\Theta \sim \mathop{\mathrm{\mathrm{Uni}}}[0,1]\), i.e., \(p(\theta) = 1\) in the interval \([0,1]\).
Likelihood: We then perform the experiment \(n\) times. Suppose that we observe \(s\) successes and \(f\) failures. Let us denote this observation as \({{\boldsymbol{x}}}=(s,f)\). The likelihood is \[\begin{equation} \begin{split} p({{\boldsymbol{x}}}|\theta) &= \binom{n}{s} \theta^s (1-\theta)^f \\ \end{split} \end{equation}\]
The posterior distribution: \[\begin{equation} p(\theta|{{\boldsymbol{x}}})\propto 1 \cdot \theta^s (1-\theta)^f = \theta^s (1-\theta)^f \end{equation}\] We observe that this distribution is of the form of a beta distribution, \(\mathop{\mathrm{\mathrm{Beta}}}(y;\alpha,\beta) \sim y^{\alpha-1}(1-y)^{\beta-1}\). Hence, \[\begin{equation} p(\theta|{{\boldsymbol{x}}}) \sim \mathop{\mathrm{\mathrm{Beta}}}(s+1, f+1). \end{equation}\]
Note that since we are interested in \(\Theta\), we can drop multiplicative terms that are constant with respect to \(\theta\), such as \(\binom{n}{s}\), in the above example.
Now that we have the posterior distribution, we can answer questions about the parameter, for example, What is the probability that \(0.4 < \Theta < 0.6\)? \[\begin{equation} \begin{split} \int_{0.4}^{0.6}p(\theta|{{\boldsymbol{x}}})d\theta \end{split} \end{equation}\]
Example 3.4 Consecutive Bayesian updating
Continuing the previous example, suppose that we collect more data \({{\boldsymbol{x}}}'=(s',f')\), consisting of \(s'\) successes and \(f'\) failures. Our prior distribution now is the posterior of the previous example, \(p(\theta)\propto\theta^s(1-\theta)^f\). We have \[\begin{equation} \begin{split} p({{\boldsymbol{x}}}'|\theta) &= \binom{s'+f'}{s'}\theta^{s'}(1-\theta)^{f'} \\ p(\theta|{{\boldsymbol{x}}}') &\propto \theta^s(1-\theta)^f \theta^{s'}(1-\theta)^{f'}\\ &= \theta^{s + s'}(1-\theta)^{f + f'} \\ \Theta|{{\boldsymbol{x}}}' &\sim \mathop{\mathrm{\mathrm{Beta}}}(s + s'+1, f+ f'+1). \end{split} \end{equation}\] Equivalently, we can update our uniform prior \(p(\theta)\propto 1\) with data \((s+s',f+f')\) to obtain \(p(\theta|(s+s',f+f'))\sim \mathop{\mathrm{\mathrm{Beta}}}(s+s'+1,f+f'+1)\). As we can see, the Bayesian approach provides a way to update our belief in a consistent manner.
The figure below provides an example of the posterior with 0, 5, 20, and 50 samples. It can be observed that the posterior becomes sharper as more data is collected.
Example 3.5 Interpreting beta priors
Beta is a common prior for the probability of Bernoulli experiments. Based on the discussion above, one way to interpret a Beta prior with parameters \(\alpha\ge1,\beta\ge1\) is to imagine that, starting with the uniform prior, we have already collected \(\alpha+\beta-2\) samples, with \(\alpha-1\) successes. The following plot shows the Beta distribution with different parameters to give a sense of the range of possible priors.
Example 3.6 Poisson likelihood, gamma prior
Suppose that \(Y\) has a Poisson distribution with paramter \(\Lambda\). That is, \(p_{Y|\Lambda}(y|\lambda) = \mathop{\mathrm{\mathrm{Poi}}}(y;\lambda)\). Hence, \[p(y|\lambda) = \frac{\lambda^ye^{-\lambda}}{y!}, \quad y\in\{0,1,\dotsc\}\] We intend to estimate \(\Lambda\) based on \(n\) iid samples \(y_1^n=\left(y_{1},\dotsc,y_{n}\right)\) of \(Y\).
We assume that the prior for \(\Lambda\) is given as \(p\left(\lambda\right)= \mathop{\mathrm{\mathrm{Gamma}}}\left(\lambda;\alpha,\beta\right)\propto\lambda^{\alpha-1}e^{-\beta\lambda}\). We have \[\begin{align} p\left(\lambda\right) & \propto\lambda^{\alpha-1}e^{-\beta\lambda}\\ p\left(y_1^n|\lambda\right) & =\prod_{i=1}^{n}\frac{\lambda^{y_{i}}e^{-\lambda}}{y_{i}!}\propto\prod_{i=1}^{n}\lambda^{y_{i}}e^{-\lambda}=e^{-n\lambda}\lambda^{n\bar{y}}, \end{align}\] where \(\bar{y}=\frac{1}{n}\sum_{i=1}^{n}y_{i}\). Note that while \(p\left(y_1^n|\lambda\right)\) is a distribution in \(y_1^n\), we still dropped the \(y_{i}!\) from its expression since our final goal is to find a distribution in \(\lambda\) and for this purpose terms that are independent of \(\lambda\) can be viewed as constant. The posterior is \[\begin{equation} p\left(\lambda|y_1^n\right)\propto\lambda^{\alpha-1}e^{-\beta\lambda}e^{-n\lambda}\lambda^{n\bar{y}}=\lambda^{\alpha+n\bar{y}-1}e^{-\lambda\left(n+\beta\right)}\propto \mathop{\mathrm{\mathrm{Gamma}}}(\lambda;\alpha+n\bar{y},n+\beta). \end{equation}\] If we choose \(\alpha=1,\beta=0\), then the Gamma prior is flat, giving all possible values the same prior probability. But this is not a proper distribution. However, as long as the final posterior is a proper distribution, an improper prior is deemed acceptable.
Suppose that \(n=10\) and \(\bar y = 2\). The figure below shows the posterior distribution with different priors. The prior on the left is called a non-informative prior because it is flat and the one on the right is an informative prior given that it represents a prior belief that certain values have a higher probability.
3.2 Bayesian Point Estimates
Having the complete distribution for \(p_{\Theta|{{\boldsymbol{X}}}}(\theta|{{\boldsymbol{x}}})\) is useful since it provides the probability for different values for \(\theta\). But sometimes we want to estimate \(\Theta\) with a single value \(\hat\theta=\hat\theta({{\boldsymbol{x}}})\) as a function of the data, similar to maximum likelihood. It is very important to note that in the Bayesian framework, the data is given and the estimate is known (and not random). The best choice for \(\hat\theta\) then depends on how we characterize the estimation error:
| Average Error | Optimal Estimator |
|---|---|
| \(\mathop{\mathrm{{\mathbb{E}}}}[(\Theta-\hat\theta)^2|{{\boldsymbol{x}}}]\) | \(\hat\theta=\mathop{\mathrm{{\mathbb{E}}}}[\Theta|{{\boldsymbol{x}}}]\) (mean) |
| \(\mathop{\mathrm{{\mathbb{E}}}}[|\Theta-\hat\theta||{{\boldsymbol{x}}}]\) | \(\hat\theta=\) median of \(p(\theta|{{\boldsymbol{x}}})\) |
| \({\Pr}(\Theta\neq\hat\theta|{{\boldsymbol{x}}}) =\mathop{\mathrm{{\mathbb{E}}}}[I(\Theta\neq\hat\theta)|{{\boldsymbol{x}}}]\) | \(\hat\theta=\arg \max_\theta p(\theta|{{\boldsymbol{x}}})\) (mode) |
In the table, \(I(condition)\) is 1 if the condition is satisfied and is 0 otherwise.
We prove the first case in the table. Let \(\bar\theta =\mathop{\mathrm{{\mathbb{E}}}}[\Theta|{{\boldsymbol{x}}}]\). We have \[\begin{align} \mathop{\mathrm{{\mathbb{E}}}}[(\hat\theta - \Theta)^2 | {{\boldsymbol{x}}}] &= \mathop{\mathrm{{\mathbb{E}}}}[((\hat\theta - \bar\theta) - (\Theta-\bar\theta ))^2 | {{\boldsymbol{x}}}] \\ &= \mathop{\mathrm{{\mathbb{E}}}}[(\hat\theta - \bar\theta)^2 - 2(\hat\theta - \bar\theta)(\Theta-\bar\theta) + (\Theta-\bar\theta)^2 | {{\boldsymbol{x}}}] \\ &= (\hat\theta - \bar\theta)^2 - 2(\hat\theta - \bar\theta)\mathop{\mathrm{{\mathbb{E}}}}[(\Theta - \bar\theta)|{{\boldsymbol{x}}}] + \mathop{\mathrm{{\mathbb{E}}}}[(\Theta-\bar\theta)^2 | {{\boldsymbol{x}}}] \\ &= (\hat\theta - \bar\theta)^2 + \mathop{\mathrm{{\mathbb{E}}}}[(\Theta-\bar\theta)^2 | {{\boldsymbol{x}}}] \\ &= (\hat\theta - \bar\theta)^2+ \mathop{\mathrm{Var}}(\Theta | {{\boldsymbol{x}}}) \\ &\ge \mathop{\mathrm{Var}}(\Theta|{{\boldsymbol{x}}}), \end{align}\] and the lower bound on the error is achieved when \(\hat\theta=\bar\theta\).
Example 3.7 Beta posterior point estimates
Generalizing Example 3.3 by assuming \(p(\theta)= \mathop{\mathrm{\mathrm{Beta}}}(\theta;\alpha,\beta)\), we obtain \(p(\theta|{{\boldsymbol{x}}})=\mathop{\mathrm{\mathrm{Beta}}}(\theta;\alpha+s,\beta+f)\) (for Uniform, \(\alpha=\beta=1\)). We have \[\begin{align} \text{Mean } &= \frac{s+\alpha}{s+f+\alpha+\beta},\\ \text{Median } &\simeq \frac{s+\alpha -1/3}{s+f+\alpha+\beta - 2/3},\\ \text{Mode } &= \frac{s+\alpha -1 }{s+f+\alpha+\beta-2}. \end{align}\] Generally speaking, Bayesian point estimates are between what is suggested only using the prior and what would be obtained using only the likelihood. For example, the mean of the prior is \(\frac \alpha {\alpha+\beta}\) and the maximum likelihood solution is \(\frac s{s+f}\). The mean of the posterior, \(\frac{s+\alpha}{s+f+\alpha+\beta}\), is between these two.
3.3 Posterior Predictive Distribution
Given \(n\) iid samples, \(y_1^n=(y_1,\dotsc,y_n)\), we are often interested in the distribution of the next (unobserved) value, \(p_{Y_{n+1}|Y_1^n}(y_{n+1}|y_1^n)\). This distribution is referred to as predictive posterior. We have \[\begin{align} p(y_{n+1}|y_1^n) &= \int p(y_{n+1},\theta|y_1^n)d\theta\\ &= \int p(\theta|y_1^n) p(y_{n+1}|\theta,y_1^n) d\theta\\ &= \int p(\theta|y_1^n) p(y_{n+1}|\theta) d\theta, \end{align}\] where we have used the fact that \(Y_{n+1}{\mathrel{\perp\mkern-10mu\perp}}Y_1^n|\Theta\). We have thus written the predictive posterior in terms of two known distributions.
Example 3.8 Bernoulli predictive probability
Continuing Example 3.3, let success in the \(n+1\)st experiment be denoted by \(Y_{n+1}=1\) and failure by \(Y_{n+1}=0\). We have \[\begin{align} p_{Y_{n+1}|Y_1^n}(1|y_1^n) &= \int \theta p(\Theta|y_1^n)=\mathop{\mathrm{{\mathbb{E}}}}[\Theta|y_1^n] = \frac{s+1}{s+f+2}, \end{align}\] where we have used the facts that \(p_{Y_{n+1}|\Theta}(1|\theta)= \theta\) and that the mean of \(\mathop{\mathrm{\mathrm{Beta}}}(s+1,f+1)\) is \(\frac{s+1}{s+f+2}\).
We may also ask about the expected value of \(Y_{n+1}\) given \(y_1^n\), i.e., \(\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|y_1^n]\). We can find this by first finding \(p(y_{n+1}|y_1^n)\) explicitly. But it is often easier to use the law of iterated expectations, since \(y_1^n\) influences \(Y_{n+1}\) through \(\Theta\). Recall that \[\begin{equation} \mathop{\mathrm{{\mathbb{E}}}}[\mathop{\mathrm{{\mathbb{E}}}}[Y|X]]=\mathop{\mathrm{{\mathbb{E}}}}[Y],\qquad \mathop{\mathrm{{\mathbb{E}}}}[\mathop{\mathrm{{\mathbb{E}}}}[Y|X,Z=z]|Z=z]=\mathop{\mathrm{{\mathbb{E}}}}[Y|Z=z]. \end{equation}\] Hence, \[\begin{equation} \mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|y_1^n] = \mathop{\mathrm{{\mathbb{E}}}}[\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|\Theta,y_1^n]|y_1^n] =\mathop{\mathrm{{\mathbb{E}}}}[\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|\Theta]|y_1^n], \end{equation}\tag{3.29}\] where the last step follows from the fact that \(Y_{n+1}{\mathrel{\perp\mkern-10mu\perp}}Y_1^n|\Theta\), implying that \(\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|\Theta,y_1^n]=\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|\Theta]\).
Example 3.9 Poisson predictive mean
Let’s find \(\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|y_1^n]\) in Example 3.6. First, observe that \(\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|\Lambda] = \Lambda\). We hence need to find \(\mathop{\mathrm{{\mathbb{E}}}}[\Lambda|y_1^n]\). We know from before that \(\Lambda|y_1^n\) is distributed according to \(\mathop{\mathrm{\mathrm{Gamma}}}(\alpha+n\bar y,\beta+n)\). Therefore, \(\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|y_1^n]=\mathop{\mathrm{{\mathbb{E}}}}[\Lambda|y_1^n]=\frac{\alpha+n\bar y}{\beta+n}\).
3.4 Gaussian Prior and Likelihood
Suppose that we want to estimate the mean of a Gaussian distribution with known variance, \[\begin{equation} p(y_i|\theta)=\frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(y_i-\theta)^2}{2\sigma^2}} \end{equation}\tag{3.30}\] given iid data \(\{y_1,\dotsc,y_n\}\).
Improper priors. Assuming that we have no information about this mean, it makes sense to choose the prior \[\begin{equation} p(\theta)\propto 1. \end{equation}\] But since the integral \(\int_{-\infty}^\infty 1 d\theta=\infty\), this does not lead to a valid distribution. Nevertheless, such a choice is acceptable, if the posterior is a valid distribution. Such priors are called improper priors. An improper prior does not necessarily have to be uniform.
Example 3.10 Gaussian mean, improper prior
Consider the above likelihood and prior and let \(\bar y = \frac1n\sum_{i=1}^n y_i\). We have \[\begin{align} p(\theta|y_1^n) &\propto p(y_1^n|\theta) \cdot 1\\ &\propto \exp\left({-\frac{\sum_{i=1}^n(y_i-\theta)^2}{2\sigma^2}}\right)\\ &\propto \exp\left({-\frac{\sum_{i=1}^n(\theta^2-2y_i\theta+y_i^2)}{2\sigma^2}}\right)\\ &\propto \exp\left({-\frac{\theta^2-2\bar y\theta}{2\sigma^2/n}}\right)\\ &\propto \exp\left({-\frac{(\theta-\bar y)^2}{2\sigma^2/n}}\right)\\ \Theta|y_1^n&\sim {\mathcal{N}}(\bar y,\sigma^2/n). \end{align}\]
For the expected value of the next sample, we have \[\begin{equation} \mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|y_1^n] = \mathop{\mathrm{{\mathbb{E}}}}[\mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|\Theta]|y_1^n]= \mathop{\mathrm{{\mathbb{E}}}}[\Theta|y_1^n] =\bar y. \end{equation}\] We can see more explicitly as well, \[\begin{align} \mathop{\mathrm{{\mathbb{E}}}}[Y_{n+1}|y_1^n] &= \int y_{n+1}p(y_{n+1}|y_1^n)dy_{n+1}\\ &=\int y_{n+1} \int p(y_{n+1},\theta|y_1^n)d\theta dy_{n+1}\\ &=\int y_{n+1} \int p(y_{n+1}|\theta)p(\theta|y_1^n)d\theta dy_{n+1}\\ &=\int p(\theta|y_1^n)\int y_{n+1} p(y_{n+1}|\theta)dy_{n+1}d\theta \\ &=\int \theta p(\theta|y_1^n)d\theta \\ &=\mathop{\mathrm{{\mathbb{E}}}}[\Theta|y_1^n]\\ &=\bar y. \end{align}\]
For the posterior predictive variance, we have \[\begin{equation} \mathop{\mathrm{Var}}(Y_{n+1}|y_1^n) = \sigma^2+\sigma^2/n. \end{equation}\]
It can be shown that \(Y_{n+1}|y_1^n\) has a Gaussian distribution, and as we know its conditional mean and variance, we have \[\begin{equation} Y_{n+1}|y_1^n \sim {\mathcal{N}}(\bar y,\sigma^2+\sigma^2/n) \end{equation}\] From the variance, we can see that there are two sources of uncertainty. One is the inherent randomness in \(Y\), quantified by \(\sigma^2\) and the other is the result of the uncertainty of our estimate of the mean, quantified by \(\sigma^2/n\).
Example 3.11 Predictive variance
Let us prove that \(\mathop{\mathrm{Var}}(Y_{n+1}|y_1^n) = \sigma^2+\sigma^2/n:\) \[\begin{align*} \mathop{\mathrm{Var}}(Y_{n+1}|y_1^n)&=\mathop{\mathrm{{\mathbb{E}}}}\left[\left(Y_{n+1}-\bar{y}\right)^{2}| y_{1}^{n}\right] \\& =\mathop{\mathrm{{\mathbb{E}}}}\left[\mathop{\mathrm{{\mathbb{E}}}}\left[\left(Y_{n+1}-\bar{y}\right)^{2}|\Theta,y_{1}^{n}\right]|y_{1}^{n}\right]\\ & =\mathop{\mathrm{{\mathbb{E}}}}\left[\sigma^{2}+\left(\Theta-\bar{y}\right)^{2}|y_{1}^{n}\right]\\ & =\sigma^{2}+\mathop{\mathrm{{\mathbb{E}}}}\left[\left(\Theta-\bar{y}\right)^{2}|y_{1}^{n}\right]\\ & =\sigma^{2}+\sigma^{2}/n \end{align*}\]
We now consider the same problem with a proper Gaussian prior. Note that below as \(\tau_0\to\infty\), the proper prior below tends to the improper prior \(p(\theta)\propto 1.\)
Example 3.12 Gaussian mean, proper prior
We would like to estimate the mean \(\Theta\) of normally distributed independent values \(y_1^n=(y_{1},\dotsc,y_{n})\). Let \(\bar{y}=\sum y_{i}/n\). We assume \[\begin{align} \Theta&\sim\mathcal{N}\left(\theta_{0},\tau_{0}^{2}\right)\\ Y_{i}|\theta&\sim\mathcal{N}\left(\theta,\sigma^{2}\right) \end{align}\] where \(\theta_{0}\) and \(\tau_0^{2}\) are the prior mean and variance, respectively, and \(\sigma^{2}\) is known. We have \[\begin{align} p\left(\theta|y_{1}^{n}\right) & \propto p\left(\theta\right)p\left(y_{1}^{n}|\theta\right)\\ & \propto\frac{1}{\sigma\tau_0}\exp\left(-\frac{\sum_{i=1}^{n}\left(y_{i}-\theta\right)^{2}}{2\sigma^{2}}-\frac{\left(\theta-\theta_{0}\right)^{2}}{2\tau_{0}^{2}}\right) \end{align}\tag{3.51}\] With some algebra, it can be shown that conditioned on \(y_1^n\), \(\Theta\) is normally distributed, \[\begin{equation} \Theta|y_{1}^{n}\sim\mathcal{N}\left(\frac{\frac{n\bar{y}}{\sigma^{2}}+\frac{\theta_{0}}{\tau_{0}^{2}}}{\frac{n}{\sigma^{2}}+\frac{1}{\tau_{0}^{2}}},\frac{1}{\frac{n}{\sigma^{2}}+\frac{1}{\tau_{0}^{2}}}\right). \end{equation}\tag{3.52}\]
Example 3.13 Completing the square
Let us prove (3.52) using (3.51). We start with the following claim: If \(p_X(x)\propto e^{-f(x)}\), where \(f\left(x\right)=ax^{2}-bx+c\) with \(a>0\), then \(X\sim\mathcal{N}\left(\frac{b}{2a},\frac{1}{2a}\right)\). Observe that \[\begin{equation} ax^{2}-bx+c=\frac{x^{2}-bx/a+c/a}{1/a}=\frac{\left(x-\frac{b}{2a}\right)^{2}-(\frac{b}{2a})^{2}+\frac{c}{a}}{2(1/(2a))}=\frac{\left(x-{b}/(2a)\right)^{2}}{2(1/(2a))}+C, \end{equation}\] where \(C\) is a constant independent from \(x\). Hence, \[\begin{equation} p_X\left(x\right)\propto\exp\left(\frac{\left(x-b/(2a)\right)^{2}}{2(1/(2a))}\right), \end{equation}\] proving the claim. Then, (3.52) can be proven by setting \[\begin{equation} a=\frac{n}{2\sigma^{2}}+\frac{1}{2\tau_{0}^{2}},\quad b=\frac{n\bar{y}}{\sigma^{2}}+\frac{\theta_{0}}{\tau_{0}^{2}}. \end{equation}\]
Example 3.14 Bayesian bias-variance trade-off
Suppose that the prior for \(\Theta\) is \(\Theta\sim\mathcal{N}\left(0,\tau_{0}^{2}\right)\). Then, from (3.52), the mean (also the mode and median) Bayesian point estimator for \(\Theta\) is \[\begin{equation} \hat\theta_{B} = \bar y\left(\frac{\tau_0^2}{\tau_0^2+\sigma^2/n}\right), \end{equation}\] while the maximum-likelihood estimator is \(\hat\theta_{mle} = \bar y\). We can evaluate both estimators in the frequentist framework, finding their MSE.
Note that the frequentist framework requires us to assume a true value \(\theta^*\) and view \(\hat\theta_B\) and \(\hat\theta_{mlue}\) as functions of random data \(Y_1^n\). So they are random variables (however, we won’t switch to capital letters to represent them here). First, as the MLE is unbiased, \[\begin{equation} \mathop{\mathrm{MSE}}(\hat\theta_{mle}) =\mathop{\mathrm{Var}}(\hat\theta_{mle})= \mathop{\mathrm{Var}}(\bar Y) = \sigma^2/n, \end{equation}\] and by CRLB, this is the best unbiased estimator.
For the Bayesian estimator, we have \[\begin{align} \text{Bias}(\hat\theta_B) &= \mathop{\mathrm{{\mathbb{E}}}}[\hat\theta_B]-\theta^*=\theta^*\left(\frac{\tau_0^2}{\tau_0^2+\sigma^2/n}\right)-\theta^*=-\theta^*\left(\frac{\sigma^2/n}{\tau_0^2+\sigma^2/n}\right)\\ \mathop{\mathrm{Var}}(\hat\theta_B) &= \frac{\sigma^2}{n}\left(\frac{\tau_0^2}{\tau_0^2+\sigma^2/n}\right)^2\\ \mathop{\mathrm{MSE}}(\hat\theta_B)&=(\theta^*)^2\left(\frac{\sigma^2/n}{\tau_0^2+\sigma^2/n}\right)^2+\frac{\sigma^2}{n}\left(\frac{\tau_0^2}{\tau_0^2+\sigma^2/n}\right)^2 \end{align}\] We can see that the bias term is decreasing in \(\tau_0^2\) while the variance term is increasing. So, there is a trade-off between the two types of error. Smaller values of \(\tau_0\) mean we have a strong prior, thus leading to bias. A strong prior is also less sensitive to data, thus leading to a smaller variance.
In particular, for \(\tau_0^2 = (\theta^*)^2\), we have\[\begin{align} \mathop{\mathrm{MSE}}(\hat\theta_B)&=\frac{(\theta^*)^2\sigma^2/n}{(\theta^*)^2+\sigma^2/n}<\sigma^2/n=\mathop{\mathrm{MSE}}(\hat\theta_{mle}). \end{align}\] So, with the right prior, \(\hat\theta_B\) has lower MSE than the maximum-likelihood estimator. Of course, this requires knowledge of \((\theta^*)\), which is not available. However, a good prior found based on experience or intuition can provide good results.
\(y_1,\dots,y_n\) iid \(\mathcal{N}(\theta^*,\sigma^2)\), with \(\sigma\) known and the true value \(\theta^*\) fixed but unknown.
Each estimator is evaluated by its MSE \(\mathbb{E}\big[(\hat\theta-\theta^*)^2\big]\) over the data, a function of \(\theta^*\) (the horizontal axis of the plot).
\(\hat\theta_{mle}=\bar y\)
Nothing to choose.
Prior \(\Theta\sim\mathcal{N}(\theta_0,\tau_0^2)\):
\(\hat\theta_B=w\,\theta_0+(1-w)\,\bar y,\quad w=\dfrac{\sigma^2/n}{\tau_0^2+\sigma^2/n}\)
\(\text{MSE}=\text{Var}=\dfrac{\sigma^2}{n}\)
Unbiased, so the MSE is the variance, the same for every \(\theta^*\).
\(\text{MSE}=\underbrace{w^2(\theta_0-\theta^*)^2}_{\text{Bias}^2}+\underbrace{(1-w)^2\,\dfrac{\sigma^2}{n}}_{\text{Var}}\)
Given \(\Theta=\theta\), the data \(y_1,\dots,y_n\) are iid \(\mathcal{N}(\theta,\sigma^2)\), with \(\sigma\) known.
Nature draws each problem's \(\Theta\) from a true prior \(\mathcal{N}(\mu,1)\) that the analyst does not know. Each estimator is evaluated by its average squared error \(\mathbb{E}\big[(\hat\theta-\Theta)^2\big]\) over \(\Theta\) and the data, a function of \(\mu\) (the horizontal axis of the plot).
\(\hat\theta_{mle}=\bar y\)
Nothing to choose.
Analyst's prior \(\Theta\sim\mathcal{N}(\theta_0,\tau_0^2)\):
\(\hat\theta_B=w\,\theta_0+(1-w)\,\bar y,\quad w=\dfrac{\sigma^2/n}{\tau_0^2+\sigma^2/n}\)
\(\mathbb{E}\big[(\hat\theta_{mle}-\Theta)^2\big]=\dfrac{\sigma^2}{n}\)
Its MSE is \(\sigma^2/n\) for every \(\theta\), so the average is too.
\(\underbrace{w^2(\theta_0-\mu)^2}_{\text{Bias}^2\text{ at }\mu}+\underbrace{w^2\cdot 1}_{\text{spread of }\Theta}+\underbrace{(1-w)^2\,\dfrac{\sigma^2}{n}}_{\text{Var}}\)
This is the frequentist MSE averaged over \(\Theta\): the same curve, raised by \(w^2\). The true prior (\(\theta_0=\mu,\ \tau_0=1\)) gives \(\big(1+n/\sigma^2\big)^{-1}\), the smallest possible.
3.5 Conjugate Priors
Given a likelihood function, a conjugate prior is a family of distributions such that the posterior is in the same family. The posterior is proportional to prior times likelihood, \[\begin{equation} p(\theta|y_1^n)\propto p(\theta)\,p(y_1^n|\theta), \end{equation}\] so when this product, as a function of \(\theta\), has the form of a member of the family, the posterior is that member. The family then also gives the normalizing constant, and the integral \(\int p(\theta)p(y_1^n|\theta)\,d\theta\) never has to be computed. Conjugate priors also often let us read the parameters of an informative prior as pseudo-observations added to a flat, possibly improper, prior. We have already met three conjugate pairs: the Beta prior for Bernoulli trials (Example 3.3), the Gamma prior for Poisson counts (Example 3.6), and the Gaussian prior for a Gaussian mean with known variance (3.52).
In each pair below, the posterior’s parameters combine the prior’s parameters with a summary of the data.
Bernoulli/Beta: \(\theta\) is the probability of success, and \(y_i=1\) marks a success and \(y_i=0\) a failure, so \(y=\sum_{i=1}^n y_i\) is the number of successes and \(n-y\) the number of failures. \[\begin{align} p(y_i|\theta)&=\theta^{y_i}(1-\theta)^{1-y_i}&\mathop{\mathrm{\mathrm{Ber}}}(\theta)\\ p(y_1^n|\theta)&=\theta^y(1-\theta)^{n-y}&&\\ p(\theta)&\propto \theta^{\alpha-1}(1-\theta)^{\beta-1}&\mathop{\mathrm{\mathrm{Beta}}}(\alpha,\beta) \\ p(\theta|y_1^n)&\propto \theta^{y+\alpha-1}(1-\theta)^{n-y+\beta-1}&\mathop{\mathrm{\mathrm{Beta}}}(y+\alpha,n-y+\beta) \end{align}\] A \(\mathop{\mathrm{\mathrm{Beta}}}(\alpha,\beta)\) prior is therefore equivalent to starting from the uniform prior \(\mathop{\mathrm{\mathrm{Beta}}}(1,1)\) and having observed \(\alpha-1\) successes and \(\beta-1\) failures.
Poisson/Gamma: \(y_i\) is the number of incidents at a fire station on day \(i\) and \(\theta\) the average number of incidents per day, so \(y=\sum_{i=1}^n y_i\) is the total number of incidents in \(n\) days. \[\begin{align} p(y_i|\theta)&=\frac{\theta^{y_i}e^{-\theta}}{y_i!}&\mathop{\mathrm{\mathrm{Poi}}}(\theta)\\ p(y_1^n|\theta)&\propto\theta^y \exp(-n\theta)&\\ p(\theta)&=\frac{\beta^\alpha}{\Gamma(\alpha)} \theta^{\alpha-1}\exp(-\beta\theta)&\mathop{\mathrm{\mathrm{Gamma}}}(\alpha,\beta)\\ p(\theta|y_1^n)&\propto \theta^{y+\alpha-1}\exp(-(n+\beta)\theta)&\mathop{\mathrm{\mathrm{Gamma}}}(y+\alpha,n+\beta) \end{align}\] A \(\mathop{\mathrm{\mathrm{Gamma}}}(\alpha,\beta)\) prior is therefore equivalent to starting from the flat improper prior \(\mathop{\mathrm{\mathrm{Gamma}}}(1,0)\) and having observed \(\alpha-1\) incidents in \(\beta\) days. In the Gamma density \(\mathop{\mathrm{\mathrm{Gamma}}}(\alpha,\beta)\), \(\alpha\) is the shape and \(\beta\) the rate, and the mean is \(\alpha/\beta\).
Exponential/Gamma: \(y_i\) is the time, in days, from the \((i-1)\)th to the \(i\)th incident at the same fire station and \(\theta\) the average number of incidents per day, so \(y=\sum_{i=1}^n y_i\) is the time taken by \(n\) incidents. \[\begin{align} p(y_i|\theta)&=\theta \exp(-\theta y_i)&\mathop{\mathrm{\mathrm{Exp}}}(\theta)=\mathop{\mathrm{\mathrm{Gamma}}}(1,\theta)\\ p(y_1^n|\theta)&=\theta^n \exp(-\theta y)&\\ p(\theta)&=\frac{\beta^\alpha}{\Gamma(\alpha)} \theta^{\alpha-1}\exp(-\beta\theta)&\mathop{\mathrm{\mathrm{Gamma}}}(\alpha,\beta)\\ p(\theta|y_1^n)&\propto \theta^{n+\alpha-1}\exp(-(y+\beta)\theta)&\mathop{\mathrm{\mathrm{Gamma}}}(n+\alpha,y+\beta) \end{align}\] A \(\mathop{\mathrm{\mathrm{Gamma}}}(\alpha,\beta)\) prior is therefore equivalent to starting from the flat improper prior \(\mathop{\mathrm{\mathrm{Gamma}}}(1,0)\) and having observed \(\alpha-1\) incidents in \(\beta\) days.
Gaussian/Gaussian: \(y_i\) is the \(i\)th of \(n\) measurements of an unknown quantity \(\theta\), each with noise of known variance \(\sigma^2\), and \(\bar y=\frac1n\sum_{i=1}^n y_i\) is their average. \[\begin{align} p(y_i|\theta)&\propto \exp\left(-\frac{(y_i-\theta)^2}{2\sigma^2}\right)&{\mathcal{N}}(\theta,\sigma^2)\\ p(y_1^n|\theta)&\propto \exp\left(-\frac{\sum_{i=1}^n(y_i-\theta)^2}{2\sigma^2}\right)&\\ p(\theta)&\propto \exp\left(-\frac{(\theta-\theta_0)^2}{2\tau_0^2}\right)&{\mathcal{N}}(\theta_0,\tau_0^2)\\ p(\theta|y_1^n)&\propto \exp\left(-\frac{(\theta-\theta_1)^2}{2\tau_1^2}\right)&{\mathcal{N}}(\theta_1,\tau_1^2), \end{align}\] where \[\begin{align} \theta_1 &=\frac{\frac{1}{\tau_0^2}\theta_0+\frac{1}{\sigma^2/n}\bar y}{\frac{1}{\tau_0^2}+\frac{1}{\sigma^2/n}},\\ \frac{1}{\tau_1^2} &= \frac{1}{\tau_0^2}+\frac{1}{\sigma^2/n}. \end{align}\] The precisions add, and the posterior mean is the precision-weighted average of the prior mean and \(\bar y\). A \({\mathcal{N}}(\theta_0,\tau_0^2)\) prior is therefore equivalent to starting from the flat improper prior \(p(\theta)\propto 1\) and having observed \(\sigma^2/\tau_0^2\) measurements with average \(\theta_0\).
If a prior is conjugate for the likelihood of a single observation, it is also conjugate for the likelihood of many iid observations. Updating with \(n\) iid observations is equivalent to updating \(n\) times with one observation at a time: the posterior after \(y_1\) is in the family, so it serves as the prior for \(y_2\), and so on.
Example 3.15 Waiting times between incidents
The waiting times (in days) between incidents at a fire station are modeled as \(Y_i|\Theta=\theta\sim\mathop{\mathrm{\mathrm{Exp}}}(\theta)\), where \(\Theta\) is the rate of incidents per day. The prior is \(\Theta\sim\mathop{\mathrm{\mathrm{Gamma}}}(2,2)\), with mean \(2/2=1\) per day. We observe \(n=5\) waits with total \(y=\sum_{i=1}^5y_i=10\) days. Find the posterior and the posterior mean.
Solution
Multiplying prior and likelihood adds the exponents of \(\theta\) and of \(e\): \[\begin{align} \text{Prior:}\quad&p(\theta)\propto\theta^{2-1}e^{-2\theta},\\ \text{Likelihood:}\quad&p(y_1^5|\theta)=\theta^{5}e^{-10\theta},\\ \text{Posterior:}\quad&p(\theta|y_1^5)\propto\theta^{2+5-1}e^{-(2+10)\theta}, \end{align}\] so \(\Theta|y_1^5\sim\mathop{\mathrm{\mathrm{Gamma}}}(7,12)\). The posterior mean is \((2+5)/(2+10)=7/12\approx0.58\) per day, between the prior mean \(1\) and the maximum-likelihood estimate \(n/y=5/10=0.5\). The posterior variance \(7/12^2\approx0.05\) is about a tenth of the prior variance \(2/2^2=0.5\).
3.6 The Exponential Family (EF)
For a random variable \({{\boldsymbol{Y}}}\) with parameter \({\boldsymbol{\Theta}}\), \(p({{\boldsymbol{y}}}|{\boldsymbol{\theta}})\) is said to be from the exponential family if it has the form \[\begin{equation} p({{\boldsymbol{y}}}|{\boldsymbol{\theta}}) = \exp\left(\langle{\textcolor{forestgreen}{{{\boldsymbol{a}}}({{\boldsymbol{y}}})}},{{\boldsymbol{b}}}({\boldsymbol{\theta}})\rangle+f({{\boldsymbol{y}}})+g({\boldsymbol{\theta}})\right), \end{equation}\tag{3.84}\] where \({{\boldsymbol{a}}},{{\boldsymbol{b}}},{{\boldsymbol{y}}},{\boldsymbol{\theta}}\) can be vectors (in bold) and \(f,g\) are scalar functions. The function \({{\boldsymbol{b}}}({\boldsymbol{\theta}})\) is the natural parameter. The data and the parameter meet only through the inner product \(\langle{\textcolor{forestgreen}{{{\boldsymbol{a}}}({{\boldsymbol{y}}})}},{{\boldsymbol{b}}}({\boldsymbol{\theta}})\rangle\): \(f\) depends on \({{\boldsymbol{y}}}\) alone and \(g\) on \({\boldsymbol{\theta}}\) alone. Below, quantities computed from the data are in green, the prior’s parameters in blue, and the posterior in red.
Example 3.16 The exponential distribution
For \(y\ge0\), \[\begin{equation} p(y|\theta)=\theta e^{-\theta y}=\exp\big({\textcolor{forestgreen}{y}}\cdot(-\theta)+\ln\theta\big), \end{equation}\] so \({\textcolor{forestgreen}{a(y)=y}}\), \(b(\theta)=-\theta\), \(f(y)=0\), and \(g(\theta)=\ln\theta\).
The exponential family includes many common distributions, among them the Bernoulli, binomial (with a known number of trials), Poisson, exponential, Gaussian, Beta, and Gamma. For likelihoods in this family, the data can be summarized in a statistic of fixed size, and the conjugate prior can be written down directly.
Sufficient statistics. Suppose that we have \(n\) iid observations. The likelihood is a product, and a product of exponentials is the exponential of the sum: \[\begin{align} p({{\boldsymbol{y}}}_1^n|{\boldsymbol{\theta}}) &= \prod_{i=1}^n p({{\boldsymbol{y}}}_i|{\boldsymbol{\theta}})=\exp\left(\Big\langle{\textcolor{forestgreen}{\sum_{i=1}^n {{\boldsymbol{a}}}({{\boldsymbol{y}}}_i)}},{{\boldsymbol{b}}}({\boldsymbol{\theta}})\Big\rangle+\sum_{i=1}^n f({{\boldsymbol{y}}}_i)+{\textcolor{forestgreen}{n}}g({\boldsymbol{\theta}})\right)\\ &\propto \exp\left(\langle{\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}},{{\boldsymbol{b}}}({\boldsymbol{\theta}})\rangle+{\textcolor{forestgreen}{n}}g({\boldsymbol{\theta}})\right), \end{align}\] where \({\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}}={\textcolor{forestgreen}{\sum_{i=1}^n {{\boldsymbol{a}}}({{\boldsymbol{y}}}_i)}}\) is the sufficient statistic. The factor \(\exp\left(\sum_i f({{\boldsymbol{y}}}_i)\right)\) does not involve \({\boldsymbol{\theta}}\), so it is absorbed into the proportionality constant. The maximum-likelihood estimate maximizes the likelihood over \({\boldsymbol{\theta}}\), and the posterior multiplies the likelihood by the prior and normalizes over \({\boldsymbol{\theta}}\). Both use the likelihood only as a function of \({\boldsymbol{\theta}}\), so a factor free of \({\boldsymbol{\theta}}\) changes neither, and both depend on the data only through \({\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}}\). Within the model, the rest of the information in \({{\boldsymbol{y}}}_1^n\) is irrelevant for estimating \({\boldsymbol{\theta}}\). The size of \({\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}}\) does not grow with \(n\).
For the exponential distribution, \({\textcolor{forestgreen}{a(y)=y}}\) (Example 3.16), so \({\textcolor{forestgreen}{t(y_1^n)=\sum_{i=1}^ny_i}}\), the total waiting time. This is why the posterior in Example 3.15 depends on the data only through \(n\) and \(y\).
Example 3.17 Gaussian mean with known variance
In \(p(y|\theta)=\frac{1}{\sqrt{2\pi\sigma^2}}e^{-(y-\theta)^2/(2\sigma^2)}\), the exponent expands as \[\begin{equation} -\frac{(y-\theta)^2}{2\sigma^2}={\textcolor{forestgreen}{y}}\,\frac{\theta}{\sigma^2}-\frac{y^2}{2\sigma^2}-\frac{\theta^2}{2\sigma^2}. \end{equation}\] So \({\textcolor{forestgreen}{a(y)=y}}\), \(b(\theta)=\theta/\sigma^2\), \(f(y)=-\frac{y^2}{2\sigma^2}-\frac12\ln(2\pi\sigma^2)\) (the prefactor joins \(f\)), and \(g(\theta)=-\frac{\theta^2}{2\sigma^2}\). The sufficient statistic is \({\textcolor{forestgreen}{t(y_1^n)=\sum_{i=1}^ny_i=n\bar y}}\), which is why the posterior (3.52) depends on the data only through \(\bar y\).
Bayesian estimation with conjugate priors. The conjugate prior of an exponential family has the form of the likelihood in \(\theta\), with two parameters \({\textcolor{royalblue}{{\boldsymbol{\nu}}}}\) and \({\textcolor{royalblue}{m}}\) in the places of \({\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}}\) and \({\textcolor{forestgreen}{n}}\): \[\begin{align} p({{\boldsymbol{y}}}_i|{\boldsymbol{\theta}})&\propto \exp\left(\langle{\textcolor{forestgreen}{{{\boldsymbol{a}}}({{\boldsymbol{y}}}_i)}},{{\boldsymbol{b}}}({\boldsymbol{\theta}})\rangle+g({\boldsymbol{\theta}})\right)\\ p({{\boldsymbol{y}}}_1^n|{\boldsymbol{\theta}})&\propto \exp\left(\langle{\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}},{{\boldsymbol{b}}}({\boldsymbol{\theta}})\rangle+{\textcolor{forestgreen}{n}}g({\boldsymbol{\theta}})\right)&\\ p({\boldsymbol{\theta}})&\propto \exp\left(\langle{\textcolor{royalblue}{{\boldsymbol{\nu}}}},{{\boldsymbol{b}}}({\boldsymbol{\theta}})\rangle+{\textcolor{royalblue}{m}}g({\boldsymbol{\theta}})\right)&{\textcolor{royalblue}{Dist({\boldsymbol{\nu}},m)}}\\ p({\boldsymbol{\theta}}|{{\boldsymbol{y}}}_1^n)& \propto \exp\left(\langle{\textcolor{royalblue}{{\boldsymbol{\nu}}}}+{\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}},{{\boldsymbol{b}}}({\boldsymbol{\theta}})\rangle+({\textcolor{royalblue}{m}}+{\textcolor{forestgreen}{n}})g({\boldsymbol{\theta}})\right)&{\textcolor{firebrick}{Dist({\boldsymbol{\nu}}+{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n),m+n)}}, \end{align}\] where \(Dist\) refers to a specific type of distribution, determined by \({{\boldsymbol{b}}}\) and \(g\). Multiplying two exponentials of this form adds their coefficients of \({{\boldsymbol{b}}}({\boldsymbol{\theta}})\) and of \(g({\boldsymbol{\theta}})\), so the posterior has the same form as the prior, and the prior is conjugate. The posterior adds the sufficient statistic \({\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}}\) to \({\textcolor{royalblue}{{\boldsymbol{\nu}}}}\) and the sample size \({\textcolor{forestgreen}{n}}\) to \({\textcolor{royalblue}{m}}\).
Pseudo-observations. The parameters in conjugate priors can be interpreted as representing pseudo-observations by comparing the forms of \(p({{\boldsymbol{y}}}_1^n|{\boldsymbol{\theta}})\) and \(p({\boldsymbol{\theta}})\). In particular, \({\textcolor{royalblue}{{\boldsymbol{\nu}}}}\) plays the same role as \({\textcolor{forestgreen}{{{\boldsymbol{t}}}({{\boldsymbol{y}}}_1^n)}}\) and \({\textcolor{royalblue}{m}}\) the same role as \({\textcolor{forestgreen}{n}}\): the prior acts like \({\textcolor{royalblue}{m}}\) earlier observations whose sufficient statistic is \({\textcolor{royalblue}{{\boldsymbol{\nu}}}}\).
Example 3.18 Bernoulli exponential family
The likelihood for a Bernoulli observation is \[\begin{align} p(y_i|\theta) &= \theta^{y_i}(1-\theta)^{1-y_i}\\ &= \exp\left(y_i \ln \theta+(1-y_i)\ln(1-\theta)\right)\\ &= \exp\left({\textcolor{forestgreen}{y_i}} \ln\frac{\theta}{1-\theta}+\ln(1-\theta)\right). \end{align}\] We thus let \({\textcolor{forestgreen}{a(y_i) = y_i}}\), \(b(\theta) = \ln\frac{\theta}{1-\theta}\), and \(g(\theta)=\ln(1-\theta)\). Furthermore, let \({\textcolor{forestgreen}{y=t(y_1^n)=\sum_{i=1}^na(y_i)=\sum_{i=1}^ny_i}}\), the number of successes. Then, \[\begin{align} p(y_1^n|\theta) &= \exp\left({\textcolor{forestgreen}{y}} \ln\frac{\theta}{1-\theta}+{\textcolor{forestgreen}{n}}\ln(1-\theta)\right),\\ p(\theta) &\propto \exp\left({\textcolor{royalblue}{\nu}} \ln\frac{\theta}{1-\theta}+{\textcolor{royalblue}{m}}\ln(1-\theta)\right)=\left(\frac{\theta}{1-\theta}\right)^{{\textcolor{royalblue}{\nu}}}(1-\theta)^{{\textcolor{royalblue}{m}}}\\ &=\theta^{{\textcolor{royalblue}{\nu}}} (1-\theta)^{{\textcolor{royalblue}{m-\nu}}},\qquad {\textcolor{royalblue}{\mathop{\mathrm{\mathrm{Beta}}}(\nu+1,m-\nu+1)}},\\ p(\theta|y_1^n)&\propto \exp\left(({\textcolor{royalblue}{\nu}}+{\textcolor{forestgreen}{y}}) \ln\frac{\theta}{1-\theta}+({\textcolor{royalblue}{m}}+{\textcolor{forestgreen}{n}})\ln(1-\theta)\right)=\theta^{{\textcolor{royalblue}{\nu}}+{\textcolor{forestgreen}{y}}}(1-\theta)^{{\textcolor{royalblue}{m}}+{\textcolor{forestgreen}{n}}-{\textcolor{royalblue}{\nu}}-{\textcolor{forestgreen}{y}}},\\ &\qquad {\textcolor{firebrick}{\mathop{\mathrm{\mathrm{Beta}}}(\nu+y+1,m+n-\nu-y+1)}}. \end{align}\] The Beta distributions are read off by matching the exponents to \(\theta^{\alpha-1}(1-\theta)^{\beta-1}\). With \({\textcolor{royalblue}{\alpha=\nu+1}}\) and \({\textcolor{royalblue}{\beta=m-\nu+1}}\), the posterior is \({\textcolor{firebrick}{\mathop{\mathrm{\mathrm{Beta}}}(\alpha+y,\beta+n-y)}}\), the Bernoulli/Beta pair of Section 3.5. For \(\alpha,\beta\ge1\), the prior acts like \({\textcolor{royalblue}{\nu=\alpha-1}}\) earlier successes in \({\textcolor{royalblue}{m=\alpha+\beta-2}}\) earlier trials.
Example 3.19 Exponential distribution, gamma prior
From Example 3.16, \(b(\theta)=-\theta\) and \(g(\theta)=\ln\theta\), and \({\textcolor{forestgreen}{y=t(y_1^n)=\sum_{i=1}^ny_i}}\) is the total waiting time. Then, \[\begin{align} p(\theta) &\propto \exp\big({\textcolor{royalblue}{\nu}}\cdot(-\theta)+{\textcolor{royalblue}{m}}\ln\theta\big)=\theta^{{\textcolor{royalblue}{m}}}e^{-{\textcolor{royalblue}{\nu}}\theta},\qquad {\textcolor{royalblue}{\mathop{\mathrm{\mathrm{Gamma}}}(m+1,\nu)}},\\ p(\theta|y_1^n)&\propto \exp\big(({\textcolor{royalblue}{\nu}}+{\textcolor{forestgreen}{y}})\cdot(-\theta)+({\textcolor{royalblue}{m}}+{\textcolor{forestgreen}{n}})\ln\theta\big)=\theta^{{\textcolor{royalblue}{m}}+{\textcolor{forestgreen}{n}}}e^{-({\textcolor{royalblue}{\nu}}+{\textcolor{forestgreen}{y}})\theta},\qquad {\textcolor{firebrick}{\mathop{\mathrm{\mathrm{Gamma}}}(m+n+1,\nu+y)}}. \end{align}\] Matching the exponents to \(\theta^{\alpha-1}e^{-\beta\theta}\), \({\textcolor{royalblue}{\alpha=m+1}}\) and \({\textcolor{royalblue}{\beta=\nu}}\), so the posterior is \({\textcolor{firebrick}{\mathop{\mathrm{\mathrm{Gamma}}}(\alpha+n,\beta+y)}}\), the Exponential/Gamma pair of Section 3.5. For \(\alpha\ge1\), the prior acts like \({\textcolor{royalblue}{m=\alpha-1}}\) earlier waits totalling \({\textcolor{royalblue}{\nu=\beta}}\) days. The \(\mathop{\mathrm{\mathrm{Gamma}}}(2,2)\) prior of Example 3.15 is one earlier wait of 2 days.
Exercise 3.20 Poisson through the recipe
A Poisson observation counts the events in one interval, \(p(y|\lambda)=\lambda^ye^{-\lambda}/y!\) for \(y=0,1,2,\dotsc\)
(a) Write \(p(y|\lambda)\) in the form (3.84). What are \(a\), \(b\), \(f\), and \(g\)?
(b) Find the conjugate prior and the posterior after \(n\) iid counts, and compare the result with Example 3.6.
Solution
(a) \(p(y|\lambda)=\exp\left({\textcolor{forestgreen}{y}}\ln\lambda-\lambda-\ln y!\right)\), so \({\textcolor{forestgreen}{a(y)=y}}\), \(b(\lambda)=\ln\lambda\), \(f(y)=-\ln y!\), and \(g(\lambda)=-\lambda\).
(b) The sufficient statistic is \({\textcolor{forestgreen}{t(y_1^n)=\sum_{i=1}^ny_i=n\bar y}}\), the total count. The conjugate prior is \[\begin{equation} p(\lambda)\propto\exp\left({\textcolor{royalblue}{\nu}}\ln\lambda-{\textcolor{royalblue}{m}}\lambda\right)=\lambda^{{\textcolor{royalblue}{\nu}}}e^{-{\textcolor{royalblue}{m}}\lambda},\qquad {\textcolor{royalblue}{\mathop{\mathrm{\mathrm{Gamma}}}(\nu+1,m)}}, \end{equation}\] and the posterior is \[\begin{equation} p(\lambda|y_1^n)\propto\lambda^{{\textcolor{royalblue}{\nu}}+{\textcolor{forestgreen}{n\bar y}}}e^{-({\textcolor{royalblue}{m}}+{\textcolor{forestgreen}{n}})\lambda},\qquad {\textcolor{firebrick}{\mathop{\mathrm{\mathrm{Gamma}}}(\nu+n\bar y+1,m+n)}}. \end{equation}\] With \({\textcolor{royalblue}{\alpha=\nu+1}}\) and \({\textcolor{royalblue}{\beta=m}}\), the posterior is \({\textcolor{firebrick}{\mathop{\mathrm{\mathrm{Gamma}}}(\alpha+n\bar y,\beta+n)}}\), as in Example 3.6. The prior acts like \({\textcolor{royalblue}{m}}\) earlier intervals in which \({\textcolor{royalblue}{\nu}}\) events were counted.