Open Side Menu Go to the Top
Register
successes in a row successes in a row

10-24-2010 , 10:42 AM
Hi i have this one question that is killing me. From my understanding it relates to Binomial distribution.

Pre-question:
Suppose person A is tossing a coin with 50% prob.

What is the probability to get 10 Heads in a row out of 1000 tosses? What is the name of such calculation and formulae?

Question:
Suppose now another Person B is tossing another coin (also P=50%), such that Person A is tossing and then person B is tossing and so on , one at a time.

What is the probability to get 10 Heads in a row (where 5 tossed by A and 5 tossed by B) from 1000 tosses (500 by each one). What is the formulae?
Any further reading will be nice.

Thanks.
successes in a row Quote
10-24-2010 , 10:47 AM
10 in a row has probability 0.5^10.

the number of attempts it takes to get 10 in a row has a geometirc distribution with p=0.5^10

2nd part it doesn't matter who tosses the coin if the probability is still 0.5.

Hope this points you in the right direction
successes in a row Quote
10-24-2010 , 11:57 AM
This problem is a lot harder than it first appears. I suggest you google 'run probability' or something similar like 'k successes in a row" to see exact and approximate solutions.
successes in a row Quote
10-24-2010 , 12:04 PM
Thanks a lot. Can u point to a formulae or calculator that will do the hard work and get me the actual values?

As for second part- I should also note that Person B is tossing a different coin. Or to be mroe precise- instead of 2 coins think of 2 totally different events, each with 50% probablity. Each event has its own set of rules and therefore different win/loss sequences.
Does that change the picture?
successes in a row Quote
10-24-2010 , 12:07 PM
Quote:
Originally Posted by statmanhal
This problem is a lot harder than it first appears. I suggest you google 'run probability' or something similar like 'k successes in a row" to see exact and approximate solutions.
Thanks Statmanhal, yes i agree with you
successes in a row Quote
10-24-2010 , 12:23 PM
Quote:
Originally Posted by peach34
Thanks a lot. Can u point to a formulae or calculator that will do the hard work and get me the actual values?

As for second part- I should also note that Person B is tossing a different coin. Or to be mroe precise- instead of 2 coins think of 2 totally different events, each with 50% probablity. Each event has its own set of rules and therefore different win/loss sequences.
Does that change the picture?
No it doesn't change the picture, the probability of each toss is 0.5 so it doesn't matter who flips it, where they fip it, how they flip etc etc etc
successes in a row Quote
10-24-2010 , 01:28 PM
Quote:
Originally Posted by peach34
Hi i have this one question that is killing me. From my understanding it relates to Binomial distribution.

Pre-question:
Suppose person A is tossing a coin with 50% prob.

What is the probability to get 10 Heads in a row out of 1000 tosses? What is the name of such calculation and formulae?
The binomial distribution is not involved except as an approximation since we don't have a fixed number of independent trials.

I wrote a perl script to solve problems like this exactly in this post, and you can find a link to the explanation of how it works there. For this problem I used the perl script with these variables:

$p = 1/2
$m = 10
$n = 1000

The result was

Code:
Probability of 10 events of probability 0.5 in a row in 1000 trials = 0.385449752412481 or 1.59437188308236 to 1.

Quote:
Question:
Suppose now another Person B is tossing another coin (also P=50%), such that Person A is tossing and then person B is tossing and so on , one at a time.

What is the probability to get 10 Heads in a row (where 5 tossed by A and 5 tossed by B) from 1000 tosses (500 by each one).
Same as above.


Quote:
What is the formulae?
The exact formula in this case is

1 - F10[1002]/21000

where F10[1002] is the 1002nd Fibonacci 10-step number. The regular Fibonacci numbers are obtained by summing the previous 2 numbers (1,1,2,3,5,8,...). The Fibonacci 10-step numbers are obtained by summing the previous 10. Whether you use this formula, or the one from the perl script above, the answer is exact, and you will need a program or spreadsheet either way, unless you just happen to know the first 1002 Fibonacci 10-step numbers.

