# Marginal distribution of a Gaussian

1. Oct 1, 2012

### fluidistic

1. The problem statement, all variables and given/known data
The random variables X and Y have a joint probability distribution of $$f_{XY}(x,y)= \frac{1}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}} \exp \{ \left [ -\frac{1}{2(1-\rho ^2)} \right ] \left [ \left ( \frac{x-\mu _X}{\sigma _X} \right )^2 + \left ( \frac{y-\mu _Y}{\sigma _Y} \right )^2 -\frac{2\rho (x-\mu _X)(y-\mu _Y)}{\sigma _X \sigma _Y} \right ] \}$$.
Where rho, sigma's and mu's are constants.
Show that the marginal distributions are also Gaussians. Calculate their mean value and their variance.
2. Relevant equations
a)The marginal distribution of the variable X is $f_ X (x)=\int _{-\infty}^{\infty} f_{XY}(x,y)dy$.
b)The marginal distribution of the variable Y is $f_Y(y)=\int _{-\infty}^{\infty} f_{XY}(x,y)dx$.
c)$$\int _{-\infty}^{\infty} e^{-ax^2+bx }dx=\sqrt{\frac{\pi}{a}}e^{\frac{b^2}{4a}}$$.
d)For the mean values I need to calculate $\int f_X(x)xdx$ and $\int f_Y(y)ydy$ which in my case is so horrible that I've lost some hope in it.
3. The attempt at a solution
So my problem resides in calculating that huge integral. I've done it 3 times, each time reaching a different result, but I've spotted an error in my first 2 attempts and didn't in my last attempt though the result is so ugly I can't believe I've done it right.
So in order to perform $\int _{-\infty}^{\infty} f_{XY}(x,y)dy$, I factorize outside the integral the constant $\frac{1}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}}\exp \{ \left [ - \frac{1}{2(1-\rho ^2)} \right ] \left ( \frac{x-\mu _X}{\sigma _X} \right ) \}$.
Therefore I am left to calculate the integral $$\int _{-\infty}^{\infty} \exp \{ \left [ - \frac{1}{2(1-\rho ^2)} \right ] \left [ \left ( \frac{y-\mu _Y}{\sigma _Y} \right ) ^2 - \frac{2\rho (x-\mu _X )(y- \mu _Y)}{\sigma _X \sigma _Y} \right ] \} dy$$.
I skip many steps (latex is very long to write!) but what I did was rewrote the argument of the exponential into a form $-ax^2+bx+c$ and where $a = \frac{1}{2(1-\rho ^2) \sigma _Y ^2}$, $$b= \frac{\mu _Y}{\sigma _Y ^2(1-\rho ^2)} - \frac{\rho \mu _X}{\sigma _X \sigma _Y (1-\rho ^2)} + \frac{2\rho x}{\sigma _X \sigma Y}$$ and $$c= \left [ \frac{1}{2(1-\rho ^2)} \right ] \left [ \frac{2\rho \mu _X \mu _Y}{\sigma _X \sigma _Y}-\frac{2\rho x \mu _Y}{\sigma _X \sigma _Y} -\frac{\mu _Y ^2}{\sigma _Y ^2} \right ]$$.
This gave me as a final result, $$f_X(x)= \frac{1}{\sqrt {2\pi} \sigma _X} \exp \{ x^2 \left [ \frac{1}{2(1-\rho ^2)} \right ] \left ( \frac{4 \rho ^2 -1 }{\sigma _X ^2} \right ) +x \left [ \frac{1}{2(1-\rho ^2)} \left ( \frac{2\rho \mu _Y }{\sigma _X \sigma _Y}-\frac{4 \rho ^2 \mu _X}{\sigma _X ^2}+\frac{2\mu _X}{\sigma _X ^2} \right ) \right ] +\left [ \frac{1}{2(1-\rho ^2)} \right ] \left ( \frac{\rho ^2 \mu _X ^2}{\sigma _X ^2}- \frac{\mu _X ^2}{\sigma _X ^2} \right ) \}$$. This would be my answer to the first question. For the marginal distribution of the random variable Y, I'd have to change all x's by y's and all X's by Y's in that result, because the joint distribution is totally symmetric with respect to x-y/X-Y.
As you can see my answer is under the form $Ae^{ax^2+bx+c}$ so I think this implies it's a Gaussian?
I would like to know whether my result is good and how can I calculate the mean of that function; I mean there must be a trick or something because the integral to perform looks much uglier than the first!
Thanks for any help!

2. Oct 1, 2012

### jbunniii

Yikes, I haven't read through all of your equations to check their validity because, as you said, it's pretty ugly. I think you can simplify this problem quite a bit using this change of variables:

