MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Sequence of Bernoulli RVs

  • To: mathgroup at
  • Subject: [mg72974] Sequence of Bernoulli RVs
  • From: Virgil Stokes <vs at>
  • Date: Sat, 27 Jan 2007 05:45:39 -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.

l1 = Tuples[{(1-p),p},n]; (* generate Bernoulli sequence 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)(p-1)p

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

--V. Stokes

  • Prev by Date: NDSolve -- initial conditions
  • Next by Date: Re: Different results for same integration
  • Previous by thread: NDSolve -- initial conditions
  • Next by thread: Re: Sequence of Bernoulli RVs