For a good approximation, just use

1 - (1023/1024)(992/2)

=~ 38.4%

where 992/2 is the approximate number of trials since the average trial is 2 flips long, and the last one starts on flip 991. The probability of failure on each trial is 1 - 1/210 = 1023/1024.

Last edited by BruceZ; 10-24-2010 at 02:51 PM.
successes in a row Quote
10-24-2010 , 05:54 PM
Here's an online streak calculator:

http://www.uksportsdata.com/scalp/streaks.php

It gives 38.530% as the exact answer to 3 places (to get 10 in a row in 1000 tosses).

In answer to the OP, if it wasn't clear from Bruce's post, there is no simple formula to solve this problem. It requires a script to accumulate the total iteratively, or a large lookup table for the factors.

Last edited by spadebidder; 10-24-2010 at 06:23 PM.
successes in a row Quote
10-24-2010 , 07:32 PM
Quote:
Originally Posted by spadebidder
Here's an online streak calculator:

http://www.uksportsdata.com/scalp/streaks.php

It gives 38.530% as the exact answer to 3 places (to get 10 in a row in 1000 tosses).
I gave the answer to 13 places, and it disagrees with your script in the 2nd place (38.545%). The answer from my script agrees with the answer from the exact Fibonacci formula that I posted up to the 13th decimal place, though the script uses a different exact method from the Fibonacci formula.

Your script has a serious problem. Check the results for series length 10, streak length 2, probability 50%. It gives an answer of 79.474%. The exact answer is

1 - F[12]/210

=~ 85.9375%

which also agrees with my script. F[12] = 144, the 12th Fibonacci number (1,1,2,3,5,8,13,21,34,55,89,144).

In fact, it gives the correct numbers for a series length of 2 (25%) and for a series length of 3 (37.5%), but for a series length of 4 it gives 46.875%. Obviously the answer for 4 is 50% by adding the 3 mutually exclusive probabilities of getting 2 consecutive heads for the first time on the 2nd, 3rd or 4th flip:

P(1st 2 flips heads) +
P(1st flip tails AND 2nd and 3rd flips heads) +
P(2nd flip tails AND 3rd and 4th flip heads)

1/4 + (1/2 * 1/4) + (1/2 * 1/4) = 1/2.

I was looking for other posts where you quoted it, and I found one where you said that it was possible to inspect the inline javascript code, but it is not inline. It appears to be in a separate file that I can't access.
successes in a row Quote
10-24-2010 , 07:38 PM
Quote:
Originally Posted by BruceZ
I gave the answer to 13 places, and it disagrees with your script in the 2nd place (38.545%). The answer from my script agrees with the answer from the exact Fibonacci formula that I posted up to the 13th decimal place, though the script uses a different exact method from the Fibonacci formula.

Your script has a serious problem. Check the results for series length 10, streak length 2, probability 50%. It gives an answer of 79.474%. The exact answer is

1 - F[12]/210

=~ 85.9375%
Wow, time to find another calculator. The code on that one is used on a whole bunch of gambling sites all over the web.

Here's a snippet from their script, the part that actually calculates the answer:

Code:
// user inputs an integer for lSeries (number of trials),
// lStreak (length of streak), dProb (chance of each event)

function calcStreakProb(lSeries, lStreak, dProb) {
        
// deleted input validation and format code

	if (lStreak > lSeries) {
		return 0;
	}
	var dTotProb = new Array(lSeries);
	dTotProb[lStreak] = Math.pow(dProb, lStreak);
	for (var i = lStreak+1; i<= lSeries; i++) {
		dTotProb[i] = dTotProb[i-1] + Math.pow(dProb, lStreak) * (1-dProb) * (dTotProb[i-lStreak] != undefined ? 1-dTotProb[i-lStreak] : 1);
	}
	return fmtPercent(dTotProb[lSeries]);

}
The whole script file is here, just save it:
http://www.uksportsdata.com/scalp/js/streak.js

