how to find the expected value of a joint density function? I have to find the covariance of this joint density function
$$f(x,y) =
\begin{cases}
\ xe^{-x(y+1)},  & \text{if } x > 0,\ y > 0 \\[2ex]
0, & \text{otherwise}
\end{cases}$$
for $E[XY]$ do I integrate $\int_0^\infty \int_0^\infty xy f(x,y) \, dy\,dx$?
and for $E[X]$ do I find the marginal of $X$ and integrate or do I integrate $\int_0^\infty\int_0^\infty x f(x,y) \, dy \, dx$?
 A: To find the expected value $\operatorname{E}(G(X,Y))$ where $G$ is any function of two variables you can find
$$
\int_0^\infty \int_0^\infty G(x,y) f(x,y)\,dy\,dx
$$
and that's it.  If $G(x,y)=xy$ then you have just the integral you wrote and if $G(x,y)=x$ then you get this:
$$
\int_0^\infty \int_0^\infty x f(x,y)\,dy\,dx. \tag 1
$$
Notice that $(1)$ is
$$
\int_0^\infty \left(\int_0^\infty x f(x,y)\,dy\right)\,dx
$$
and in the inside integral
$$
\int_0^\infty x f(x,y)\,dy
$$
the variable $x$ does not change as $y$ goes from $0$ to $\infty$, so the inside integral is the same as
$$
x\int_0^\infty f(x,y)\,dy
$$
and that is $x$ times the marginal density of $X$.  So finding $(1)$ is the same as integrating $x$ times the marginal density of $X$ from $0$ to $\infty$.
There is also the question of whether it is more efficient to find
$$
\int_0^\infty \int_0^\infty x f(x,y)\,dy\,dx \quad\text{or}\quad \int_0^\infty \int_0^\infty x f(x,y)\,dx\,dy.
$$
In the second form, you can't pull $x$ out of the inside integral the way you can in the first form.
