Given that $X$ and $Y$ are two independent random variables uniform on $[0, 1]$, and having the joint density:
$$f(x,y) = 2\,,\,\,\,\,\,\,0\leq x \leq y $$
Find $E[X\,|\,Y= y]$ and $E[Y\,|\,X = x]$.
Known Solution:
$$E[X\,|\,Y= y] = \frac{Y}{2}$$
$$E[Y\,|\,X = x] = \frac{X+1}{2}$$
My Approach (which apparently is wrong):
Given $f(x,y) = 2$, we have:
$$f_X(x) = \int_0^1 2 dy = 2 \,\,\,\, \textrm{and}\,\,\,\, f_Y(y) = \int_0^y 2 dx = 2y$$
From this, we can compute:
$$p_{Y|X}(y|x) = \frac{f(x,y)}{f_X(x)} = \frac{2}{2} = 1 \,\,\,\,\textrm{and}\,\,\,\, p_{X|Y}(x|y) = \frac{f(x,y)}{f_Y(y)} = \frac{2}{2y} = \frac{1}{y}$$
Therefore we have:
$$E[X\,|\,Y = y] = \int_0^y x \cdot p_{X|Y}(x|y) dx = \int_0^y x\cdot \frac{1}{y} dx = \frac{1}{y}\left[\frac{x^2}{2}\right]_0^y = \color{green}{\frac{y}{2} \textrm{(which seems to be right)}}$$
and
$$E[Y\,|\,X = x] = \int_0^1 y \cdot p_{Y|X}(y|x) dy = \int_0^1 y \cdot 1\, dy = \color{red}{\frac{1}{2} \textrm{(WHICH IS WRONG!)}}$$
Can someone please explain to me what am I doing wrong? Thanks in advance!
The answer to your question is simple: do not forget your indicator functions. More specifically, the marginal density of $X$ is wrong. To see why, just note that the joint density is $$ f(x,y)=2\mathbf{1}_{0<x<y<1} $$ and hence the marginal density of $X$ is given by $$ f_X(x)=\int_{\mathbb{R}} f(x,y)\,\mathrm dy=\int_x^1 2\,\mathrm dy,\quad 0<x<1. $$ The density of $Y$ is correctly specified though.