scoringrules.crps_negbinom

Contents

scoringrules.crps_negbinom#

scoringrules.crps_negbinom(obs: ArrayLike, n: ArrayLike, prob: ArrayLike | None = None, *, mu: ArrayLike | None = None, backend: Backend = None) ArrayLike#

Compute the closed form of the CRPS for the negative binomial distribution.

It is based on the following formulation from [1]:

\[\mathrm{CRPS}(F_{n, p}, y) = y (2 F_{n, p}(y) - 1) - \frac{n(1 - p)}{p^{2}} \left( p (2 F_{n+1, p}(y - 1) - 1) + _{2} F_{1} \left( n + 1, \frac{1}{2}; 2; -\frac{4(1 - p)}{p^{2}} \right) \right),\]

where \(F_{n, p}\) is the CDF of the negative binomial distribution with size parameter \(n > 0\) and probability parameter \(p \in (0, 1]\). The mean of the negative binomial distribution is \(\mu = n (1 - p)/p\).

Parameters:
obsarray_like

The observed values.

n: array_like

Size parameter of the forecast negative binomial distribution.

probarray_like

Probability parameter of the forecast negative binomial distribution.

mu: array_like

Mean of the forecast negative binomial distribution.

Returns:
crpsarray_like

The CRPS between NegBinomial(n, prob) and obs.

Raises:
ValueError

If both prob and mu are provided, or if neither is provided.

References

[1]

Wei, W., Held, L. (2014), Calibration tests for count data. TEST 23, 787-805. https://doi.org/10.1007/s11749-014-0380-8

Examples

>>> import scoringrules as sr
>>> sr.crps_negbinom(2, 5, 0.5)
1.5533629909058577