Compute the posterior on a Gamma distribution with a gaussian random variable

bayes-theorembayesiangamma distributionnormal distributionprobability

i have the following problem:

given a variable $x \in \mathbb{R}$ drawn from a Gaussian distribution with known mean $\mu$ and unknown precision $\tau$ (the inverse of the variance).
So: $$p(x \vert \tau) = \mathcal{N}(x; \mu, \tau^{-1})$$

Now we assume as our prior that $\tau$ is Gamma distributed: $$p(\tau) = \mathcal{G}(\tau; k, \theta) = \frac{\tau^{k-1}}{\Gamma(k)\theta^k} \exp\left(\frac{-\tau}{\theta}\right)$$

The goal now is to compute the posterior distribution : $p(\tau \vert x)$

What I have so far:

I want to calculate the posterior via the Bayes theorem: $$p(\tau \vert x) = \frac{p(x \vert \tau) \cdot p(\tau)}{\int p(x \vert \tau) \cdot p(\tau) d\tau}$$
After doing some calculations I came up with $$p(x \vert \tau) \cdot p(\tau) = \frac{\tau^{k-1}}{\sqrt{2 \pi \tau^{-1}} \cdot\Gamma(k)\theta^k} \exp\left(-\frac{(x – \mu)^2}{2\tau^{-1}} + \frac{-\tau}{\theta}\right)$$

So is there any other way than integrating this term and to some nasty calculations or is this the way I have to go? Or am I completely wrong here using the Bayesian approach?

Tanks for answers!

Best Answer

There is an error in you posterior formula, normalization should be wrt $\tau$. The correct formula is

\begin{equation} p(\tau|x)=\frac{p(x|\tau)p(\tau)}{\int d\tau p(x|\tau) p(\tau)} \end{equation}

You have that

\begin{equation} p(x|\tau)p(\tau)\propto \tau^{k-\frac{1}{2}}e^{-\tau\Bigg(\frac{(x-\mu)^2}{2}+\frac{1}{\theta}\Bigg)} \end{equation}

which is proportional to $\mathcal{G}\Bigg(\tau,k-\frac{1}{2},\Bigg(\frac{(x-\mu)^2}{2}+\frac{1}{\theta}\Bigg)^{-1}\Bigg)$ for the purposes of integration in $\tau$ and thus you can calculate the renormalization constant. I leave to you the details of the calculation and collecting all factors.