# Thread: Expected value of Bernouilli Distribution

1. ## Expected value of Bernouilli Distribution

A set of binary data can have either a 1 with probability $p$ or a 0 with probability $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

$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) $E[N] = E[N|Y=1]P \left( Y=1 \right)+E[N|Y=0]P \left(Y=0\right)$

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

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

$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

$\frac{1}{p}$ if it was a 1 and $\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 $X_1$: $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 $P(\cdot|X_1=1)$, the situation is that of the usual geometric distribution of parameter $1-p$: position of the first 0 among the next bits ( $X_2,\ldots$). And conversely when $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 $N_1$ and $X_1$ so that we can use the independence: $P(N_2=n_2, N_1=n_1, X_1=1)=p^{n_1}(1-p)^{n_2}p$ ( $n_1$ "1", $n_2$ "0" and $1$ "1"), so that $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 $p$). The same way, $P(N_2=n_2|N_1=n_1,X_1=0)=p^{n_2-1}(1-p)$ (parameter $1-p$). Notice that $N_2$ is independent of $N_1$ since $n_1$ doesn't appear in the conditional distribution. Finally, $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 :

$\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 :

$\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 $p$), you wait for the first 0 (so geom. with parameter $1-p$), and conversely. And the expected value of a geometric random variable of parameter $1-p$ is $\frac{1}{1-p}$. And indeed, there was a mistake in your previous post, I didn't notice.