$$U = \frac{X - \mu_X}{\sigma_X}$$
$$V = \frac{Y - \mu_Y}{\sigma_Y}$$

Then it's easy to find the marginal distributions, means, and variances for X and Y if you have found these things for U and V.

3. Oct 1, 2012

### Ray Vickson

I don't want to spoil your fun, but the mere fact that the parameters have names like μX and σX, etc., should be a hint that the final answer is pretty simple. All I can say is that if you do the y-integration very carefully and completely, the formula for fX(x) comes out pleasantly uncomplicated.

RGV

4. Oct 2, 2012

### fluidistic

Wow. Wow. Wow. Worked like a charm, thanks a lot!!!!
Haha, "my fun". Yeah you are right, I was execting a friendler result that the one I obtained, but I must say it's even simpler than what I thought. Thanks a lot guys, problem solved (99% sure). I'm too exhausted to post the full answer right now. If anyone care, just ask me and I'll post it.

5. Oct 2, 2012

### jbunniii

Nice! Glad it worked out. I still remember the day as an undergraduate when I had sweated through some similarly horrible thing, and then the teaching assistant goes over the solution and says "well, first of all, let's make this problem easier by changing the variables..."

6. Oct 2, 2012

### Ray Vickson

Yes, please post it.

BTW: your initial post gave a wrong formula for fX(x).

RGV

7. Oct 3, 2012

### fluidistic

Here are my results: $f_X(x)=\frac{1}{\sqrt{2\pi} \sigma _X} \exp \left [ -\frac{1}{2} \left ( \frac{x-\mu _X}{\sigma _X} \right )^2 \right ]$.
$f_Y(y)=\frac{1}{\sqrt{2\pi} \sigma _Y} \exp \left [ -\frac{1}{2} \left ( \frac{y-\mu _Y}{\sigma _Y} \right )^2 \right ]$.
Mean of $f_X(x)$, $\langle X \rangle = \mu _X$.
Mean of $f_Y(y)$, $\langle Y \rangle = \mu _Y$.
Furthermore, $\langle X ^2 \rangle = \mu _X ^2+ \sigma _X ^2$ and $\langle Y ^2 \rangle = \mu _Y ^2+ \sigma _Y ^2$ so that the variances are $\text{var} (f_X(x))= \sigma _X^2$ and $\text{var} (f_Y(y))= \sigma _Y^2$.
I must also get the covariance matrix which involves calculating the term $\langle XY\rangle = \int _{-\infty}^{\infty} \int _{-\infty}^{\infty} f(x,y)xydxdy$. I guess I must look at an integral table to do $\int f_{XY} (x,y)xdx$.

8. Oct 3, 2012

### Ray Vickson

These are the correct marginals, etc.

To calculate $E[(X-\mu_X)(Y - \mu_Y)]$ you do not need to use integration tables. The first step would be to simplify everything by following previous suggestions, and use variables
$$Z_1 = \frac{X - \mu_X}{\sigma_X}, \; Z_2 = \frac{Y - \mu_Y}{\sigma_Y}.$$ The function
$f_{Z_1 Z_2}(z1,z2) \equiv g(z_1,z_2)$ is much, much simpler than the original, and then all you need to do is calculate
$$\int_{-\infty}^{\infty}\, \int_{-\infty}^{\infty} z_1 z_2 g(z_1,z_2) \, dz_1 \, dz_2.$$ It is fairly easy to do the z2 integral first, then do the z1 integral. Both integrals just rely on already-known values of gaussian integrals.

RGV

Last edited: Oct 3, 2012
9. Oct 5, 2012

### fluidistic

Thanks for helping me again. I don't really understand how the change of variable could be helpful nor why what you wrote holds. Nor do I understand why the z_2 integral is easier than the z_1 first, to me they look absolutely symmetric, so the same algebra. I also do not see how we get rid of an integral of the type $\int x e^{x^2}dx$.

10. Oct 5, 2012

### Ray Vickson

Do whichever one you want first, but pick one and do it first. Why change variables? Because it is 100 times easier to do it in z1,z2 than in x,y. However, it is absolutely NOT NECESSARY: just use the original form if you like doing lots of work and have lots of spare time.

RGV

11. Oct 6, 2012

### fluidistic

Ok I don't have that much time and I'd rather use the change of variables.
Please correct me where I'm wrong:
$$f_{Z_1Z_2}(z_1,z_2)=\frac{1}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}}\exp \left [ -\frac{1}{2 (1-\rho ^2)} (z_1 ^2 +z_2 ^2-2\rho z_1 z_2 ) \right ]$$.
The first integral would be $$\int _{-\infty}^{\infty} \frac{z_1}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}}\exp \left [ -\frac{1}{2 (1-\rho ^2)} (z_1 ^2 +z_2 ^2-2\rho z_1 z_2 ) \right ] dz_1$$. Is this correct so far?