Edit: I also just found some discussion on the web that also points out this tool is wrong for certain size streaks and right for others. I've been using it for a while, but no more.

Here's one that appears to give the right answers, but rounded:
http://www.beatingbonuses.com/calc_streak.htm

Their script is inline and can be seen in the page source.

Last edited by spadebidder; 10-24-2010 at 07:49 PM.
successes in a row Quote
10-24-2010 , 10:19 PM
Quote:
Here's one that appears to give the right answers, but rounded:
http://www.beatingbonuses.com/calc_streak.htm
I already made it fail pretty badly. Put in:

hands = 100
streak = 5
p = 0.5

It gives 82.7%. The correct answer should be 81.0%. Again I got the same answer to 13 decimal places with both my script and the Fibonacci formula. The UKsportsdata script gives 80.453%, so your 2 scripts are both off in opposite directions.

For the OPs question, Beatingbonuses only gives 3 digits, and it is actually worse than UKsportsdata:

Correct: 38.545%
UKsportsdata.com: 38.530%
Beatingbonuses.com: 38.6%

Last edited by BruceZ; 10-25-2010 at 01:09 AM.
successes in a row Quote
10-25-2010 , 06:51 AM
I fixed the UKsportsdata.com script. With the fixed files now residing on my PC, it gives the correct answers to all of the cases for which I reported errors in this thread. You can make it work on your PC by simply changing this 1 line in streak.js from this:

Quote:
dTotProb[i] = dTotProb[i-1] + Math.pow(dProb, lStreak) * (1-dProb) * (dTotProb[i-lStreak] != undefined ? 1-dTotProb[i-lStreak] : 1);
to this:

Quote:
dTotProb[i] = dTotProb[i-1] + Math.pow(dProb, lStreak) * (1-dProb) * (dTotProb[i-lStreak-1] != undefined ? 1-dTotProb[i-lStreak-1] : 1);
That is, you just need to subtract 1 from 2 indices. This is the term that multiplies by the probability that no streak ended (streak length + 1) before the index being currently considered. See the explanation of my perl script referenced in this thread for more details. This is the same method that I use, except that I implemented a circular buffer to save memory. So for me, this index is the oldest data value, at the same index as the one that I am currently updating.

Simply place the fixed file, and also the file http://www.uksportsdata.com/scalp/js/common.js in a directory named "js", and place http://www.uksportsdata.com/scalp/streaks.php one level above this. I had to change the .php extension to .html for my browser to recognize it on my machine.

I haven't debugged the Beatingbonuses.com script yet. It appears to be using the inclusion-exclusion principle.

Last edited by BruceZ; 10-25-2010 at 02:48 PM.
successes in a row Quote
10-25-2010 , 07:20 AM
Thanks Bruce and all that’s great stuff.

So if the probability of having 10 heads in a raw out of 1000 tosses is 38. 545%...

Does it mean that if we are tossing infinite number of times, we will have (on average) one streak of 10 heads in a raw every approx 2594 tosses?
successes in a row Quote
10-25-2010 , 09:15 AM
Quote:
Originally Posted by peach34
So if the probability of having 10 heads in a raw out of 1000 tosses is 38. 545%...

Does it mean that if we are tossing infinite number of times, we will have (on average) one streak of 10 heads in a raw every approx 2594 tosses?
No, every 2048 tosses on average we will have a sequence of at least 10 heads in a row. This counts sequences longer than 10 heads as a single sequence. A sequence of at least 10 heads will occur on average 1 time in every 210 = 1024 TRIALS, but the average trial is 2 tosses long, so it happens on average every 2048 tosses.

Why is the average trial 2 tosses long? Because it is always at least 1 toss long, half of the time it is at least 2 tosses long, 1/4 of the time it is at least 3 tosses long, etc., so the average length is

