Statistical analysis question

A thread in another forum mentioned a statistical probability situation where there are multiple guns, each with a 33% chance to hit a target. The question asked (and the subsequent equation showed) how to calculate the probability that the target would be hit, or in other words, what are the odds that at least one gun would hit?

If I understand the math, it would go like this:

Gun-1-chance-to-hit + (Gun-1-chance-to-miss x Gun-2-chance-to-hit) + (Gun-1-and-2-chance-to-miss x Gun-3-chance-to-hit)

or

33% + (66% x 33%) + (45.22% x 33%) = 69.7% chance for at least one gun to hit

I don’t think I’m writing the equation as neatly or clearly as someone else might who has a better understanding of the math, so I may have made an error here.

Anyway, I also believe I understand that that the chance for all the guns to hit would be 33% x 33% x 33% or approximately 3.6%, while the chance for the all to miss would be 66% x 66% x 66% or about 28.75% or so.

So my question: how do you calculate the probability that the target will be hit only once? That the target will be hit twice? What would those equations look like?

Note: As a completely irrelevant aside, I’m looking to produce some statistical numbers on a combat simulator (City of Heroes) where the hero faces 3 enemies (X1, X2, X3) at once and each enemy has Y% chance to hit for Z points of damage.

You’re probably after the binomial distribution.

This isn’t right. The probability that at least one gun will hit is



1 - (probability that no guns will hit)


You’ve correctly computed the latter probability as 28.75%, so the probability that at least one gun will hit is 71.25%.

I’ll have to think a bit more about the rest of your question.

Aha! My calculations give me about 44.44%



   3!        1           (3-1)    6              2
-------- 0.33  (1 - 0.33)      = ---- 0.33 (0.67) = 0.444411
1!(3-1)!                         1(2)


So if I understand the math right…

If there are three villains attacking my hero (that is, three simultaneous trials), each of whom has a 5% chance to hit (1 chance of 20), if I want to know the probability that the hero would be hit one time only, the equation would look like:



   3!        1           (3-1)    6              2
-------- 0.05  (1 - 0.05)      = ---- 0.05 (0.95) = 13.5375%
1!(3-1)!                         1(2)


That number seems high to me. Did I do something wrong?

Seems about right.
[ul]
[li]Probability of getting one hit = 0.135375[/li][li]Probability of getting two hits = 0.007125[/li][li]Probability of getting three hits = 0.000125[/li][/ul]
If you add them all up, you get 0.142625, which is the probability of getting at least one hit. To confirm, calculate the probability of not getting hit, which is 0.950.950.95 = 0.857375, then subtract that from 1 and you get 0.142625.

Terminus already demonstrated this is the right answer, but I just wanted to add…

If I had had to estimate the probability for your particular example, I would have guessed 15%, or 3 times 5%. That’s because the binomial distribution formula is approximately Np when n = 1 and Np is much less than 1. So when those conditions hold, this simplified expression gives you a “sanity check” for comparison.

Of course the real formula is simple enough that you might as well do the whole thing properly from the start. But I came of age in a world without cheap electronic computation, so I still tend to look for the shortcuts.

Thank you for the answers. I had no trouble understanding how to grind through the equation presented here (once I knew which variables went where and why), but that link to the mathematical expressions goes into math that is way beyond my ability. I don’t even know what some of those symbols are.

I’m not above using a few electronic shortcuts, though. Is there a program or a scripting software that does mathematical computations like this?

Of course, but ready-made solutions will cost you. Your average scripting language can do this.

Then I think I’ll pull out the ol’ Commodore 64 emulator and program in the formula, just for the joy of making it jump through hoops.

Means I’m gonna have to figure out how to make it comprehend factorials, though. :smiley:

The following pseudocode will compute the factorial of a non-negative integer.



factorial(n)
    factorial = 1
    for i = 2 to n
        factorial = factorial * i
    return factorial


Python is a cross-platform scripting language that supports arbitrary precision integers and many common math functions. It doesn’t include a factorial function, but you can roll your own quite easily. In fact ultrafilter’s pseudo-code maps to Python pretty much line-to-line.

If your system is some flavor of Unix, then you very likely have the bc utility already installed, which will do much the same stuff only using a terser syntax.

But if you have a Commodore 64 emulator handy, by all means fire it up. What better tool is there, really?

And I can even make the screen borders flash colors! Oh, and I have to make sure the C-64 program contains some [R][e][v][e][r][s][e] text.