12. Oct 6, 2012

### Ray Vickson

It is OK if you eliminate σX and σY in the denominator. The change of variable gets rid of the σ, because dz1 = dx/σX, etc.

RGV

Last edited: Oct 6, 2012
13. Oct 6, 2012

### fluidistic

Ok I understand, this is what I thought at first but then... I don't understand the integral.
Since $z_1=\frac{x-\mu _X}{\sigma _X}$ the integral $$\int _{-\infty}^{\infty} \frac{z_1}{2\pi \sigma _Y \sqrt{1-\rho ^2}}\exp \left [ -\frac{1}{2 (1-\rho ^2)} (z_1 ^2 +z_2 ^2-2\rho z_1 z_2 ) \right ] dz_1$$ (1) is not equivalent to the integral $$\int _{-\infty}^{\infty }\frac{x}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}} \exp \{ \left [ -\frac{1}{2(1-\rho ^2)} \right ] \left [ \left ( \frac{x-\mu _X}{\sigma _X} \right )^2 + \left ( \frac{y-\mu _Y}{\sigma _Y} \right )^2 -\frac{2\rho (x-\mu _X)(y-\mu _Y)}{\sigma _X \sigma _Y} \right ] \} dx$$ (2).
Oh wait, so it would mean that (2) is equivalent to $(1) -\frac{f_Y(y)\mu_X}{x}$?

14. Oct 6, 2012

### Ray Vickson

What on Earth are you talking about? Just get rid of the denominator $\sigma_X \sigma_Y$ in your (z1,z2) integral. Have you never studied changes of variables in integration?

RGV

15. Oct 6, 2012

### fluidistic

I have studied change of variables in integration but I'm stuck at understanding the change of variable you use in post #8.
From what I understand you are saying that to simplify the computation of $$\int _{-\infty}^{\infty} \int _{-\infty}^{\infty} \frac{xy}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}} \exp \{ \left [ -\frac{1}{2(1-\rho ^2)} \right ] \left [ \left ( \frac{x-\mu _X}{\sigma _X} \right )^2 + \left ( \frac{y-\mu _Y}{\sigma _Y} \right )^2 -\frac{2\rho (x-\mu _X)(y-\mu _Y)}{\sigma _X \sigma _Y} \right ] \}dxdy$$ it is equivalant to calculate $\int _{-\infty}^{\infty} \int _{-\infty}^{\infty} z_1z_2g(z_1,z_2)dz_1dz_2$ but if you replace $z_1$ and $z_2$ by $\frac{x-\mu _X}{\sigma _X}$ and $\frac{y-\mu _Y}{\sigma _Y}$ respectively, then you get $$\int _{-\infty}^{\infty} \int _{-\infty}^{\infty} z_1z_2g(z_1,z_2)dz_1dz_2= \int _{-\infty}^{\infty} \int _{-\infty}^{\infty} \left ( \frac{x-\mu _X}{\sigma _X} \right ) \left ( \frac{y-\mu _Y}{\sigma _Y} \right ) \cdot \frac{1}{2 \pi \sqrt{1-\rho ^2}} \cdot \exp \{ \left [ -\frac{1}{2(1-\rho ^2)} \right ] \left [ \left ( \frac{x-\mu _X}{\sigma _X} \right )^2 + \left ( \frac{y-\mu _Y}{\sigma _Y} \right )^2 -\frac{2\rho (x-\mu _X)(y-\mu _Y)}{\sigma _X \sigma _Y} \right ] \}dxdy$$. Clearly this is not equal to what we started with, namely $$\int _{-\infty}^{\infty} \int _{-\infty}^{\infty} \frac{xy}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}} \exp \{ \left [ -\frac{1}{2(1-\rho ^2)} \right ] \left [ \left ( \frac{x-\mu _X}{\sigma _X} \right )^2 + \left ( \frac{y-\mu _Y}{\sigma _Y} \right )^2 -\frac{2\rho (x-\mu _X)(y-\mu _Y)}{\sigma _X \sigma _Y} \right ] \}dxdy$$.
I know I'm missing something but I don't know what.

16. Oct 7, 2012

### Ray Vickson

This will be absolutely the last time I respond.
(1) What is the relation between Cov(X,Y) and Cov(Z1,Z2)?
(2) What is the formula for Cov(Z1,Z2)?
(3) The density $f_{Z_1,Z_2}(z_1,z_2) \equiv g(z_1,z_2)$ should not have any parameters $\sigma_X, \; \sigma_Y$ in it, but it will still contain $\rho.$

RGV

17. Oct 21, 2012

### fluidistic

