# The expectation and variance in case of dependency

I have the following question:

We have that $$Z = IB + (1-I)0$$ and $$P(I=1)=q , P(I=0)=1-q$$ Now calculate the expectation and variance of Z and don't assume that B and I are independent.

The E[Z] was not hard to find:

$$E[Z] = E[IB] = E[E[IB|I]] = E[IE[B|I]] = E[I]E[B|I] = qE[B|I].$$

Using the following rule Var[Z] = E[Var(Z|I)] + Var(E[Z|I]) we should be able to obtain the variance of Z.

$$Var(E[Z|I]) = Var( IE[B|I]) = E[B|I]^2 Var(I) = E[B|I]^2*q(1-q)$$

Now, I have problems with the other term... I know that $$Var(Z|I) = I^2 Var(B)$$ so $$E[Var(Z|I)] = E[I^2 Var(B)]$$

However, the final answer should be: $$Var[Z] = q Var(B) + q (1-q) E[B]^2$$

Now, I don't understand these last steps:

$$E[I^2 Var(B)]=Var(B)Var(I^2)=qVar(B)$$

Can anyone tell me how these last steps work? Thanks!

• I don't get the one before last step for $\mathbb E[Z]$, before that step you have a number, after that step you have a random variable. I think you need to have $\mathbb E[Z]=q \mathbb E[B|I=1]$ – P. Quinton Apr 25 at 16:48
• I think you are correct, because: $$E[Z]=E[IB]=E[E[IB|I]]$$ (the tower rule) $$=E[IE[B|I]]= 1*E[B|I=1]*P[I=1] + 0*E[B|I=0]*P[I=0]=q*E[B|I=1]$$. Can you also help me with the steps for finding the variance of Z? – Pam Apr 26 at 9:12
• Well the second term has the same issue, it should be something like $Var(\mathbb E[Z|I])=\mathbb E[\mathbb E[Z|I]^2]-\mathbb E[\mathbb E[Z|I]]^2=q \mathbb E[B|I=1]^2-q^2 \mathbb E[B|I=1]^2=q(1-q)\mathbb E[B|I=1]^2$. – P. Quinton Apr 26 at 10:41
• The last term should be $\mathbb E[(Z-\mathbb E[Z|I])^2|I]=I^2 \mathbb E[(B-\mathbb E[B|I])^2|I]=I E[(B-\mathbb E[B|I])^2|I]$ hence taking the expectation you get that $\mathbb E[Var(Z|I)]=q Var(B|I=1)$. Combining I don't get the same result as you, where does it come from ? – P. Quinton Apr 26 at 10:56