# Expected value of fraction of heads in n independent tosses with non-zero probability of filtering the outcome

Imagine an experiment of tossing $n$ identical coins. The probability of observing a head is $p$ and of observing a tail is $1-p$ for any coin.

We are interested in calculating the expected value of the fraction of tosses that show heads.

This is easy because the expected number of heads is $np$ and the total number of tosses is a constant i.e. $n$. So, the expected value of the fraction of tosses with heads is $\frac{np}{n} = p$.

Now, there is a twist. The twist is that if a toss shows tail, then it is always considered part of the experiment but if it shows head, then it is considered part of the experiment with probability $q$. In other words, the denominator in the fraction is not a constant $n$ anymore. I know that we can easily calculate the expected value of numerator and denominator separately but that won't give the expected value of the ratio of the two. How can we solve it ?

Please note the difference from a simpler question in which only the count of heads decreases by a factor of $q$ but not the total number of tosses that are considered in the experiment.

• Have you tried the simple cases $n = 1, 2, 3, \dots$? What have you tried? – user357980 Mar 3 '18 at 3:16
• @user357980 I have tried to write the probabilities and expected values of the fraction for each of the values that the denominator can take. For e.g. the probability that exactly 1 toss is counted in the experiments can be calculated as probability of every toss except one showing head and being discarded with probability $1-q$ and exactly one toss showing tail + probability of every toss showing head and exactly one being considered with probability $q$, rest being discarded with probability $1-q$. But this becomes intractable soon. – NGInd Mar 3 '18 at 11:43

Let $X$ be the count of heads, and $Y$ the count of heads "in the experiment", among $n$ trials.

You seek $\tfrac 1n\mathsf E(Y)$.

We know $X$ follows a binomuial distribution.   Well, likewise the count of heads "in the experiment", under the condition that $X$ heads show, will be Binomially distributed too. $$\begin{split}X&\sim\mathcal{Bin}(n,p)\\Y\mid X&\sim\mathcal {Bin}(X, q)\end{split}$$

The relation expectation of a Binomial distributed random variable is well known.   You have stated it.   $\mathsf E(X)=np$.   So similarly $\mathsf E(Y\mid X)=Xq$.

Then it is just a matter of applying the Law of Total Probability: $\mathsf E(Y)=\mathsf E(\mathsf E(Y\mid X))$.

That is all.

Alternatively: You are conducting $n$ independent trials where a success occurs with probability $pq$, since a success is: a head shows and is considered "in the experiment".   Then the count of heads "in the experiment" among the $n$ trials is binomially distributed: $Y\sim\mathcal{Bin}(n, pq)$.   What is its expectation?

Edit: It seems what you seek is $\mathsf E(\tfrac Y M)$ where $M$ is the count of tosses "in the experiment." $M=n-X+Y$

Well, we know that the counts of tails, heads-in, and heads-out will be multinomially distributed, $(n-X,Y,X-Y)\sim\mathcal{Multinom}(n; 1-p,pq,p-pq))$

A little thought tells us that $Y\mid M\sim\mathcal{Binom}(M, \rho)$ for some $\rho$ .

And so $\mathsf E(Y\mid M)= M\rho$ and $\mathsf E(\tfrac Y M)=\mathsf E(\tfrac {\mathsf E(Y\mid M)} M)= \rho$

Identify $\rho$ and you are done.

$Y$ is the count of heads among the $M$ coin-tosses that we don't ignore. $\rho$ is the condtional probability that a particular coin toss is a head, when given that it is not ignored.

• thank you for the answer. As I said in the question, we can not use constant $n$ in the denominator. Because the question asks to completely discard a toss from the experiment with probability $q$ if it shows head, so that it is not even counted in the total number of tosses. In a way, there is randomness in the total number of tosses and we have to find the expected value of the ratio of two random variables (number of tosses with heads and number of tosses). – NGInd Mar 3 '18 at 11:04
• Ah, then is what you want $\mathsf E(Y/(n-X+Y))$? – Graham Kemp Mar 3 '18 at 11:53
• thanks for the edited answer. So, $\rho$ is $\frac{pq}{pq+(1-p)}$ if understand the answer correctly ? I understand the intuition behind the answer and it is very elegant. However, I do not understand that why we didn't have to deal with the case $M = 0$ in your method ? – NGInd Mar 3 '18 at 20:48
• $\mathsf E\big(g(Y)\,h(Z)\big)=\mathsf E\Big(\mathsf E\big(g(Y)\mid Z\big)\, h(Z)\Big)$ is a general rule. As to the edge case, $M=0$, well $\lim_{m\to 0^+}\tfrac{m\rho}{m}=\rho$. – Graham Kemp Mar 3 '18 at 22:43
• (Well, providing $\mathsf E(g(Y)h(Z))$ is finite, anyway.) – Graham Kemp Mar 4 '18 at 1:52