I have detector which will detect an event with some probability *p*. If the detector says that an event occured, then that is always the case, so there are not false-positives. After I run it for some time, I get *k* events detected. I would like to calculate what the total number of events that occured was, detected or otherwise, with some confidence, say 95%.

So for example, let's say I get 13 events detected. I would like to be able to calculate that there were between 13 and 19 events with 95% confidence based on *p*.

Here's what I've tried so far:

The probability of detecting *k* events if there were *n* total is:

`binomial(n, k) * p^k * (1 - p)^(n - k)`

The sum of that over *n* from *k* to infinity is:

`1/p`

Which means, that the probability of there being *n* events total is:

`f(n) = binomial(n, k) * p^(k + 1) * (1 - p)^(n - k)`

So if I want to be 95% sure I should find the first partial sum `f(k) + f(k+1) + f(k+2) ... + f(k+m)`

which is at least 0.95 and the answer is `[k, k+m]`

. Is this the correct approach? Also is there a closed formula for the answer?

**Contents**hide

#### Best Answer

I would choose to use the negative binomial distribution, which returns the probability that there will be X failures before the k_th success, when the constant probability of a success is p.

Using an example

`k=17 # number of successes p=.6 # constant probability of success `

the mean and sd for the failures are given by

`mean.X <- k*(1-p)/p sd.X <- sqrt(k*(1-p)/p^2) `

The distribution of the failures X, will have approximately that shape

`plot(dnbinom(0:(mean.X + 3 * sd.X),k,p),type='l') `

So, the number of failures will be (with 95% confidence) approximately between

`qnbinom(.025,k,p) [1] 4 `

and

`qnbinom(.975,k,p) [1] 21 `

So you inerval would be [k+qnbinom(.025,k,p),k+qnbinom(.975,k,p)] (using the example's numbers [21,38] )

### Similar Posts:

- Solved – How to find a confidence interval for the total number of events
- Solved – How to find a confidence interval for the total number of events
- Solved – Expected number of failures preceding the first success
- Solved – Difference between geometric distribution and negative binomial distribution
- Solved – How to calculate a confidence interval for a series of Bernoulli Trials