An example for conditional expectation A factory has produced n robots, each of which is faulty with probability $\phi$. To each robot a test is applied which detects the faulty (if present) with probability $\delta$. Let X be the number of faulty robots, and Y the number detected as faulty.
Assuming the usual indenpendence, determine the value of $\mathbb E(X|Y)$.
Please explain me the result in detail or give me a good hint pls, since I am very new to this concept (of conditional expectation).
Thanks!
 A: $\mathbb{E}\left[ {X|Y} \right]$ is a random variable. Since $Y$ is a discrete random variable, $\mathbb{E}\left[ {X|Y} \right]$ is of the form $\sum\limits_{i = 0}^n {\frac{{\mathbb{E}\left[ {X{1_{Y = i}}} \right]}}{{\mathbb{P}\left( {Y = i} \right)}}{1_{Y = i}}} $.
Let $F$ be the event that a robot is faulty and $D$ be the event that a robot is detected faulty. We have $\mathbb{P}\left( F \right) = \phi $, 
$\mathbb{P}\left( D \right) = \mathbb{P}\left( {D|F} \right)\mathbb{P}\left( F \right) + \mathbb{P}\left( {D|{F^C}} \right)\mathbb{P}\left( {{F^C}} \right) = \delta \phi  + 0\left( {1 - \phi } \right) = \delta \phi $, 
$\mathbb{P}\left( {F|{D^C}} \right) = \frac{{\mathbb{P}\left( {{D^C}|F} \right)\mathbb{P}\left( F \right)}}{{\mathbb{P}\left( {{D^C}|F} \right)\mathbb{P}\left( F \right) + \mathbb{P}\left( {{D^C}|{F^C}} \right)\mathbb{P}\left( {{F^C}} \right)}} = \frac{{\left( {1 - \delta } \right)\phi }}{{\left( {1 - \delta } \right)\phi  + \left( {1 - \phi } \right)}}$,
$\mathbb{P}\left( {F|D} \right) = 1$.
$\mathbb{E}\left[ {X{1_{Y = i}}} \right] = \mathbb{E}\left[ {\sum\limits_{j = 1}^n {1_F^{\left( j \right)}} {1_{Y = i}}} \right] = \mathbb{E}\left[ {\sum\limits_{j = 1}^n {1_F^{\left( j \right)}} |Y = i} \right]\mathbb{P}\left( {Y = i} \right) = \left( {i\mathbb{E}\left[ {{1_F}|D} \right] + \left( {n - i} \right)\mathbb{E}\left[ {{1_F}|{D^C}} \right]} \right)\mathbb{P}\left( {Y = i} \right) = \left( {i\mathbb{P}\left( {F|D} \right) + \left( {n - i} \right)\mathbb{P}\left( {F|{D^C}} \right)} \right)\mathbb{P}\left( {Y = i} \right) = \left( {i + \left( {n - i} \right)\frac{{\left( {1 - \delta } \right)\phi }}{{\left( {1 - \delta } \right)\phi  + \left( {1 - \phi } \right)}}} \right)\mathbb{P}\left( {Y = i} \right)$
So, 
$\sum\limits_{i = 0}^n {\frac{{\mathbb{E}\left[ {X{1_{Y = i}}} \right]}}{{\mathbb{P}\left( {Y = i} \right)}}{1_{Y = i}}}  = \sum\limits_{i = 0}^n {\left( {i + \left( {n - i} \right)\frac{{\left( {1 - \delta } \right)\phi }}{{\left( {1 - \delta } \right)\phi  + 1 - \phi }}} \right){1_{Y = i}}}  = \sum\limits_{i = 0}^n {\left( {\frac{{n\phi \left( {1 - \delta } \right) + \left( {1 - \phi } \right)i}}{{1 - \delta \phi }}} \right){1_{Y = i}}}  = \frac{{n\phi \left( {1 - \delta } \right) + \left( {1 - \phi } \right)Y}}{{1 - \delta \phi }}$
A: Denote with $F$ the event that a robot is faulty, with $P(F)=\phi$ and with $T$ the event that it was tested faulty with $$P(T|F)=\delta$$ and $$P(T|F')=0$$ Thus according to the law of Total Probability the probability that a random robot is tested faulty is equal to $$P(T)=P(T|F)P(F)+P(T|F')P(F')=\delta\cdot\phi+0=\delta\cdot\phi$$ Now, if a robot was not tested faulty then the probability that it is nevertheless faulty is equal to $$P(F|T')=\frac{P(T'|F)P(F)}{P(T')}=\frac{(1-\delta)\phi}{1-\delta\phi}$$ Assume, now that $Y$ robots were found faulty, then $$E[X|Y]=Y+(n-Y)\cdot\frac{(1-\delta)\phi}{1-\delta\phi}=\frac{n\phi(1-\delta)+(1-\phi)Y}{1-δ\phi}$$ since according to the above calculations if there where $Y$ robots tested faulty, then these $Y$ are for sure faulty, and there is a$\frac{(1-\delta)\phi}{1-\delta\phi}$ probability that each of the remaining $n-Y$ robots that were not tested faulty, is actually faulty as well. 