1 + 1/2 + 1/4 + 1/8 + ... = 2 tosses.

Now suppose we want to count sequences of 20 heads as 2 sequences of 10, 30 heads as 3 sequences, etc. This seems more reasonable, but it won't make much difference because these long sequences are so rare. Now a trial will terminate after 10 heads in a row, and a new trial will begin, so no sequence can be longer than 10 tosses, whereas before a trial could be any length. The probability of 10 heads in a row is still 1 in 1024 trials; however, now the average length of a trial will terminate after 9 terms instead of an infinite number of terms:

1 + 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/64 + 1/128 + 1/256 + 1/512

= 1023/512

The last term says that 1/512 of the time, there will be at least 9 heads in a row, so there will be 10 tosses. After that, the trial ends, so the 10th toss doesn't affect the length. So on average we will have a sequence of 10 heads in a row every 1024 trials times an average 1023/512 tosses per trial = 2046 tosses. Not much difference from the other case of 2048 tosses.
successes in a row Quote
10-25-2010 , 11:13 AM
Quote:
Originally Posted by BruceZ
The last term says that 1/512 of the time, there will be at least 9 heads in a row, so there will be 10 tosses.
1/512 of what time?

-are you familiar with a calculator that will take into account the longer sequences of 11, 12, 13 and up..?


Now- if I try to be practical:
suppose a betting event with 50% probability to lose and it pays even money when wins.
If doing "stop at a winner" of 10 rounds, doubling each time including the 10th event (so after the 10th event is lost the loss is accepted and new sequence starts at the 11th event). What will be the result? What should I take 2048 or 1024?
There is nothing new with this approach (im sure many even lost using it LOL) but what I'm trying to do is find the critical payout for each case and then look for value bets which are bigger payouts.
successes in a row Quote
10-25-2010 , 12:23 PM
Quote:
Originally Posted by peach34
1/512 of what time?
That is the fraction of trials that have at least 9 heads in a row.


Quote:
-are you familiar with a calculator that will take into account the longer sequences of 11, 12, 13 and up..?
The calculators discussed in this thread compute the probability of at least 1 streak of length m or longer in n tosses. That is a completely different question from asking the average number of tosses required to get a streak of length m or longer. The latter is a simple calculation that doesn't require a script, as I showed in my last post.


Quote:
Now- if I try to be practical:
suppose a betting event with 50% probability to lose and it pays even money when wins.
If doing "stop at a winner" of 10 rounds, doubling each time including the 10th event (so after the 10th event is lost the loss is accepted and new sequence starts at the 11th event). What will be the result?
If you are doing a martingale, doubling your bet each time you lose a toss, and starting over from 1 bet after you win, then you will lose 10 in a row every 1024 trials on average, where a "trial" is a sequence of bets ending in a win or 10 consecutive losses. When you lose 10 in a row, it will cost you 1023 bets, which will exactly cancel the 1023 bets that you won on the other 1023 trials of course since it is an even game. These 1024 trials will require an average of 2046 tosses as computed in the last post.


Quote:
What should I take 2048 or 1024?
I'm not sure what you are asking, but hopefully I answered it.
successes in a row Quote
10-25-2010 , 02:52 PM
Quote:
Originally Posted by BruceZ
I fixed the UKsportsdata.com script.
I sent a note to the site with the correction, and another site that uses that same widget. Thanks
successes in a row Quote
06-01-2011 , 10:33 AM
Hello,

I am posting here because i've found a reference from this streak calculator http://www.pulcinientertainment.com/...tor-enter.html over here.

I dont know who "fixed" this calculator but sometimes mathematics is very hard. Just put 0.99 (99%) in the probability field in the calculator with series length 1 and streak length 1 and hit both "calculate" buttons.

