MXB341 Statistical Inference
“Bayes’ theorem is to the theory of probability what the Pythagorean theorem is to geometry.”
— Sir Harold Jeffreys1
Week 7: Bayesian Statistics
In the first half of this unit, we have learned frequentist or classical approaches to statistical inference. The second half of this unit focuses on Bayesian approaches to statistical inference.
Probability and Priors
Conditional probability
If \(S\) and \(T\) are events then recall that the joint probability can be written as \[ \begin{aligned} Pr(S,T) &= Pr(S~\vert~T)Pr(T) \text{ or} \\ Pr(S,T) &= Pr(T~\vert~S)Pr(S) \end{aligned} \] If \(S\) and \(T\) are independent then \(P(S~\vert~T) = P(S)\) and \(P(T~\vert~S)\) so \[ Pr(S,T) = Pr(S)Pr(T) \] Also related, is the rule for conditional probability \[ Pr(S~\vert~T) = \frac{Pr(S,T)}{Pr(T)} \] These rules apply to discrete probabilities, but also when using probability distribution functions for continuous probability distributions. For example if \(p(\cdot)\) represents a pdf then \[ \begin{aligned} p(x~\vert~y) & = \frac{p(x,y)}{p(y)} &= \frac{p(y~\vert~x)p(x)}{p(y)} \text{ where} \\ p(y) &= \int_{\mathcal{X}} p(x,y)~dx &= \int_{\mathcal{X}} p(y~\vert~x)p(x)~dx \end{aligned} \] where \(\mathcal{X}\) is the support of \(x\).
“Scientific Inference”“, Cambridge University Press, 1973, pg 31.↩︎
Bayes Theorem2
If \(A\) and \(B\) are events, and \(Pr(B)\neq 0\), then \[ Pr(A~\vert~B) = \frac{Pr(B~\vert~A)Pr(A)}{Pr(B)} \] When applied to statistical inference, Bayes theorem can be understood as \[ Pr(\text{parameters} ~\vert~ \text{data}) \propto f(\text{data} ~\vert~ \text{parameters}) \times \pi(\text{parameters}) \] where
- \(\pi(\text{parameters}) = \pi(\theta)\) is the prior distribution. The information we have about the parameter of interest before observing the data.
- \(f(\text{data} ~\vert~ \text{parameters}) = f(\boldsymbol{x} ~\vert~ \theta)\) is the likelihood or probability distribution for observing the data. This defines the way we assume the data is generated, if we were given the exact value of the parameters.
- \(Pr(\text{parameters} ~\vert~ \text{data}) = Pr(\theta ~\vert~ \boldsymbol{x})\) is the posterior distribution. Defines our new updated information (beliefs, uncertainty etc.) about the parameters of interest, after observing the data.
The only thing missing is the normalising constant: \[ Pr(\text{data}) = Pr(\boldsymbol{x}) = \int_{\theta} f(\boldsymbol{x} ~\vert~ \theta) \pi(\theta) \text{ d}\theta \] To recap, Bayes theorem gives us a method for statistical inference through the posterior: \[ Pr(\theta ~\vert~ \boldsymbol{x}) =\frac{f(\boldsymbol{x} ~\vert~ \theta) \pi(\theta)}{Pr(\boldsymbol{x})} \]
Exercise: prove Bayes Theorem using conditional probabilities.↩︎
Jeffery’s prior
Jeffery’s prior are motivated by wanting priors that are uninformative, in the sense that the prior has little effect on the statistical inference being performed. In otherwords, the data informs the posterior distribution as much as possible. This can be a desirable property in some analysese but is not always wanted. For example, shrinkage priors are known to be helpful in high dimensional parameter settings.
The Jeffery’s prior is given by \[ \pi(\boldsymbol{\theta}) \propto \sqrt{\det \left[ \mathcal{I}(\boldsymbol{\theta}) \right]} \] where \(\mathcal{I}(\boldsymbol{\theta})\) is the Fisher information matrix (or value).
Theory questions
Question 1
Suppose \(A\), \(B\), \(C\) are three events. Which of the following are always true, and which are special relations following from assumptions. State the assumption(s) (if any) required to make the statement true.
- \(p(A,B,C) = p(A)p(B|A)p(C|B)\)
- \(p(A,B,C) = p(A)p(B|A)p(C|A,B)\)
- \(p(A|B,C) =
\frac{p(B,C|A)p(A)}{p(B,C)}\)
- \(p(A|B,C) = \frac{p(B|A)p(C|A)p(A)}{p(B)p(C)}\)
Question 2
Let’s explore a particular test for credit worthiness3 using Bayes theorem.
A bank finds that \(5\%\) of its customers default on loans within a year. In an effort to reduce this percentage it introduces a questionnaire for customers; they either pass or fail the questionnaire. It is found from the database that \[ \begin{aligned} P(\text{fail questionnaire}~\vert~\text{default loan}) &= 0.9\\ P(\text{pass questionnaire}~\vert~\text{no default loan}) &= 0.95. \end{aligned} \] (a) Is it in the bank’s best interest to introduce the questionnaire and only give loans to those customers who pass the questionnaire4.
Which of the following has more effect on \(P(\text{no default loan} \vert \text{pass questionnaire})\) in terms of improving the questionnaire?
- changing the value of \(P(\text{fail questionnaire} ~\vert~ \text{default loan})\) from \(0.9\) to \(0.95\) or
- \(P(\text{pass questionnaire}~\vert~\text{no default loan})\) from \(0.95\) to \(0.99\).
Question 3
Suppose data \(y\) is binomially distributed, that is \(y~\vert~\theta \sim \text{Bin}(n,\theta)\). If our prior information for \(\theta\) is best represented as a \(\text{Beta}(8,4)\) (prior) distribution with mode at \(\theta=7/10\), determine the posterior distribution for \(\theta\) and the mode of this distribution when \(n=3\), and \(y=2\).
Question 4
Find the Jeffery’s prior for the Gamma distribution with \(\alpha = 3\). The Gamma distribution has the denisty \[ p(x~\vert~\alpha,\beta) = \frac{\beta^{\alpha}}{\Gamma(\alpha)} x^{\alpha-1} \exp(-\beta x) \]
Is it a proper distribution?
Question 5
In Bayesian statistics we often work with density functions up to a constant of proportionality. For example, \(p(x,y) \propto xy\) implies that \(p(x,y) = Cxy\) where \(C\) is a constant such that \(p(x,y)\) integrates to 1 over the joint support.
Let \(p(x,y) \propto 1\), \(0 < y < x <1\), this defines uniform probability over a triangle5. Find \(p(x|y)\) and \(p(y|x)\). Are \(x\) and \(y\) independent?
Suppose we define the joint probability density by \[p(x,y) \propto \frac{1}{(x+y)^2}, \quad x>0, \, y>0.\] Find \(p(x)\), \(p(y)\), \(p(x|y)\). Is there anything unusual about \(p(x)\), etc?
Suppose \(x\) is discrete and \(y\) is continuous with \[p(x,y) \propto \frac{1}{x}, \quad x=1,2; \, 0<y<x.\] Find \(p(x)\) and \(p(y)\), \(p(x|y)\) and \(p(y|x)\) properly normalised.
The triangle with vertices \((0,0), (1,0), (1,1)\)↩︎
Practical questions
Question 6
Students are asked to repeat an online test until they obtain a pass mark. The number of times, \(y\), the test is repeated by a given student is recorded. Suppose the distribution of \(y\) for a given student is given by the geometric distribution \[p(y~|~\theta)= (1-\theta)^{y-1} \theta, \quad \quad y=1,2,\ldots \] for \(0 < \theta < 1\). Suppose independent data \(y_1,\ldots,y_n\) (results from similar tests with the same value of \(\theta\)) are available.
If the prior for \(\theta\) is taken as \(\text{Beta}(\alpha,\beta)\) determine the posterior distribution of \(\theta\) as a Beta distribution.
Plot the posterior distribution in (a) for \(n=10\) tests and \(\sum_j {y_j} = 12\) for \(\alpha = 0.1, 1, 8, 20\) and \(\beta = 0.1, 1, 8, 20\). What part of your model are you changing when you vary \(\alpha\) and \(\beta\)?
Repeat (b) with \(n=5\) tests and \(\sum_j {y_j} = 6\). Explain why the posterior distributions change, even though the mean number of times a test is repeated remains the same.