Bayesian Estimation
This lecture note is still being edited: the text may contain typos, inaccuracies, and locally underdeveloped passages. If you find something, please let the author know (contact information on the course page).
1 Frequentist and Bayesian approaches to parameter estimation
Up to this point, when estimating a parameter \(\theta\) we assumed that it is an unknown but constant quantity from some set \(\Theta\). This is the frequentist approach to parametric estimation in statistics. Under this approach we assumed no initial distinctions between possible values of the parameter from the set \(\Theta\). In practice, a researcher often has some information about the parameter before the experiment is even carried out.
Imagine we have a coin, and we want to estimate how fair it is, i.e. we want to estimate the probability of heads. To obtain an estimate of the probability, an experiment is conducted: the researcher tosses the coin several times and then analyzes the results. In the language of mathematical statistics, we can say that we have a sample \(X_1, \ldots , X_n\) from a Bernoulli distribution \(\operatorname {Ber}(\theta )\) with unknown parameter \(0 < \theta < 1\). In the frequentist approach we would treat \(\theta \in \Theta = (0,1)\), i.e. before the experiment we consider it equally possible that \(\theta\) is \(0.5\) or \(0.00001\) β there is no distinction between possible parameter values for us before the experiment. But it is clear that if we are holding an ordinary coin received as change in a store, minted by some government purely to serve as legal tender rather than as a tool in the hands of a swindler, then its probability of heads \(\theta\) is approximately \(0.5\) and cannot deviate far from this value. In this case we have some assumption, some knowledge about the parameter prior to the experiment. Such knowledge is called prior (from Latin a priori, literally βfrom what precedesβ). Given this framing, the goal of the study is to update this knowledge, to revise it in light of the experimentβs results β in philosophical terms, to obtain posterior knowledge (from Latin a posteriori, literally βfrom what followsβ) out of prior knowledge.
How can we mathematically formalize prior and posterior information about a parameter? We can think of \(\theta\) as a random variable defined on the same space as the sample \(X\), with some predetermined distribution \(\operatorname {Law}\left(\theta \right) = \mathbb {Q}\) on the parameter set \(\Theta\), corresponding to our prior knowledge and called the prior distribution. If the sample \(X\) takes values in \(\mathcal{X}\) (usually \(\mathcal{X}\) is \(\mathbb {Z}_+^n\) or \(\mathbb {R}^{n}\)), and \(\theta\) takes values in \(\Theta\), then \((X,\theta )\) can be viewed as a random element with values in the space
\[ (\mathcal{X} \times \Theta , \mathscr {B}\left(\mathcal{X}\right) \otimes \mathscr {B}\left(\Theta \right), \tilde{\mathbb {P}}), \]
with \(\mathbb {Q}(A) = \tilde{\mathbb {P}}(\mathcal{X}, A)\).
In the coin example, it would be natural to take as the prior distribution \(\mathbb {Q}\) some distribution on \([0,1]\) that is continuous and symmetric about \(0.5\) (with expectation \(0.5\), respectively). The most convenient distribution of this kind is the beta distribution \(B(\alpha , \alpha ), \; \alpha > 0\)1. In this case \(\operatorname {Var}\left[\theta \right] = \frac{1}{4(2\alpha + 1)}\), and the more strongly we are initially confident that \(\theta\) deviates only slightly from \(\frac{1}{2}\), the larger a prior value of \(\alpha\) we can take.
If \(\theta\) is a random variable, then under this approach the sample \(X = (X_1, \ldots , X_n)\) from the distribution \(\mathbb {P}_\theta = \operatorname {Ber}(\theta )\) is a collection of random variables that are conditionally independent given \(\theta\), with conditional distribution given \(\theta\) equal to \(\mathbb {P}_\theta = \operatorname {Ber}(\theta )\):
\[ \operatorname {Law}\left(X \mid \theta \right) = \mathbb {P}_\theta \otimes \ldots \otimes \mathbb {P}_\theta = \left(\mathbb {P}_\theta \right)^{\otimes n} = \left(\operatorname {Ber}(\theta )\right)^{\otimes {n}} \]
As in the frequentist approach, for brevity it is convenient to denote the distribution \(\left(\mathbb {P}_\theta \right)^{\otimes n}\) simply as \(\mathbb {P}_\theta\).
The goal of the study is to update the knowledge about the distribution of the parameter \(\theta\) using the sample \(X\). In mathematical terms this means passing from the prior, unconditional distribution \(\operatorname {Law}\left(\theta \right) = \mathbb {Q}\) of the parameter \(\theta\) to a distribution that accounts for the sample, to the conditional distribution \(\operatorname {Law}\left(\theta \mid X\right)\). The distribution \(\operatorname {Law}\left(\theta \mid X\right)\) is called the posterior distribution.
2 How to obtain the posterior distribution
2.1 Bayesβ formula for densities
How do we find the posterior distribution \(\operatorname {Law}\left(\theta \mid X\right)\)? As a rule, the distribution of \(\theta\) on \(\Theta\) and the conditional distribution \(\mathbb {P}_\theta\) of the sample \(X\) on \(\mathcal{X}\) given \(\theta\) are absolutely continuous (dominated) with respect to some measures \(\mu_\Theta , \mu_{\mathcal{X}}\) on \(\Theta\) and \(\mathcal{X}\), and thanks to this they possess densities \(q(t)\), \(p_{X | \theta }(x|t)\). The two most common choices of dominating measure and the space on which they are defined are: Lebesgue measure \(\lambda\) on \(\mathbb {R}\) (\(\lambda^n\) on \(\mathbb {R}^{n}\)), and counting measure \(\#\) on \(\mathbb {Z}\) (\(\#^n\) on \(\mathbb {Z}^n\)). In this case the joint distribution of \((X,\theta )\) on the space \(\mathcal{X} \otimes \Theta\) is dominated by the product measure \(\mu_{\mathcal{X}} \otimes \mu_\Theta\), and the problem of finding \(\operatorname {Law}\left(\theta \mid X\right)\) reduces to the problem of finding the conditional density \(p_{\theta | X}(t | x)\). Recall that the conditional density equals the joint density divided by the density of the component being conditioned on. The latter is called the marginal density of the corresponding component (from the English βmarginβ β βedgeβ). We have
\[ p_{\theta | X}(t | x) = \frac{p_{(X, \theta )}(x, t)}{p_X(x)} \]
At the same time, by the same definition,
\[ p_{(X, \theta )}(x, t) = p_{X | \theta }(x|t) p_{\theta }(t) = p_{X | \theta }(x|t) q(t). \]
The marginal density can be computed by integrating the joint density over the remaining components:
\[ p_X(x) = \int _{\Theta } p_{(X, \theta )}(x, t) \mu _\Theta (dt). \]
Putting this together, we arrive at the formula
\[ p_{\theta | X}(t | x) = \frac{p_{X | \theta }(x|t) q(t)}{\int _{\Theta } p_{X | \theta }(x|t) q(t) \mu _\Theta (dt) }, \]
which is the analog of Bayesβ formula for densities. Note that, just as in the frequentist approach, the (conditional) density of the sample \(p_{X|\theta }(x|t)\) is called the likelihood function.
2.2 Using proportionality
If the support of the density and the dominating measure are known, then the shape of the density \(p(t)\) is determined only by those factors that involve \(t\). The remaining factors merely play the role of normalizing constants. For example, the gamma distribution \(\Gamma (\alpha , \lambda )\) is defined on \(\mathbb {R}_+\), is dominated by Lebesgue measure, and has density
\[ p_{\Gamma (\alpha , \lambda )}(t) = \frac{\lambda ^\alpha }{\Gamma (\alpha )}t^{\alpha - 1}e^{-\lambda t}. \]
Given the known support and dominating measure, this density is specified purely by \(t^{\alpha - 1}e^{-\lambda t}\). The factor \(\frac{\lambda^\alpha }{\Gamma (\alpha )}\) normalizes the density, uniquely determined so that \(\int_0^\infty p_{\Gamma (\alpha , \lambda )}(t) dt = 1\):
\[ \frac{\lambda ^\alpha }{\Gamma (\alpha )} = \frac{1}{\int _0^\infty t^{\alpha - 1}e^{-\lambda t} dt} \]
In example Example 1, for the posterior density \(p_{\theta | X}(t | x)\), the role of the normalizing constant was played by the factor \(\frac{1}{B(\alpha + n\overline{x}, \alpha + n(1-\overline{x}))}\). We knew that the posterior distribution \(\operatorname {Law}\left(\theta \mid X\right)\) is defined on the same set and dominated by the same measure as the prior distribution \(\operatorname {Law}\left(\theta \right)\): on \([0,1]\) with Lebesgue measure. To recognize that \(p_{\theta | X}(t | x)\) is the density of a beta distribution with parameters \(\alpha + n\overline{X}, \alpha + n(1 - \overline{X})\), in principle we only needed to compute \(t^{\alpha + n\overline{x} - 1} (1-t)^{\alpha + n(1-\overline{x}) - 1}\). For this reason, when finding the posterior distribution it is convenient to use the proportionality sign β\(\propto\)β:
\[ f_1(t) \; \propto \; f_2(t) \stackrel{\text{def}}{\iff } \; \exists c \in \mathbb {R}\setminus \left\{ 0\right\} : f_1(t) = c f_2(t) \]
The densities of the gamma distribution and the beta distribution can be rewritten as follows:
\[ p_{\Gamma (\alpha , \lambda )}(t) \; \propto \; t^{\alpha - 1}e^{-\lambda t}, \qquad p_{B(\alpha , \beta )}(t) \; \propto \; t^{\alpha - 1}(1-t)^{\beta - 1} \]
Bayesβ formula can be rewritten as:
\[ p_{\theta | X}(t | x) = \frac{p_{X | \theta }(x|t) q(t)}{\int _{\Theta } p_{X | \theta }(x|t) q(t) \mu _\Theta (dt) } \; \propto \; p_{X | \theta }(x|t) q(t), \]
since the denominator \(\int_{\Theta } p_{X | \theta }(x|t) q(t) \mu_\Theta (dt)\) does not depend on \(t\) and plays the role of a normalizing constant.
Bayesian updating in the Bernoulli model: the prior distribution \(B(\alpha_0,\beta_0)\) (gray dashed line) turns, after \(n = 5, 20, 100\) observations, into the posteriors \(B(\alpha_0 + k, \beta_0 + n - k)\), where \(k\) is the accumulated number of successes along a single simulated path with true \(\theta\) (black vertical dashed line). Move the sliders to change the true \(\theta\) and the prior parameters, click βRegenerate dataβ for a new sample of tosses, or βAnimate toss by tossβ to watch the density flow smoothly from the prior to the posterior as observations arrive.
It is useful to see the geometry of a single step of Bayesian updating: the posterior density is obtained by βmultiplyingβ the prior density by the likelihood (followed by normalization), rather than by simply replacing one curve with another.
The geometry of a single step of Bayesian updating for \(X_1,\ldots,X_n\sim\operatorname{Ber}(\theta)\) with a conjugate \(\operatorname{Beta}(\alpha,\alpha)\) prior (as in the example above): the posterior density is proportional to the product of the prior density and the likelihood, \(p(\theta\mid x)\propto q(\theta)\,L(\theta;x)\). Move the parameter \(\alpha\) of the prior and the number of observed successes/trials to see how the likelihood βpullsβ the prior distribution toward the posterior.
3 Estimators and their comparison in the Bayesian approach
3.1 Estimation in the Bayesian approach
Suppose we need to estimate the parameter \(\theta\). If the study has not yet taken place and we currently have only the prior (unconditional) distribution of \(\theta\), then the most logical estimate of \(\theta\) is obtained by taking the expectation \(\mathbb {E}\left[\theta \right] = \int_\Theta t \mathbb {Q}(dt)\) with respect to the prior distribution (assuming the expectation exists). Acting analogously after the experiment has been carried out and the posterior distribution obtained, it seems most reasonable to estimate \(\theta\) by the (conditional) expectation with respect to the posterior, conditional distribution \(\operatorname {Law}\left(\theta | X\right)\):
\[ \theta ^* = \theta ^*(X) := \mathbb {E}\left[\theta \mid X\right] = \int _\Theta t \; \cdot \operatorname {Law}\left(\theta | X\right)(dt) \]
Such an estimator is called a Bayesian estimator.
If the distributions of \(\theta\) and \(X\) are dominated and \(q(t)\), \(p_{X|\theta }(x|t)\) are the density of \(\theta\) and the conditional density (likelihood function) of \(X\), then the Bayesian estimator can be found in 2 steps:
find the function \(\varphi (x) := \mathbb {E}\left[\theta \mid X = x\right] = \int_\Theta t \cdot p_{\theta | X}(t|x) \mu_\Theta (dt)\);
substitute \(X\) into \(\varphi\): \(\theta^* = \mathbb {E}\left[\theta \mid X\right] = \varphi (X)\).
We discussed above how to find the posterior density \(p_{\theta | X}(t|x)\).
3.2 Consistency of estimators
As in the frequentist approach, in the Bayesian approach an estimator \(\widehat{\theta }\) is a consistent estimator of \(\theta\) if \(\widehat{\theta } \xrightarrow [n \to \infty ]{\mathbb {P}} \theta\). The difference is that here \(\theta\) is not a constant but a random variable. Convergence in probability to a random variable is not equivalent to convergence in distribution. Consistency cannot be reduced to convergence in distribution. One can only use the absence of convergence in distribution to prove the absence of consistency.
The conditional law of large numbers can help prove consistency.
3.3 Comparing estimators
Letβs discuss comparing estimators in the Bayesian approach. We have already discussed comparing estimators and used for this the uniform approach with a quadratic loss function. Under this approach, one estimator is considered better than another if the variance of the first is no greater than the variance of the second for every value of the parameter. Of course, if we possess some prior knowledge about the value of the parameter, we can relax the βrequirement of being bestβ by comparing only the averaged values of the variances.
The following theorem is a direct consequence of properties of conditional expectation.
4 Conjugate distributions
In statistical problems it is often assumed that the prior distribution \(\mathbb {Q} = \operatorname {Law}\left(\theta \right)\) and the posterior distribution \(\operatorname {Law}\left(\theta \mid X\right)\) belong to the same family of distributions. In this case the family of distributions to which \(\mathbb {Q}\) belongs is called the conjugate prior distribution for the family of sample distributions \(\mathcal{P} = \left\{ \mathbb {P}_\theta \right\}\). Of course, for an arbitrary family of sample distributions \(\mathcal{P}\), the family of all possible distributions on \(\Theta\) is conjugate. However, in some models \(\mathcal{P}\) the family of conjugate prior distributions can be significantly narrowed.
Consider example Example 1. In it
\[ \operatorname {Law}\left(\theta \right) = B(\alpha , \alpha ), \qquad X_1, \ldots , X_n \text{ -- a sample from } \operatorname {Ber}(\theta ) \quad \; \Rightarrow \; \quad \operatorname {Law}\left(\theta \mid X\right) = B\left(\alpha + n\overline{X}, \alpha + n(1-\overline{X})\right). \]
It is clear that in general
\[ \operatorname {Law}\left(\theta \right) = B(\alpha , \beta ), \qquad X_1, \ldots , X_n \text{ -- a sample from } \operatorname {Ber}(\theta ) \quad \; \Rightarrow \; \quad \operatorname {Law}\left(\theta \mid X\right) = B\left(\alpha + n\overline{X}, \beta + n(1-\overline{X})\right). \]
The beta distribution \(B(\alpha , \beta )\) is the conjugate prior distribution for \(\operatorname {Ber}(\theta )\).
Footnotes
Recall that if \(\xi \sim B(\alpha , \beta ), \; \alpha , \beta > 0\), then the density equals
\[ \begin{align} p_\xi (x) & = \frac{1}{B(\alpha , \beta )} x^{\alpha - 1}(1-x)^{\beta - 1} \; \mathbb {1}_{x \in [0,1]}, \qquad B(\alpha , \beta ) = \int _0^1 t^{\alpha - 1}(1-t)^{\beta - 1}dt = \frac{\Gamma (\alpha )\Gamma (\beta )}{\Gamma (\alpha + \beta )}, \\ \mathbb {E}\left[\xi \right] & = \frac{\alpha }{\alpha + \beta }, \qquad \operatorname {Var}\left[\xi \right] =\frac{\alpha \beta }{(\alpha + \beta )^2 (\alpha + \beta + 1)}. \end{align} \] If \(\beta = \alpha\), then \(\mathbb {E}\left[\xi \right] = \frac{1}{2}, \; \operatorname {Var}\left[\xi \right] = \frac{1}{4(2\alpha + 1)}\). Note that \(B(1, 1) = U[0,1]\).β©οΈ