# Deduce the formula for conditional expectation via basic definition in sigma-algebra.

I am trying to deduce the formula for conditional expectation $$\mathbb{E}(X\mid Y) = \int_{-\infty}^{\infty} x \cdot f_{X|Y}(x|y)dx = \int_{-\infty}^{\infty} x \cdot \frac{f_{X,Y}(x,y)}{f_Y(y)}dx,$$ through the basic definition of conditional expectation.

Recall the definition of conditonal expectation $\mathbb{E}(X|\mathcal{H})$, suppose probability space $(\Omega, \mathcal{F}, \mathbb{P})$, and $\mathcal{H} \subset \mathcal{F}$, $\forall H \in \mathcal{H}$, \begin{equation} \int_{H} \mathbb{E}(X\mid \mathcal{H})d\mathbb{P} = \int_{H} Xd\mathbb{P}. \end{equation} My try:

Basically, we consider the $\mathcal{H} = \sigma(Y)$ is the $\sigma-$algebra generated by $Y$, the definition is equivalent to, $\forall B \in \mathcal{B}$, $$\int_{Y^{-1}(B)} \mathbb{E}(X\mid Y)d\mathbb{P} = \int_{Y^{-1}(B)} Xd\mathbb{P}.$$ Then, Taking the $B = (\infty, y),$

$$Left = \int_{\infty}^y \mathbb{E}(X\mid Y = y)d\mathbb{P}_Y = \int_{\infty}^y \mathbb{E}(X\mid Y = y)dF_Y(y) = \int_{\infty}^y \mathbb{E}(X\mid Y = y)\cdot f_Y(y)dy.$$ This result is pretty close to the solution. However, I have no idea to prove the $Right$, can anyone show me the proof for the following equation? Thanks. $$Right = \int_{Y^{-1}(B)}Xd\mathbb{P} = \int_{-\infty}^y \int_{-\infty}^{\infty}x \cdot f_{X,Y}(x,y)dxdy.$$

Note that, by definition (see Shiryaev), $\mathbb{E}(X\mid Y=y)$ is a Borel measurable function such that, for any Borel set $B$, \begin{align*} \int_{Y \in B} X dP = \int_B \mathbb{E}(X \mid Y=y) P_Y(dy), \end{align*} where $P_Y(dy)$ is the Lebesgue-Stieltjes measure generated by the distribution function of $Y$, that is $P_Y(B) = P(Y \in B)$. Since \begin{align*} \int_{Y \in B} X dP &= \mathbb{E}(X 1_{\{Y\in B\}})\\ &=\iint_{\mathbb{R}^2}x1_{\{y\in B\}}f_{X,Y}(x, y) dxdy\\ &=\int_{-\infty}^{\infty}\left(\int_{-\infty}^{\infty} x \frac{f_{X, Y}(x, y)}{f_Y(y)} dx\right)1_{\{y\in B\}}f_Y(y) dy\\ &=\int_B\left(\int_{-\infty}^{\infty} x \frac{f_{X, Y}(x, y)}{f_Y(y)} dx\right)f_Y(y) dy\\ &=\int_B\left(\int_{-\infty}^{\infty} x \frac{f_{X, Y}(x, y)}{f_Y(y)} dx\right) P_Y(dy), \end{align*} we deduce that \begin{align*} \mathbb{E}(X \mid Y=y) = \int_{-\infty}^{\infty} x \frac{f_{X, Y}(x, y)}{f_Y(y)} dx. \end{align*} See also related answers here, here, and here.