# Estimate the mean and variance 95% HPD credible region using Bayesian inference

I have the following data:

31.0, 30.5, 20.6, 27.2, 26.5, 28.1, 25.8, 29.6, 30.0, 25.8, 25.1, 27.9, 23.0, 29.4, 28.7, 25.0, 31.1, 24.8, 24.8, 27.0, 22.3, 29.5, 31.5, 26.2, 24.6, 23.2, 25.7, 24.2, 28.8, 27.4, 29.6, 23.5, 26.4, 28.7, 25.5, 18.6, 25.2, 24.5, 27.9, 33.0, 21.4, 34.4, 27.2, 23.3, 29.3, 31.4, 24.6, 32.3, 22.8, 19.7, 24.6

And I have to conduct a bayesian analysis to make inferences about the 95% HPD credible region for the mean $\mu$ and the variance $\sigma^2$. Supposing the semi-conjugate prior is assigned:

$$\sigma^2 \sim IG(3,36)$$ $$\mu | \sigma^2 \sim N(26, \sigma^2)$$

And Supposing normal model $N(\mu,\sigma^2)$

• Do you want someone to solve this exercise for you? – niandra82 May 15 '18 at 21:10
• Not really. The truth is that I do not know how to face it. I just want a little guidance. Do you have a resource that you recommend me? – Eduardo Vieira May 15 '18 at 21:30
• Ok, then try to read this cs.ubc.ca/~murphyk/Papers/bayesGauss.pdf – niandra82 May 15 '18 at 21:32

Letting $\tau = \frac{1}{\sigma^{2}}$, be the precision, the priors become:

$\tau \sim Gamma(3, 36)$

$\mu \space | \space \tau \sim \mathcal{N}(26, n_{0}\tau)$

Then the posterior distributions have the form:

$\mu \space | \space \tau, x \sim \mathcal{N}(\frac{n\tau}{n\tau + n_{0}\tau}\bar{x} + \frac{n_{0}\tau}{n\tau + n_{0}\tau} \mu_{0}, \space \space n\tau + n_{0}\tau)$

$\tau \space | \space x \sim Gamma(\alpha+\frac{n}{2}, \space \beta +\frac{1}{2}\sum(x_{i}-\bar{x})^2 + \frac{nn_{0}}{2(n+n_{0})} (\bar{x}-\mu_{0})^2)$

Now you should be able to plug in the values from your priors and the data to get the posterior distributions. Then you can sample from those distributions to get point estimates, credible intervals, HPDs, etc. Hopefully that helps you get started; more details can be found here and here.