Find the Marginal Distribution of a density function and E[X] and E[Y] I have a question on a practice exam paper on Marginal densities. I have answered it and think my answer is correct but would like someone to check for me as i do not have the full solutions. 
Let X and Y have joint density $f(x,y)=1/x$ on $0<y<x<1$ and zero otherwise. 
I need to find the Marginal Densities of $X$ and $Y$ and $E[X]$ and $E[Y]$
To find the Marginal Densities of $X$ and$Y$ I have checked that
$$\int\int_R f(x,y) \, dx \, dy = 1=
\int_{0}^1\int_{y}^1 1/x \, dx \, dy$$
Then i have that the marginal density of X is $0$ for $x<0$, $x=0$ and for $x>0$ we have
$$f_X(x)=\int_{0}^x 1/x \, dy = [y/x]=x/x = 1$$
and i have that the marginal density of $Y$ is $0$ for $y<0$, $y=0$ and for $y>0$ we have
$$f_Y(y)=\int_{y}^0 1/x \, dx = [\ln x]= -\ln x$$
Now to find $E[X]$ and $E[Y]$ I have 
$$E[X] =\int_{0}^1 xf_X(x) \, dx=\int_{0}^1 (x)(1) \, dx =\int_{0}^1 x \, dx = [x]=1$$
$$E[Y] =\int_{0}^1 yf_Y(y) \, dy=\int_{0}^1 (y)(-\ln y) \, dy = [1/4y^2(1-2\ln y)]=1/4$$
Could someone please tell me if I have done this correctly, and if not, please point out where I have gone wrong and why?
Many thanks
 A: A spectacular example of the mess and head-scratching that can occur when one fails to write down densities rigorously. Recall that the density of a couple $(X,Y)$ of random variables is always a function $f$ defined on the whole real plane. Here, using the proper (and crucial) indicator function,
$$
f:\mathbb R^2\to\mathbb R_+,\qquad (x,y)\mapsto x^{-1}\mathbf 1_{0\lt y\lt x\lt 1}.
$$
My stance is that, if one starts from this writing (a benign modification if ever there was such), one cannot fail...
Density of $X$? This is the function $f_X$ defined on the whole real line by
$$
f_X(x)=\int_\mathbb Rf(x,y)\mathrm dy=\int_\mathbb Rx^{-1}\mathbf 1_{0\lt y\lt x\lt 1}\mathrm dy.
$$
To factor as many terms that does not depend on $y$ as one can, use the identity $\mathbf 1_{0\lt y\lt x\lt 1}=\mathbf 1_{0\lt x\lt1}\mathbf 1_{0\lt y\lt x}$ (do you agree that it holds?). Thus,
$$
f_X(x)=x^{-1}\mathbf 1_{0\lt x\lt1}\int_\mathbb R\mathbf 1_{0\lt y\lt x}\mathrm dy=x^{-1}\mathbf 1_{0\lt x\lt1}\int_0^x\mathrm dy=\mathbf 1_{0\lt x\lt1}.
$$
And it always works... Density of $Y$? This is the function $f_Y$ defined on the whole real line by
$$
f_Y(y)=\int_\mathbb Rf(x,y)\mathrm dx=\int_\mathbb Rx^{-1}\mathbf 1_{0\lt y\lt x\lt 1}\mathrm dx.
$$
This time, rewrite the indicator function as $\mathbf 1_{0\lt y\lt x\lt 1}=\mathbf 1_{0\lt y\lt1}\mathbf 1_{y\lt x\lt1}$ (correct?). Thus,
$$
f_Y(y)=\mathbf 1_{0\lt y\lt1}\int_\mathbb Rx^{-1}\mathbf 1_{y\lt x\lt 1}\mathrm dx=\mathbf 1_{0\lt y\lt1}\int_y^1x^{-1}\mathrm dx=(-\log y)\mathbf 1_{0\lt y\lt1}.
$$
See? This cannot fail...