You wanna convince me that an event that has 99% probability of succes, suddenly has only a 98% of chance at the first trial and that the average number of trials is over 100 to have a streak of 1 or bigger????

Thanks for an answer!
successes in a row Quote
06-01-2011 , 12:25 PM
Quote:
Originally Posted by bullet101
Hello,

I am posting here because i've found a reference from this streak calculator http://www.pulcinientertainment.com/...tor-enter.html over here.

I dont know who "fixed" this calculator but sometimes mathematics is very hard. Just put 0.99 (99%) in the probability field in the calculator with series length 1 and streak length 1 and hit both "calculate" buttons.

You wanna convince me that an event that has 99% probability of succes, suddenly has only a 98% of chance at the first trial and that the average number of trials is over 100 to have a streak of 1 or bigger????

Thanks for an answer!
Thanks for the heads up.
I know the webmaster at pe.com and emailed him of the error.

The person that made that html passed away earlier this year and I think his son was just trying to update the page, and was creating rounding errors in the javascript.

BruceZ's original repaired javascript looks to be back up.

I also suggested to pe.com just to remove the page since the script is not theirs.
successes in a row Quote
06-01-2011 , 01:03 PM
Quote:
Originally Posted by bullet101
Hello,
that the average number of trials is over 100 to have a streak of 1 or bigger????

Thanks for an answer!
after reading your post again, I came up with an answer, may not be correct.

I use these 2 formulas for mean recurrence time of a streak of exactly length X:
=(1/p^k)*((1-p^k)/(1-p)) (k=streak length) or
=((p^-k)-1)/1-p
I come up with 1.01010101 for exactly a streak of length 1.

and your question, and I must agree my answer also looks to be wrong..
to have a streak of 1 or bigger: where one counts streaks of lengths 2,3,4,etc.
101.010101
(1/p^k)*(1/(1-p))
Why? because there are way more streaks larger than length 1 when p = 0.99 and the average counts the number of trials that are larger than a streak of I.
maybe someone else can explain it better than myself.

Last edited by guido1; 06-01-2011 at 01:14 PM. Reason: typo in formula
successes in a row Quote
06-01-2011 , 01:41 PM
Quote:
Originally Posted by bullet101
Hello,

I am posting here because i've found a reference from this streak calculator http://www.pulcinientertainment.com/...tor-enter.html over here.

I dont know who "fixed" this calculator but sometimes mathematics is very hard. Just put 0.99 (99%) in the probability field in the calculator with series length 1 and streak length 1 and hit both "calculate" buttons.

You wanna convince me that an event that has 99% probability of succes, suddenly has only a 98% of chance at the first trial and that the average number of trials is over 100 to have a streak of 1 or bigger????

Thanks for an answer!
This thread describes the bug that I found with the original script, and how to fix it. This fix has been incorporated by the website that you linked.

When I enter the numbers that you mention, I get the correct answer of 99% both on the website that you linked, and on my fixed version running on my own machine. So I don't understand what you reported. What do you mean both "calculate" buttons? There is only 1.
successes in a row Quote
06-01-2011 , 02:02 PM
Hello,

yes look like the page has been modified. There were earlier 2 calculate buttons along with some pseudo scientific comments about the fact that streaks are not independent events etc etc....
successes in a row Quote
06-01-2011 , 02:03 PM
Sounds like a different script altogether from the one I worked on. (BTW, I just realized that I posted a link to this thread hehe).
successes in a row Quote
06-01-2011 , 03:03 PM
Now the one with 2 buttons is back, with the 99% problem fixed, and with my fix too.
successes in a row Quote
06-01-2011 , 03:36 PM
Something is wrong with b. b is higher than a when it should be less than or equal. For example, put series length = 10, streak length = 2, probability = 0.5. If it takes 6 trials to get a streak of exactly 2, it can't take 8 to get a streak of 2 or more.

Last edited by BruceZ; 06-01-2011 at 04:06 PM.
successes in a row Quote

      
m