## Longest streaks of successes

Let's say you have 5 successes in 7 trials. There are a total of 21 different ways to arrange them. How many times will the longest streak of successes be 5, 4, 3, and 2? I figured this out by brute force, but wondered if there was a formula to calculate it, one that could be used for any x successes in y trials. The answers for the example are:

5 in a row: 3
4 in a row: 6
3 in a row: 9
2 in a row: 3

Thanks for any help.

Ken
 PhysOrg.com science news on PhysOrg.com >> City-life changes blackbird personalities, study shows>> Origins of 'The Hoff' crab revealed (w/ Video)>> Older males make better fathers: Mature male beetles work harder, care less about female infidelity
 It's fairly complicated. See http://mathworld.wolfram.com/Run.html
 Thank you for the link! I am trying to understand the formulas and adapt them for my purposes.

## Longest streaks of successes

For small numbers (say less than 10), it is probably easiest to do it recursively. Even by hand. For somewhat larger numbers, you would need a computer. Take a look at this thread:

 That is a handy website. If you are still interested in doing the problem as you originally stated it (where the number of successes and the number of trials are given), it is doable. If you are comfortable with counting techniques and binomial coefficients, I believe it is even possible to obtain a formula (kinda nasty looking...but still manageable) in terms of those two given quantities. For fairly large values like 162, it may be easier to have a computer evaluate the formula than to have it solve the problem recursively. If you want to pursue this, I'll try to help. EDIT: I'll go ahead and post the formula I have in mind, and you can decide if it's something you want to look into. Here n is the number of trials, s the number of successes, and R the longest run or streak of successes. Then the number of ways of getting a run of at least r is $$N(R \geq r) = \sum_{b=1}^{B} \binom{n-s+1}{b}\sum_{j=1}^{J}(-1)^{j+1}\binom{b}{j}\binom{s-j(r-1)-1}{b-1}$$ here J = min{b, integer part of s/r} and B = min{s, n-s-1} To find the number of ways N(R=r) where the longest streak is exactly r, you can subtract N(R >= r+1) from N(R >= r).
 I ran 1000 seasons of a baseball team going exactly 100-62, recording the longest winning streak in each. This would be a with replacement experiment. In the table below, the first column lists the maximum streak lengths. The second column lists the actual probabilities of at least that long of a streak for without replacement (probability of winning each game exactly 100/162), which I got from the site linked in post 5. The third column lists the percentages from the 1000 trials. As you would expect, without replacement has a better chance for longer streaks, but for the shorter ones, the results are almost identical. Overall, these numbers are a lot closer than I thought they would be. Code:  Random Specific Streak Pct Pct 4 100.0 100.0 5 99.9 99.9 6 98.0 98.0 7 89.9 89.3 8 74.3 73.1 9 55.7 52.5 10 38.8 37.2 11 25.8 24.8 12 16.6 14.4 13 10.5 8.7 14 6.5 5.8 15 4.1 4.0 16 2.5 2.0 17 1.5 1.0 18 0.9 0.6 19 0.6 0.5
 Interesting. For long streaks, which are infrequent, it looks like you can treat it as a Poisson process. If p is the probability of success and q = 1-p, then the expected number of streaks of length at least r in a sequence of n trials is given by $$\lambda = p^r + (n-r)qp^r \approx (n-r)qp^r$$ Then the probability of at least one streak of length r or more is given by $$P(R \geq r) \approx 1-e^{-\lambda}$$ Using p = 100/162, I tried it for r=10 and r = 15 and got answers that agree well with what you got by simulation.
 here are the values I get with the Poisson approximation (which asssumes independent trials with probability of success p = 100/162 each time): Code: Streak length 5 .996 6 .965 7 .873 8 .717 9 .539 10 .378 11 .253 12 .164 13 .104 14 .065 15 .040 16 .025 17 .015 18 .009 19 .006