exact form for the marginal posterior I have a question that I come across for practicing. Basically the question is this:
Consider a random sample from the normal distribution with unknown mean and variance $Y_i \sim^{i.i.d.} N(\mu, \sigma^2)$ ,  $i = 1,...,n$ with the joint prior
$p(\mu, \sigma^2) \propto \sigma^{-1} (\sigma^2)^{-(v_0/2 + 1)} exp\{-\frac{1}{2\sigma^2}[v_0 \sigma_0^2 + k_0(\mu_0 - \mu)^2]\}$ and where $\mu_0, k_0, v_0$ and $\sigma_0^2$ are all known.
Derive the exact form of the marginal posterior distributions of $p(\sigma^2 | Y_1,...,Y_n)$ and $p(\mu | Y_1,...,Y_n)$
So I basically try to write the joint posterior as the product of the prior $p(\mu, \sigma^2)$ and the likelihood function which is $\frac{1}{\sqrt{2\pi}\sigma^n} \exp(-\frac{1}{2\sigma^2} \sum(y_i-\mu)^2)$.
So I have this:
$\sigma^{-1} (\sigma^2)^{-(v_0/2 + 1)} exp\{-\frac{1}{2\sigma^2}[v_0 \sigma_0^2] + k_0(\mu_0 - \mu)^2]\} \cdot \frac{1}{\sqrt{2\pi}\sigma^n} \exp(-\frac{1}{2\sigma^2} \sum(y_i-\mu)^2)$
and then to find $p(\mu | Y_1,...,Y_n)$, I tried taking the integral of the above function from negative infinity to positive infinity. 
However I got stuck. 
Also I just want to know if it is correct that when I try to find the marginal of $\mu$, i.e. $p(\mu | Y_1,...,Y_n)$: I would take the integral from 0
And when I try to find the marginal of $\sigma^2$, i.e. $p(\sigma^2 | Y_1,...,Y_n)$, I would integrate from negative infinity to positive infinity?
Could someone give some suggestions.
thanks
 A: For this type of analysis, it is often possible to decompose the posterior density into a part representing the marginal posterior of one of the parameters, and another part representing the conditional posterior of the other parameter.  It turns out to be possible to do this in the present case.  
To facilitate our analysis, let us define the useful posterior quantities:
$$\mu_* \equiv \frac{n \bar{y} + k_0 \mu_0}{n + k_0}
\quad \quad \quad \quad \quad
\beta_* \equiv \frac{||\mathbf{y}||^2 + v_0 \sigma_0^2 + k_0 \mu_0^2 - (n+k_0) \mu_*}{2}.$$
Now, we can solve this problem by writing out the posterior kernel, and then collect all terms involving $\mu$ and simplify this into the kernel of a known density function (in this case the normal density).  Using the method of completing the square, we obtain:
$$\begin{equation} \begin{aligned}
p(\mu, \sigma^2 | \mathbf{y}) 
&\propto L_\mathbf{y}(\mu, \sigma^2) \cdot p(\mu, \sigma^2) \\[6pt]
&\propto \sigma^{-n} \exp \Bigg( - \frac{1}{2 \sigma^2} \cdot \sum_{i=1}^n ( y_i-\mu)^2 \Bigg) \cdot \sigma^{-v_0 -3} \exp \Bigg( -\frac{1}{2\sigma^2} [v_0 \sigma_0^2+ k_0(\mu_0 - \mu)^2] \Bigg) \\[6pt]
&= \sigma^{-n-v_0 -3} \exp \Bigg( - \frac{1}{2 \sigma^2} \Bigg[ \sum_{i=1}^n ( y_i-\mu)^2 +v_0 \sigma_0^2+ k_0(\mu_0 - \mu)^2 \Bigg] \Bigg) \\[6pt]
&= \sigma^{-n-v_0 -3} \exp \Bigg( - \frac{1}{2 \sigma^2} \Bigg[ (||\mathbf{y}||^2 -2 n \bar{y} \mu + n \mu^2) + v_0 \sigma_0^2 + (k_0 \mu_0^2 - 2 k_0 \mu_0 \mu + k_0 \mu^2) \Bigg] \Bigg) \\[6pt]
&= \sigma^{-n-v_0 -3} \exp \Bigg( - \frac{1}{2 \sigma^2} \Bigg[ -2 (n \bar{y} + k_0 \mu_0 ) \mu + (n + k_0) \mu^2 + ||\mathbf{y}||^2 + v_0 \sigma_0^2 + k_0 \mu_0^2 \Bigg] \Bigg) \\[6pt]
&= \sigma^{-n-v_0 -3} \exp \Bigg( - \frac{n + k_0}{2 \sigma^2} \Bigg[ -2 \mu_* \mu + \mu^2 \Bigg] - \frac{||\mathbf{y}||^2 + v_0 \sigma_0^2 + k_0 \mu_0^2}{2 \sigma^2} \Bigg) \\[6pt]
&= \sigma^{-n-v_0 -3} \exp \Bigg( - \frac{n + k_0}{2 \sigma^2} \Bigg[ \mu_*^2 -2 \mu_* \mu + \mu^2 \Bigg] - \frac{\beta_*}{\sigma^2} \Bigg) \\[6pt]
&= \sigma^{-n-v_0 -3} \exp \Bigg( - \frac{n + k_0}{2 \sigma^2} ( \mu - \mu_* )^2 - \frac{\beta_*}{\sigma^2} \Bigg) \\[6pt]
&= \sigma^{-1} \exp \Bigg( - \frac{n + k_0}{2 \sigma^2} ( \mu - \mu_* )^2 \Bigg) \cdot \sigma^{-n-v_0 -2} \exp \Bigg( - \frac{\beta_*}{\sigma^2} \Bigg) \\[6pt]
&= \sigma^{-1} \exp \Bigg( - \frac{n + k_0}{2 \sigma^2} ( \mu - \mu_* )^2 \Bigg) \cdot (\sigma^2)^{-(n+v_0)/2 -1} \exp \Bigg( - \frac{\beta_*}{\sigma^2} \Bigg) \\[6pt]
&\propto \text{N} \Big( \mu \Big| \mu_*, \frac{\sigma^2}{n + k_0} \Big) \cdot \text{InvGa} \Big( \sigma^2 \Big| \frac{n+v_0}{2}, \beta_* \Big). \\[6pt]
\end{aligned} \end{equation}$$
Since the joint density is a probability density, we then have:
$$p(\mu, \sigma^2 | \mathbf{y}) = \text{N} \Big( \mu \Big| \mu_*, \frac{\sigma^2}{n + k_0} \Big) \cdot \text{InvGa} \Big( \sigma^2 \Big| \frac{n+v_0}{2}, \beta_* \Big). $$
From this equation we obtain the marginal distribution:
$$\sigma^2 | \mathbf{y} \sim \text{InvGa} \Big( \frac{n+v_0}{2}, \beta_* \Big). $$
