# Thread: Expected value of Bernouilli Distribution

1. ## Expected value of Bernouilli Distribution

A set of binary data can have either a 1 with probability $\displaystyle p$ or a 0 with probability $\displaystyle 1-p$. A set of outcomes that have to same values is referred to as a run (i.e the set 1,1,0,1,1,1,1 where the first run with have 2 values, the second run would have 1, the third of length 4, and so on).

A) Find the expected length of the 1st run
B) Find the expected length of the 2nd run

$\displaystyle Y = \left\{ \begin{array}{rcl} 1 & \mbox{if} & \mbox{if the first number is a 1} \\ 0 & \mbox{if} & \mbox{if the first number is a 0} \end{array}\right.$

A) $\displaystyle E[N] = E[N|Y=1]P \left( Y=1 \right)+E[N|Y=0]P \left(Y=0\right)$

$\displaystyle E[N] = E[N|Y=1]p+E[N|Y=0](1-p)$

$\displaystyle E[N] = (1)p+1+E[N](1-p)$

$\displaystyle E[N] = \frac{1}{p}$

B) I would think it would be an identical to part A), but I'm unsure of that.

2. I would think this problem to be a geometric distribution. so the expected run of the first outcome would be

$\displaystyle \frac{1}{p}$ if it was a 1 and $\displaystyle \frac{1-p}{p}$ if it was a zero.

it would be similar for the second run. But I still have no clue on how to merge them together, considering that either a 1 or a 0 can occur.

3. You're almost right about the geometric distribution. In fact, because the first bit is either 0 or 1, this is rather a mix (a convex combination) of the two geometric distributions you give. To find the expected value, condition on the first bit $\displaystyle X_1$: $\displaystyle E[N]=E[N|X_1=1]P(X_1=1)+E[N|X_1=0]P(X_1=0)=\frac{1}{1-p}p+\frac{1}{p}(1-p)$.
Indeed, under the conditional distribution $\displaystyle P(\cdot|X_1=1)$, the situation is that of the usual geometric distribution of parameter $\displaystyle 1-p$: position of the first 0 among the next bits ($\displaystyle X_2,\ldots$). And conversely when $\displaystyle X_1=0$.

As for the second question, if the first run was a 1 (probability p), then the second is a 0, and conversely, so that the probabilities aren't the same. Let's condition on the values of $\displaystyle N_1$ and $\displaystyle X_1$ so that we can use the independence: $\displaystyle P(N_2=n_2, N_1=n_1, X_1=1)=p^{n_1}(1-p)^{n_2}p$ ($\displaystyle n_1$ "1", $\displaystyle n_2$ "0" and $\displaystyle 1$ "1"), so that $\displaystyle P(N_2=n_2|N_1=n_1,X_1=1)=\frac{p^{n_1}(1-p)^{n_2}p}{p^{n_1}(1-p)}=(1-p)^{n_2-1}p$ (geometric distribution of parameter $\displaystyle p$). The same way, $\displaystyle P(N_2=n_2|N_1=n_1,X_1=0)=p^{n_2-1}(1-p)$ (parameter $\displaystyle 1-p$). Notice that $\displaystyle N_2$ is independent of $\displaystyle N_1$ since $\displaystyle n_1$ doesn't appear in the conditional distribution. Finally, $\displaystyle E[N_2]=E[N_2|X_1=1]P(X_1=1)+E[N_2|X_1=0]P(X_1=0)=\frac{1}{p}p+\frac{1}{1-p}(1-p)=2$.

4. for the first part why wouldn't it be :

$\displaystyle \frac{1}{p}(p) + \frac{1-p}{p}(1-p) = \frac{1-p+p^2}{p}$?

5. Originally Posted by lllll
for the first part why wouldn't it be :

$\displaystyle \frac{1}{p}(p) + \frac{1-p}{p}(1-p) = \frac{1-p+p^2}{p}$?
Because of what I wrote: if the first is 1 (prob $\displaystyle p$), you wait for the first 0 (so geom. with parameter $\displaystyle 1-p$), and conversely. And the expected value of a geometric random variable of parameter $\displaystyle 1-p$ is $\displaystyle \frac{1}{1-p}$. And indeed, there was a mistake in your previous post, I didn't notice.