Law of total expectation with conditional expectations

I am confused between these two equations which use the law of total expectation: $$E(X|Y)=E(X|Y,Z)P(Z)+E(X|Y,Z')P(Z')$$ $$E(X|Y)=E(X|Y,Z)P(Z|Y)+E(X|Y,Z')P(Z'|Y)$$ where Z' is the complement of Z. The first one makes sense to me because if one defines the random variable $$A=X|Y$$, then it is simply using the law of total expectation. The other also makes sense as it is as if we are applying the law of total probability on $$X$$ but then reducing the universe to the "given Y" subspace. Which one is right?

In general, is thinking of X given Y and Z the same as X given Y, given Z? $$P(X|Y,Z)=P((X|Y)|Z)$$

• What does “not $Z$” mean? If $Z$ is a real valued random variable then the logical negation of $Z$ is nonsense. If $Z$ is an event, then $Z’$ is the complement of this event with respect to the sample space. (Further, many authors discourage the notation $A=X|Y$ to denote a “conditional RV”. Pedantically there is no such thing as a “conditional RV” rather we talk about RVs having a conditional distribution conditional on some event, some RV, or in general, some $\sigma$-algebra.) Nov 15, 2019 at 20:47

Your second equation is correct, and the first one is wrong. Here is an example.

In my example, $$X,Y,Z$$ are events, i.e. subsets of the sample space $$\Omega$$. If you wish to have them be random variables, then consider their indicator variables. As is well known, $$P(A) = E[1_A]$$

• Pick a number $$\in \Omega = \{1,2,3\}$$, uniformly randomly, i.e each with equal prob $${1 \over 3}$$.

• $$X = \{1\}, Y = \{1,2\}, Z = \{2,3\}$$

• $$Y\cap Z = \{2\}$$ and $$Y \cap Z' = \{1\}$$

• $$P(X\mid Y) = 1/2$$

• $$P(X\mid Y,Z) = 0$$ and $$P(X \mid Y,Z') = 1$$

• 1st RHS $$= P(X \mid Y,Z) P(Z) + P(X\mid Y,Z') P(Z') = 0\times \frac23 + 1 \times \frac13 = \frac13 \neq P(X \mid Y)$$

• 2nd RHS $$= P(X \mid Y,Z) P(Z \mid Y) + P(X\mid Y,Z') P(Z' \mid Y) = 0 \times \frac12 + 1 \times \frac12 = \frac12 = P(X \mid Y)$$

More generally, lets expand:

$$\begin{array}{} P(X \mid Y) &= {P(X, Y) \over P(Y)}\\ &={P(X,Y,Z) + P(X,Y,Z') \over P(Y)}\\ &={P(X \mid Y,Z) P(Y,Z) + P(X \mid Y,Z') P(Y, Z') \over P(Y)}\\ &=P(X\mid Y,Z) {P(Y,Z) \over P(Y)}+ P(X \mid Y,Z') {P(Y,Z') \over P(Y)}\\ &=P(X \mid Y,Z) P(Z \mid Y) + P(X \mid Y,Z') P(Z' \mid Y) \end{array}$$

The way I remember is that conditioning on $$Y$$ creates its own probability law, so the correct equations look like Law of Total Probability/Expectation but within the event $$Y$$, i.e. every term is conditioned on $$Y$$.