# Statistical analysis question

**URL:** <https://boards.straightdope.com/t/statistical-analysis-question/315755>\
**Category:** Factual Questions\
**Created:** [August 5, 2005, 6:26pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755 "2005-08-05T18:26:17Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fish](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Fish](https://boards.straightdope.com/u/Fish)\
**Post date:** [August 5, 2005, 6:26pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/1 "2005-08-05T18:26:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bytegeist](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bytegeist](https://boards.straightdope.com/u/Bytegeist)\
**Post date:** [August 5, 2005, 6:50pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/2 "2005-08-05T18:50:08Z")

</div>

You’re probably after the [binomial distribution](http://mathworld.wolfram.com/BinomialDistribution.html).

---

<div class="post-metadata">

**Author:** ![Terminus\_Est](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/terminus_est/32/3087_2.png) [@Terminus\_Est](https://boards.straightdope.com/u/Terminus_Est)\
**Post date:** [August 5, 2005, 6:51pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/3 "2005-08-05T18:51:18Z")

</div>

> [@Fish](#):
>
> 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.

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

```auto

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.

---

<div class="post-metadata">

**Author:** ![Terminus\_Est](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/terminus_est/32/3087_2.png) [@Terminus\_Est](https://boards.straightdope.com/u/Terminus_Est)\
**Post date:** [August 5, 2005, 6:59pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/4 "2005-08-05T18:59:36Z")

</div>

> [@Bytegeist](#):
>
> You’re probably after the [binomial distribution](http://mathworld.wolfram.com/BinomialDistribution.html).

Aha! My calculations give me about 44.44%

```auto

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

```

---

<div class="post-metadata">

**Author:** ![Fish](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Fish](https://boards.straightdope.com/u/Fish)\
**Post date:** [August 5, 2005, 7:44pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/5 "2005-08-05T19:44:38Z")

</div>

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:

```auto

   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?

---

<div class="post-metadata">

**Author:** ![Terminus\_Est](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/terminus_est/32/3087_2.png) [@Terminus\_Est](https://boards.straightdope.com/u/Terminus_Est)\
**Post date:** [August 5, 2005, 8:14pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/6 "2005-08-05T20:14:13Z")

</div>

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.95_0.95_0.95 = 0.857375, then subtract that from 1 and you get 0.142625.

---

<div class="post-metadata">

**Author:** ![Bytegeist](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bytegeist](https://boards.straightdope.com/u/Bytegeist)\
**Post date:** [August 5, 2005, 8:43pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/7 "2005-08-05T20:43:53Z")

</div>

> [@Fish](#):
>
> If there are **three** villains attacking my hero …, each of whom has a **5%** chance to hit … the equation would look like: [Prob. of one hit =] 13.5375%
> 
> That number seems high to me.

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

---

<div class="post-metadata">

**Author:** ![Fish](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Fish](https://boards.straightdope.com/u/Fish)\
**Post date:** [August 5, 2005, 10:21pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/8 "2005-08-05T22:21:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [August 5, 2005, 10:26pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/9 "2005-08-05T22:26:49Z")

</div>

> [@Fish](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Fish](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Fish](https://boards.straightdope.com/u/Fish)\
**Post date:** [August 5, 2005, 11:10pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/10 "2005-08-05T23:10:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [August 5, 2005, 11:18pm UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/11 "2005-08-05T23:18:41Z")

</div>

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

```auto

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

```

---

<div class="post-metadata">

**Author:** ![Bytegeist](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bytegeist](https://boards.straightdope.com/u/Bytegeist)\
**Post date:** [August 6, 2005, 2:24am UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/12 "2005-08-06T02:24:04Z")

</div>

> [@Fish](#):
>
> Is there a program or a scripting software that does mathematical computations like this?

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?

---

<div class="post-metadata">

**Author:** ![Fish](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Fish](https://boards.straightdope.com/u/Fish)\
**Post date:** [August 6, 2005, 2:45am UTC](https://boards.straightdope.com/t/statistical-analysis-question/315755/13 "2005-08-06T02:45:26Z")

</div>

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.
