Build confidence intervals for the rate of a Poisson random variable using the Feldman-Cousins construction (Feldman and Cousins, 1998).

```
confint_pois(
n,
b = 0,
cl = 0.95,
acc = 0.001 * (max(n - b, 0) + 1),
lambda_min = NULL,
lambda_max = NULL
)
```

- n
number of events. Numeric vector of length one.

- b
expected number of background events. Numeric vector of length one or three (see Details).

- cl
confidence level for the returned confidence interval. A number between zero and one.

- acc
required accuracy in the confidence interval endpoints. A positive number.

- lambda_min, lambda_max
window of Poisson rate values for whom the Neyman belt construction is performed. Numeric vectors of length one or

`NULL`

(see Details). For advanced users only, use the default value (`NULL`

) if unsure.

a numeric vector of length two, containing the confidence interval endpoints.

The Feldman-Cousins confidence intervals construction
(Feldman and Cousins, 1998) provides a unified treatment for the estimation
of Poisson rates, which
produces consistent results for both the common case, where the number of
observed events `n`

is greater than the number of background events
`b`

, and the boundary cases, when `n`

is equal or even less than
`b`

. In these last cases, a naive treatment can lead to either
overcovering (that is, unnecessarily large confidence intervals;
this is the case for, *e.g.*, the intervals returned from
`stats::poisson.test`

for zero events and no background) or,
even worse, undercovering and/or non-sensical confidence intervals
(relevant examples can be found in (Feldman and Cousins, 1998)).

In order to find confidence intervals, the standard Neyman construction
is performed over a grid of values for the estimated rate. The search
interval can be controlled through the parameters `lambda_min`

and
`lambda_max`

; if these are left as default (`NULL`

), they are
estimated automatically based on a rough estimate, which should be adequate
in a large majority of cases.

The argument `b`

controls the expected number of background events,
which would differ from zero if some of the event counts are expected
to correspond to spurious events. In other words, the number of total counts
`n`

is assumed to follow a Poisson distribution with rate
`lambda + b`

, with `b`

known and `lambda`

unknown and to be
estimated.

The original reference discusses a minor correction to confidence intervals,
which ensures that the produced upper limits are decreasing functions of
`b`

.
This is computationally intensive and not necessary for the correctness of
Feldman-Cousins confidence intervals, but may facilitate interpretation for
e.g. sensitivity analyses.
The correction can be implemented by providing a length three numeric to the
`b`

argument, such that `b[[1]]`

is the expected background rate as
before, while `b[[2]]`

and `b[[3]]`

represent a maximum value
for `b`

and a grid step. The construction is repeated over the whole
grid of `b`

values and the actual upper limit is chosen as the
greatest upper limit encountered in the sequence of intervals so constructed.

Feldman, Gary J. and Cousins, Robert D.
"Unified approach to the classical statistical analysis of small signals"
*Phys. Rev. D* **57**, issue 7 (1998): 3873-3889.

```
confint_pois(n = 10, cl = 0.68)
#> [1] 6.781298 13.804798
#> attr(,"cl")
#> [1] 0.68
confint_pois(n = 10, b = 5, cl = 0.68)
#> [1] 1.899 8.805
#> attr(,"cl")
#> [1] 0.68
# Compare:
confint_pois(n = 0, cl = 0.95)
#> [1] 0.0000 3.0925
#> attr(,"cl")
#> [1] 0.95
# with:
poisson.test(x = 0, conf.level = 0.95)$conf.int
#> [1] 0.000000 3.688879
#> attr(,"conf.level")
#> [1] 0.95
```