# Why are these following variance and expected value computations legitimate?

I spent over an hour of my exam's given time to calculate the variances and expected values as given here: Let $p,q\in (0,1)$. The number of costumers entering a supermarket is a r.v. $X$ with geometric distribution with parameter $q$. Every costumer buys a product with probability $p$ or buys nothing, with $1-p$. Let $Y$ be the number of products purchased (or bought? Is there a difference?). What is $E[Y]$? $V[Y]$?

The problematic part is that after a long computation, I arrived at $p\over q$. The formal answers simply argued: $E(Y)=E(Y|X)=\color{green}{E(pX)}=pE(X)={p\over q}$, where the green part is an argument never have I ever encountered. I couldn't compute the second one for it became too intricate(That is a really long multiple choice test.), but the formal answers used that again: $V(Y)=E(V(Y|X))+V(E(Y|X))=\color{green}{E(p(1-p)X)+V(pX)}$, and I wonder, why is $E(X|Y)=E(E(X)Y)$? I would appreciate your help.

Okay I am under the impression that suggesting free points is unorthodox or illegitimate here. I will wait as long as it enables me, for an answer to be given, and share my points with the answer I happen to see as best in my view.

• This is a question on an exam that you're taking as we speak?
– JimB
Jul 18, 2015 at 18:27
• You are missing an expectation when you write $E(Y)=E(Y|X)$. What is true is the Law of Iterated Expectation which asserts that $$E[Y] = E\left[E[Y\mid X]\right].$$ (Would I LIE to you?) If you know that $6$ customers entered the store, then (assuming independence of purchase decisions), $Y$ has conditional distribution that is Binomial$(6,p)$ and hence mean $6p$. Thus, $E[Y\mid X=6] = 6p$ and more generally, $E[Y\mid X = n] = np$ which suggests that the random variable $E[Y\mid X]$ (which is a function $g(X)$ of $X$, not $Y$, is $pX$. Also, $E[g(X)]=E[pX]=pE[X]$ has value $E[Y]$. Jul 18, 2015 at 18:30
• As an English side note: "I have spent an hour doing this" implies that you are doing that right now. "I spent an hour doing this" would be the way to convey that you spent an hour in the past, when you were taking the exam. Jul 18, 2015 at 22:13
• You are pretty much correct. I am not native and was never taught these patterns strictly and consistently, so I cling to books and TV shows hoping I won't(don't?) make this kind of mistakes. They still pop up every now and then, though. Thank you for pointing out. :) Jul 18, 2015 at 22:17
• Suggestion: when in doubt, check for yourself everything everybody says, whether they are your "highly-competent teacher" or some stranger met on the net. In the end, it is mathematics that (should) rule(s) mathematics, not some social status.
– Did
Jul 22, 2015 at 17:24

This is a computation based on conditional expectations.

Knowing that $n = X$ customers entered the supermarket, the total number $Y$ of products purchased follows a binomial distribution with parameter $p$ and $n$, the expected value of which is $pn = pX$. Therefore, the conditional expectation of $Y$ with respect to $X$ is $E[Y \mid X] = pX$.

Therefore, $E[Y] = E[E[Y \mid X]] = E[pX] = pE[X] = \frac{p}{q}$.

Similarly, the variance of $Y$ is given by $$\mathrm{Var}(Y) = E[\mathrm{Var}(Y\mid X)] + \mathrm{Var}(E[Y\mid X]) = E[p(1-p)X] + \mathrm{Var}(pX) = \dots$$ since $E[Y \mid X] = pX$ has already been computed, and the conditional variance $\mathrm{Var}(Y \mid X)$ is simply the variance of a binomial random variable with parameters $n=X$ and $p$.

Remark. The formula above for $\mathrm{Var}(Y)$ is easily proven:

\begin{align} \mathrm{Var}(Y) & = E[Y^2] - E[Y]^2 \\ &= E[E[Y^2 \mid X]] - E[E[Y\mid X]]^2\\ & = \color{blue}{E\left[E[Y^2\mid X] - E[Y\mid X]^2\right]} + \color{red}{E[E[Y\mid X]^2] - E[E[Y\mid X]]^2}\\ & = \color{blue}{E[\mathrm{Var}(X\mid Y)]} + \color{red}{\mathrm{Var}(E[X\mid Y])} \end{align}

• You also need the variance. Jul 22, 2015 at 17:53
• Thank you. I did mention variance but the concept of what I didn't understood is the conditioned expectation (and variance.) Jul 22, 2015 at 19:03
• @emcor: now it's done. Jul 22, 2015 at 20:43

There are $X$ customers and each buys with probability $p$. So the total number of buys is $X\cdot p$.

The Geometric Distribution has expected value $E(X)=\frac{1}{q}$ and $p$ is constant (hence independent).

So the expected number of buys is $$E(Xp)=E(X)\cdot p=\frac{p}{q}.$$

Since $p$ is fixed, the variance is $$V(Xp)=p^2V(X)=p^2\frac{1-q}{q^2}.$$

A detailed computation of the variance of the geometric distribution can be found here, and of its expected value here.

• Thank you for your answer. It helped me a lot. But what mostly confused me was dealing with $E[E[Y|X]]$. It wasn't addressed here, however. Since you were elaborative about the geometric distribution and the variance, I will regularly accept your answer. Jul 22, 2015 at 19:07
• Thank you for the link, by the way. I always cherish enriching my knowledge and studying about the extra. Jul 22, 2015 at 19:08