Correction to "Sequence of Bernoulli RVs"

• To: mathgroup at smc.vnet.net
• Subject: [mg73004] Correction to "Sequence of Bernoulli RVs"
• From: Virgil Stokes <vs at it.uu.se>
• Date: Sun, 28 Jan 2007 01:23:57 -0500 (EST)

```The following code will get the expected number of "runs" (sequence of
equal values) for a sequence of Bernoulli RVs in terms of p, which is
the probability of the value 1, and of course, (1-p), the probability of 0.

n=3
l1 = Tuples[{(1-p),p},n]; (* generate all possible sequences of length n *)
xx = Table[Split[l1[[k]]],{k,1,Length[l1]}]; (* list of runs *)
l2 = Map[Length,Map[Split,xx]]; (* lengths of each run *)
tt = Table[Times@@l1[[k]],{k,1,Length[l2]}];  (* probabilities for each run *)
expectedruns = Inner[Times,tt,l2]//FullSimplify  (* mean of a function of a Discrete RV *)

It may not be very obvious that this is correct. Please try it over a
range of values of n  (n=1,2,...) if you are in doubt. The expected
value for such a sequence is given by

E[number of runs] = 1 + 2(n-1)(1-p)p

Finally, my question --- Is it possible to derive this equation (in
terms of p and n) using Mathematica?

--V. Stokes
PS. The error was in the equation above: (p-1) has been replaced by (1-p) and the
is equation is correct!

```

• Prev by Date: Re: Changing Defaults
• Next by Date: Re: [TS 2379]--Re:eps exports with dashes in them (important - to me, anyway)
• Previous by thread: Re: Problem with base 2 logs and Floor
• Next by thread: Re: [TS 2379]--Re:eps exports with dashes in them (important - to me, anyway)