# Computing and simulating a conditional expectation

I was working the following problem :
You go on a camping trip with two friends who each have a mobile phone. Since you are out in the wilderness, mobile phone reception isn’t very good. One friend’s phone will independently drop calls with 10% probability. Your other friend’s phone will independently drop calls with 25% probability. Say you need to make 6 phone calls, so you randomly choose one of the two phones and you will use that same phone to make all your calls (but you don’t know which has a 10% versus 25% chance of dropping calls). Of the first 3 (out of 6) calls you make, one of them is dropped. What is the conditional expected number of dropped calls in the 6 total calls you make (conditioned on having already had one of the first three calls dropped)?
Let D be the event that the phone dropped. By the law of total probability : $$P(D) = 0.5*0.1+0.5*0.25=0.175$$
For i in 1..6 let $$X_i$$ the random variable that equals to 1 if the ith phone call dropped and 0 otherwise. The expectation S that we are asked to compute is :
$$S = E[\sum_{i=1}^6 X_i |\sum_{i=1}^3 X_i = 1]$$ By linearity and independence $$S = 1 + 3 * P(D) = 1.525$$ To verify if the computation is correct I simulate a lot of iterations using python. First, I used this function to generate the result of the six phone calls :

from scipy.stats import bernoulli
def drop_uni():
return bernoulli.rvs(0.175,size=6)
simu = 100000
condi = []
general = []
for i in range(simu):
echan = drop_uni()
if sum(echan[0:3])==1:
condi.append(sum(echan))
print(sum(condi)/len(condi))


This method gave me an expectation of 1.522 which is good.
However I used another method to simulate the 6 phone calls

def drop():
friend = bernoulli.rvs(0.5)
if friend == 1:
return bernoulli.rvs(0.1,size=6)
else:
return bernoulli.rvs(0.25,size=6)
simu = 100000
condi = []
general = []
for i in range(simu):
echan = drop()
if sum(echan[0:3])==1:
condi.append(sum(echan))
print(sum(condi)/len(condi))


This method gave me an expectation of 1.587 which is weird. Can you please help figure out why the two methods don't give the same result ? Thanks for your help

The second simulation is correct. The first one and the calculation that matches it are wrong. Where you write “By linearity and independence”, it’s not clear to me why you think that this follows by linearity and independence (it doesn’t).

It’s perhaps easier to see that the two simulations simulate two quite different experiments if you change the numbers: Imagine that the phone of one of your friends is broken and always drops calls and your other friend’s phone never drops calls. Now if you choose a phone once and for all and make $$6$$ calls with it, it’s impossible that exactly one call is dropped; whereas if you choose the phone anew for every call, like you do in the first simulation and the associated calculation, it’s entirely possible that exactly one call is dropped (namely with probability $$\binom61\left(\frac12\right)^6=\frac3{32}$$).

The correct calculation that matches the result of the second simulation is

$$\begin{eqnarray} P\left(p=\frac1{10}\mid S_3=1\right) &=& \frac{P\left(p=\frac1{10}\cap S_3=1\right)}{P\left(S_3=1\right)} \\ &=& \frac{\frac12\binom31\frac1{10}\left(\frac9{10}\right)^2}{\frac12\binom31\frac1{10}\left(\frac9{10}\right)^2+\frac12\binom31\frac14\left(\frac34\right)^2} \\ &=& \frac{72}{197} \end{eqnarray}$$

and thus

$$\begin{eqnarray} P\left(p=\frac14\mid S_3=1\right) &=& 1-P\left(p=\frac1{10}\mid S_3=1\right) \\ &=& \frac{125}{197}\;, \end{eqnarray}$$

so

$$\begin{eqnarray} E\left[S_6\mid S_3=1\right] &=& \sum_i E\left[S_6\mid p=p_i\cap S_3=1\right]P\left(p=p_i\mid S_3=1\right) \\ &=& \sum_i\left(1+3p_i\right)P\left(p=p_i\mid S_3=1\right) \\ &=& \left(1+\frac3{10}\right)\cdot\frac{72}{197}+\left(1+\frac34\right)\cdot\frac{125}{197} \\ &=& \frac{6247}{3940} \\ &\approx& 1.5855\;. \end{eqnarray}$$