# Expected value of a conditional Y given X, $E(Y|X)$ is or is not a constant?

For a random variable $$X$$, there is an expected value $$E(x)$$. Since $$E(X) = \mu \in \mathcal{R}$$ where $$\mu$$ is a mean, and can be viewed as a constant. If this is true, then $$E(E(X)) = E(\mu) = \mu$$ by linearity and property of expectation.

However, my confusion sets in when I try to apply this logic in trying to understand the law of total expectation that is $$E(Y) = E(E(Y|X))$$. If I know that X is given, then it is appropriate to characterize $$E(Y|X)$$ as a constant, according to previous logic, such that $$E(E(Y|X)) = E(Y|X)$$, but $$E(Y) = E(E(Y|X)) \neq E(Y|X)$$

Can anybody give me a hand here? Thanks.

• The outer "$E$" is taken with respect to $X$, so, although at the time of evaluating $E(Y|X)$ $X$ is a constant, at the time of evaluating the outer expectation in the expression $E[E(Y|X)]$, $X$ is not. Dec 12 '19 at 19:28
• Another way to say this is that $\operatorname E(Y|X)$ is still a random variable and it is being averaged w.r.t. the marginal distribution of $X$
– jld
Dec 12 '19 at 19:33
• thanks a lot for the clarification Dec 12 '19 at 19:52

The conditional expectation $$E(Y|X=x)$$ is a function $$g(x)$$ of $$x$$. For a fixed value $$x$$ this is not a random variable. The notation $$E(Y|X)$$ (a slight abuse of notation since $$X$$ is not an event) is shorthand for $$g(X)$$. This is a random variable and hence we can talk about $$Eg(X)=E(E(Y|X))$$ which according to the law of total exectation equals $$EY$$.