# Finding the joint pdf and then calculating the covariance

Let the joint probability distribution of X and Y be $f(x,y)=Te^{-x-y}$ for $0<y<x<\infty$

Find cov(X,Y)

My approach is to first find T. I did this by evaluating T from:

$\int_0^\infty\int_0^xTe^{-x-y}dydx=1$

I got T=2. Is this correct?

Next, I want to use $Cov(X,Y)=E(XY) - E(X)E(Y)$

However, I'm having a problem in getting the marginal distribution of x. I was doing $\int_0^\infty2e^{-x-y}dy$ but this leads to $2e^{-x}$ which is wrong because it is not a valid pdf.

• In the marginal, the integral should be from 0 to $x$ not $0$ to $\infty$. Commented Jul 3, 2017 at 9:02

A good way to check one's results is to use a completely different analysis. I will offer two: statistical reasoning and simulation.

### Statistical reasoning

The density is proportional to the product $$e^{-x}e^{-y}$$, which is instantly recognizable as the product of Exponential densities, and the only additional restriction is $$y \lt x$$. That shows us $$(y,x)$$ have the same distribution as the order statistics of two independent exponential variables. That is, letting $$Z_1$$ and $$Z_2$$ be those variables, set $$Z_{(1)} = \min(Z_1,Z_2)$$ and $$Z_{(2)}=\max(Z_1,Z_2)$$. The vector $$(Z_{(1)}, Z_{(2)})$$ has the same distribution as $$(y,x)$$.

Let the expectation of an Exponential variable be $$\mu=1$$. Then because $$Z_1+Z_2 = Z_{(1)}+Z_{(2)}$$ and $$Z_{(1)}Z_{(2)}=Z_1Z_2$$,

$$E(x+y) = E(Z_{(1)}+Z_{(2)}) = E(Z_1 + Z_2) = E(Z_1)+E(Z_2) = 2\mu=2\tag{1}$$

and

$$E(xy) = E(Z_{(1)}Z_{(2)}) = E(Z_1Z_2) = E(Z_1)E(Z_2) = \mu^2=1\tag{2}.$$

The Exponential distribution is memoryless: this means that $$x-y$$, conditional on $$x \gt y$$, also has an Exponential distribution. Thus

$$E(x)-E(y) = E(x-y) = \mu = 1\tag{3}.$$

The simultaneous linear equations $$(1)$$ and $$(3)$$ have the unique solution

$$E(y)=1/2,\ E(x) = 3/2.\tag{4}$$

Plug $$(2)$$ and $$(4)$$ into a standard formula for the covariance:

$$\operatorname{Cov}(x,y) = E(xy) - E(x)E(y) = 1 - \frac{3}{2}\frac{1}{2}=\frac{1}{4}.$$

### Simulation

It's fast and easy to draw realizations $$(x,y)$$ from this distribution. The most obvious way--although it's a little inefficient--is to draw positive $$(x,y)$$ from the distribution with density $$e^{-x-y}$$ and discard any for which $$y \ge x$$. Since this density factors into $$e^{-x}e^{-y}$$, it suffices to draw an independent pair from the univariate distribution with density $$e^{-x},\ x\gt 0$$: the Exponential. The sample moments for a large set of realizations ought to approximate those of the underlying distribution. Here is R code to produce and analyze approximately a million such realizations; it takes one second to run.

n <- 2e6
set.seed(17)
a <- matrix(rexp(2*n), ncol=2)
a <- a[a[,2] < a[,1], ]
x <- a[,1]
y <- a[,2]
signif(c(E.xy=mean(x*y), E.x=mean(x), E.y=mean(y), Cov=cov(x,y)), 3)


The output is

E.xy  E.x  E.y  Cov
1.00 1.50 0.50 0.25


The values agree exactly with the preceding solution to the three significant figures shown.

• Should I get the same answer by evaluating $E(xy)=\int_0^\infty\int_0^x2xye^{-x-y}dydx$ then subtracting by (1.5)(0.5)? Why are X and Y considered independent when Y is restricted to be less than X? Commented Jul 4, 2017 at 22:03
• Yea, I got it wrong. I evaluated the above expectation again and got 1. Thanks! Commented Jul 4, 2017 at 22:15
• I don't know what you mean by "X" and "Y". If they are the same as "x" and "y", then you're right: they're not independent. The point is that $Z_1$ and $Z_2$ are independent. That makes them easier to work with.
– whuber
Commented Jul 5, 2017 at 12:45

Thanks to @Greenparker for pointing out where I got it wrong.

So I solved the following to get to the answer:

$f(x)=\int_0^x2e^{-x-y}dy=2e^{-x}-2e^{-2x}$

$E(x)=\int_0^\infty x(2e^{-x}-2e^{-2x})dx=1.5$

$f(y)=\int_y^\infty 2e^{-x-y}dy=2e^{-2y}$

$E(y)=\int_0^\infty 2e^{-2y}=0.5$

$E(xy)=\int_0^\infty\int_0^x2xye^{-x-y}dydx=1$

So, $COV(xy)=1-(1.5)(0.5)=\frac{1}{4}$

• Since $X$ takes on positive values only, warning bells ought to go off in your mind when you find that $E[X]$ -- the average value of $X$ -- is a negative number.... Commented Jul 3, 2017 at 22:45
• Sorry about that. Yes, that should be $1.5$. I made a mistake in evaluating the integral. Commented Jul 3, 2017 at 22:55