Conditional expectation

In words...

The conditional expectation of a random variable given another one yields the mean value of the first variable for each particular value of the second one.

In picture...


In maths...

Conditional expectation for a discrete random pair

Given a discrete random pair $(X,Y)\in\X\times\Y$, the conditional expectation of $X$ given $Y$ is the random variable $$ \E_{X|Y} [ X\ |\ Y=y ] = \sum_{x\in\X} x \ P(X=x\ |\ Y = y ) = \sum_{x\in\X} x \ \frac{P(X=x,\ Y=y)}{P(Y=y)} , $$ i.e., it is the sum of all possible values taken by $X$ weighted by their conditional probabilities.

More generally, with a function $f : \X\times\Y \rightarrow \R$, we have $$ \E_{X|Y} [ f(X,Y)\ |\ Y=y ] = \sum_{x\in\X} f(x,y) \ P(X=x\ |\ Y = y ) = \sum_{x\in\X} f(x,y) \ \frac{P(X=x,\ Y=y)}{P(Y=y)} . $$

Conditional expectation for a continuous random pair

Given a continuous random pair $(X,Y)\in\X\times\Y$, the conditional expectation of $X$ given $Y$ is (if it exists) $$ \E_{X|Y} [ X\ |\ Y=y ] = \int_{\X} x\, p_{X|Y}(x|y) dx = \int_{\X} x\, \frac{p_{X,Y}(x, y)}{p_Y(y)} \ dx , $$ where $p_{X|Y}$ is the conditional probability density function of $X$ given $Y$.

More generally, for a function $f : \X \rightarrow \R$, we have $$ \E_{X|Y} [ X\ |\ Y=y ] = \int_{\X} f(x,y)\, p_{X|Y}(x|y) dx = \int_{\X} f(x,y)\, \frac{p_{X,Y}(x, y)}{p_Y(y)} \ dx . $$