# How to prove this property of conditional expectation $E(X f(Y) )=E(E(X|Y)f(Y))$

If assume X, Y are discrete random variables and develop the left hand side get that \begin{align} E(E(X|Y)f(Y))&=\sum_y E(E(X|Y)f(Y))P(Y=y)\\ &=\sum_y \sum_x xP(X=x|Y=y)f(Y=y)P(Y=y)\\ &=\sum_y \sum_x x\frac{P(X=x,Y=y)}{P(Y=y)}f(Y=y)P(Y=y)\\ &=\sum_y \sum_x xP(X=x,Y=y)f(Y=y)\\ &=\sum_x x\sum_y P(X=x,Y=y)f(Y=y)\\ \end{align}

I don't know how to remove the f(y). i tried to develop that to continuos random variables but i have the same problem.

• It is easy to prove that $E[X]=E[E[X|Y]]$ for discrete (and continuous) random variables. I'd say: $E[Xf(Y)]=E[E[Xf(Y)|Y]]=E[f(Y)E[X|Y]]$ where you can pull out $f(Y)$ because you are conditioning over a value of $Y$, so $f(Y)$ becomes a constant. Not sure tho... Commented May 21, 2022 at 18:36
• @Usmur That is true. Commented May 21, 2022 at 19:05
• @Mason Thank you for checking it, gonna write an answer for that Commented May 21, 2022 at 19:10
• You should write $f(y)$ instead of $f(Y=y)$.
– user140541
Commented May 21, 2022 at 19:12

## 1 Answer

Let $$X, Y$$ random variables with distribution $$f_X$$, $$f_Y$$ (and $$f_{X|Y}$$ distribution of $$X|Y$$), then $$E[X]=E[E[X|Y]]$$.

Proof

\begin{align}E[E[X|Y]] &= \int E[X|Y]f_Y(y)dy \\ &=\int \left[\int xf_{X|Y}(x,y)dx \right]f_Y(y)dy\\ &=\int \int xf_{X|Y}(x,y)f_Y(y) dxdy\\ &=\int\int x f_{X,Y}(x,y)dydx \\ &=\int x\left[\int f_{X,Y}(x,y)dy \right]dx \\ &=\int xf_X(x)dx\\ &=E[X] \end{align}

From this we can write:

$$E[Xf(Y)]=E[E[Xf(Y)|Y]]=E[f(Y)E[X|Y]]$$ where you can take $$f(Y)$$ out because it is in the expected value conditioned over a value of $$Y$$