2

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.

  • 1
    Are you talking about a mechanical computation? If so, I'd do it by backwards induction. Let $q(k,i)$ be the probability that you don't throw three consecutive heads in the next $N-k$ tosses, given that you are running a string of $i$ heads (and $N$ is your large number) Then it is easy to compute this if $k$ is near $N$ and there is a simple recursion. Not exactly a pencil and paper computation, I understand. – lulu Nov 01 '16 at 19:56
  • Your question requires you to be more specific about what you count as an event of "3 or more consecutive heads." For example, if you see a sequence $T, H, H, H, H, H, H, T$, do you count this as a single occurrence of three or more heads, or do you count it as four occurrences? – heropup Nov 01 '16 at 20:08
  • @heropup, it counts as a single occurence. Thanks for the question. I've updated my question. – Greg Clinton Nov 01 '16 at 20:41
  • @lulu, I am using python to do the computation. I will attempt your backwards induction technique and let you know how it goes. Thank you. – Greg Clinton Nov 01 '16 at 20:45
  • @Did, thank you very much for this answer. The math is a little beyond my reach but the results closely match my simulated results and those of David K. I tried with variations of the parameters as I might see in the problem at large. I agree with David that your comment would do well as an answer. Please excuse my awkwardness here, I'm new at this. – Greg Clinton Nov 01 '16 at 23:54
  • @lulu, Here's my attempt at your suggestion. I must be doing something wrong. My q function returns higher numbers than I expect. Also, it can only handle very small N values before getting bogged down. See anything wrong? 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
  • Well, you need to tell the machine that $q(k,i)=0$ if $i≥3$. But the approximate methods are much, much better than this. did you understand where those came from? – lulu Nov 02 '16 at 16:36
  • @lulu, I will be using one of the approximate methods. But still it's nice to view the calculation from another perspective, as with the inductive approach, even if just to watch it work on small N. I will look into i >= 3 as you suggest. Thank you for your help. – Greg Clinton Nov 02 '16 at 17:35

2 Answers2

2

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.)

David K
  • 98,388
  • 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
  • 1
    I 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
2

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.)

Did
  • 279,727