How would I calculate the probability of rolling 3 or more heads consecutively out of total 525600 flips of a biased coin whose probablity of heads is 0.01? I am able to approximate this through simulation, but I need a faster calculation. With simulation I get about 0.4. The sequence T,H,H,H,H,H,H,T counts as a single occurence.
2 Answers
Referring to the answers to the question "Expected number of tosses for two coins to achieve the same outcome for five consecutive flips," the expectation of the number of times you will need to flip a coin with probability $p$ of heads before you see $n$ consecutive heads for the first time is $$ E[X_{p,n}] = \frac{(1/p)^n - 1}{1 - p}. $$ For $p = 0.01$ and $n = 3$ this comes out to $1\,010\,100$. On average, I'd expect to see three consecutive head about once in every $1\,010\,100$ flips. (I say I expect this "about" once because you might consider a single head flipped after the first occurrence of three consecutive heads to be another occurrence of three consecutive heads. Since there is only a $0.01$ chance to continue the streak of heads, however, this will have only a small effect on the answer.)
Since you have only $525\,600$ flips, we might expect $525\,600/1\,010\,100 \approx 0.520$ occurrences of three consecutive heads. But if $Y$ is the number of times we get three consecutive heads, then $0.520 \approx P(Y=1) + 2P(Y=2) + 3P(Y=3)+\cdots$, whereas we actually want $P(Y=1) + P(Y=2) + P(Y=3)+\cdots$. A better estimate (though not exact) would be $$ 1 - \left(1 - \frac{1}{1\,010\,100}\right)^{525\,600} \approx 0.405683, $$ which seems to agree with your simulation. To get this, I made the simplifying assumption that each flip (even the first one!) has a $1/1\,010\,100$ chance to complete a run of three consecutive heads. (Treating the first two flips the same as the others has very little effect on the final result.)
-
Thank you, David, very much. It appears to be giving good results that agree with my simulated answers for various values of p, k, and N. Also close to @Did's 1 - (1 + p^k) ^-N solution. – Greg Clinton Nov 01 '16 at 22:21
-
1I think Did's comments may be on better theoretical ground than this answer, thought it's nice to see how closely the numeric results agree. If this were my question I might try to get Did to repost the comments as an answer so I could accept it. – David K Nov 01 '16 at 22:30
-
As you suggested, @David. By the way, I lack the reputation points to vote up an answer. – Greg Clinton Nov 02 '16 at 00:28
The usual one-step Markov decomposition yields that the generating function of the first time $T$ when three consecutive heads appear is $$E(s^T)=x^3s^3f(s)^{-1}$$ with $x=.01$ the probability of heads and $$f(s)=1-(1-x)s-x(1-x)s^2-x^2(1-x)s^3$$ In the limit $x\to0$, one sees that $f(1)\sim x^3$ and $f'(1)\sim-1$ hence the root $s^*$ of smallest modulus of $f$ is such that $s^*-1\sim x^3$ and $f(s)\approx s^*-s$ hence $$E_0(s^T)\approx x^3\sum_{n\geqslant0}s^{n+3}(1+x^3)^{-n-1}$$ which yields $$P_0(T⩾n)≈x^3\sum_{k⩾n−3}(1+x^3)^{-k-1}=(1+x^3)^{-n+3}$$ Thus, the probability to observe at least once three consecutive heads before time $t=525600$ is approximately $$1−(1+x^3)^{−t}=1−1.000001^{−525600}\approx.408799$$ (Using the true root of $f$ yields the approximate value $.405684$ instead.)

- 279,727
q = lambda N, i: 0 if i == k else 1 if N == k else (1 - p) * q(N - 1, 0) + p * q(N - 1, i + 1)
– Greg Clinton Nov 02 '16 at 14:15