Hey guys I'm still stuck on this problem; if someone could push me a little further I'd be happy.
Okay no problem
I don't know.
I don't know either. I'm asked to find the covariance matrix, namely $\begin{bmatrix} <X^2>-<X>^2 &<YX>-<Y><X> \\ <XY>-<X><Y> & <Y^2>-<Y>^2 \end{bmatrix}$; I've all the terms except <XY>=<YX> and this is where I'm stuck.
Yes I noticed this, that's because the $dz_i$'s contain a $\sigma _x dx$ and $\sigma _y dy$.

18. Oct 21, 2012

### fluidistic

Ok I've made more progresses thanks to Ray Vickson's last post.
I didn't realize that the coefficient I'm looking for in the matrix, namely $<XY>-<X><Y>$ is the covariance between X and Y (yes I'm a total newbie I know).
More than this, the covariance between X and Y is definied as $cov(x,y)=\iint dxdy (x-\mu _X)(y-\mu _Y)f_{XY}(x,y)$. I was not taught this, that's why nothing clicked in my mind.
So now I UNDERSTAND why the change of variable $z_i=\frac{x_i-\mu _i}{\sigma _i}$ works!!!
I can answer your question now Ray Vickson: $cov(x,y)=\sigma _X \sigma _Y cov(z_1,z_2)$.
I have that $cov(z_1, z_2)=\iint \sigma _X \sigma _Y dz_1 dz_2 z_1 z_2 \sigma _X \sigma _Y \cdot \frac{1}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}}\exp \{ \left [ -\frac{1}{2(1-\rho^2)} \right ] (z_1^2+z_2^2-2 \rho z_1 z_2) \}$.
So that $cov(z_1,z_2)=\frac{\sigma _X \sigma _Y}{2\pi \sqrt{1-\rho ^2}} \int _{-\infty}^{\infty}\int _{-\infty}^{\infty} z_1 z_2 \exp \{ \left [ -\frac{1}{2(1-\rho ^2)} \right ] (z_1^2+z_2^2 -2\rho z_1 z_2 \}$.
So I can concentrate on the integral of $z_1$ first.
I have it under the form $\int _{-\infty}^{\infty} z_1 \exp (-az_1^2+bz_1)dz_1$ where $a=\frac{1}{2(1-\rho ^2 )}$ and $b=\frac{\rho z_2}{1-\rho ^2}$.
I'm having troubles solving this integral. I tried by parts by calling $u=z_1$, $v'=\exp (-az_1^2+bz_1)$ so that $u'=1$ and $v=\frac{1}{2} \sqrt {\frac{\pi}{a}} erf \left ( \frac{2a z_1 -b}{2 \sqrt a} \right ) e^{b^2/(4a)}$.
And so that integral is worth $uv \big | _{-\infty}^{\infty} - \int _{-\infty}^{\infty} vdu$.
First huge problem: uv evaluated in infinities is infinite, because the erf function is worth -1 at -infinity and 1 at infinity but the u part ($z_1$) is not finite there. Hence the integral diverges... which is I know, wrong.
Second big problem, I don't know a primitive of the erf function.

Ray Vickson said there is no need to look at integral tables and that it's fairly easy to solve (post #8). I do not see any substitution that could help me and integral by parts shows that it's divergent (I don't know where lies my error) while it's not.
Any help would be appreciated.

19. Oct 22, 2012

### fluidistic

I'm totally lost guys and exhausted.
I could solve the integral of the last post.
At the end I reached that $\iint \sigma _X \sigma _Y dz_1 dz_2 z_1 z_2 \sigma _X \sigma _Y \cdot \frac{1}{2\pi \sigma _X \sigma _Y \sqrt{1-\rho ^2}}\exp \{ \left [ -\frac{1}{2(1-\rho^2)} \right ] (z_1^2+z_2^2-2 \rho z_1 z_2) \} = \sigma _X \sigma _Y \rho \frac{(1-\rho ^2 )^{3/2}}{[1-/(1-\rho ^2) \rho ^2]^{3/2}}$. It's almost obvious I made at least one error somewhere and that I should have reached $\sigma _X \sigma _Y \rho$. I know this is worth cov(X,Y) and I thought it was worth cov (Z_1, Z_2) but I don't think it's true now.
I don't know the relation between cov (X, Y) and cov (Z_1, Z_2).

20. Oct 27, 2012

### fluidistic

Hi guys! I've finnally reached the desired result!!!! (1 min ago!)
I reached $cov(x,y)=\sigma _X \sigma _Y \rho$. I just had to be extremely careful and solve 2 "nasty" integrals (one with a very "tough" trick, i.e. rewriting of the integral into something to make a u substitution and the other by parts).
Problem solved.