Link to home
Start Free TrialLog in
Avatar of Laszlo Benedek
Laszlo BenedekFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to calculate probability of the same events happening 3 times in a row, from binomial distribution given n trials?

In a game (XCOM) you have a stated chance of hitting the target. You either hit or miss. Let's say your chance of hitting is 90% every time.

I want to know the chance of 3 misses (10% each) happening 3 times in a row anywhere given n trials (let's say 50, 100, 200 etc)

Ideally I'm looking for a simple solution, and it can be an approximation.

The only way I can think is working out permutations for each possible number of misses (probability of x number of misses calculated from binomial formula) but that would take quite a long time. I'm wondering if there's a more elegant way.

Optional
It would be also nice to know the probability of at least 1 such streak, at least 2 etc.
Avatar of ozo
ozo
Flag of United States of America image

Here's a program to generate those probabilities:
#!/bin/perl
@p=(0,0,0,.001,.0019,.00280,.003700);
for $n (3..6){
    print "$n $p[$n]\n";
}
for $n (7..200){
        print $n," ",$p[$n]=1.9*$p[$n-1]-.81*$p[$n-2]-.081*$p[$n-3]-.0090*$p[$n-4],"\n";
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Laszlo Benedek

ASKER

Thanks. Is there a site where they explain the math behind it, so that I can understand better how this is calculated. When I tried to make my similar software I found out that I don't know how calculate permutations with 3 next to each other given x number of misses.
I actually cheated a little by counting the number of permutations for small n, then using oeis.org to derive a recurrence formula.  In principle you could also derive the recurrence by thinking carefully about how to extend known solutions when you add more trials.  Or by solving a set of simultaneous linear equations relating the values for n...n+4
I have smaller problems than that. I couldn't even correctly derive the formula for small n.

I could not work out how to solve for the permutation: eg from 100 trials 6 missed, what's the chance 3 of those 6 misses are next to each other?

Optional further explanation.

I have an excel sheet of what I wanted to do. Let's say I have 100 trials.
The first column is the number of misses (everything from 0-100, as you could have no miss, 1 miss ... etc or all 100 misses). The next column is is the chance of that combination: eg the chance of having 6 misses in any order out of 100. (I'm pretty sure this is correct so far)

Next I wanted to calculate the chance that I get a correct permutation (with 3 consecutive misses) given that I already know the number of misses in total for that row, so the total chance would be the multiple of the 2 chances for the row and adding all those up is the final total.
Probability.xlsx
I could have given a smaller example than 100 for "small" n, but I think the formula would be the same.