Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé
Module « scipy.special »

Fonction nbdtrik - module scipy.special

Signature de la fonction nbdtrik

def nbdtrik(*args, **kwargs) 

Description

help(scipy.special.nbdtrik)

nbdtrik(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])

nbdtrik(y, n, p, out=None)

Negative binomial percentile function.

Returns the inverse with respect to the parameter `k` of
``y = nbdtr(k, n, p)``, the negative binomial cumulative distribution
function.

Parameters
----------
y : array_like
    The probability of `k` or fewer failures before `n` successes (float).
n : array_like
    The target number of successes (positive int).
p : array_like
    Probability of success in a single event (float).
out : ndarray, optional
    Optional output array for the function results

Returns
-------
k : scalar or ndarray
    The maximum number of allowed failures such that `nbdtr(k, n, p) = y`.

See Also
--------
nbdtr : Cumulative distribution function of the negative binomial.
nbdtrc : Survival function of the negative binomial.
nbdtri : Inverse with respect to `p` of `nbdtr(k, n, p)`.
nbdtrin : Inverse with respect to `n` of `nbdtr(k, n, p)`.
scipy.stats.nbinom : Negative binomial distribution

Notes
-----
Wrapper for the CDFLIB [1]_ Fortran routine `cdfnbn`.

Formula 26.5.26 of [2]_,

.. math::
    \sum_{j=k + 1}^\infty {{n + j - 1}
    \choose{j}} p^n (1 - p)^j = I_{1 - p}(k + 1, n),

is used to reduce calculation of the cumulative distribution function to
that of a regularized incomplete beta :math:`I`.

Computation of `k` involves a search for a value that produces the desired
value of `y`.  The search relies on the monotonicity of `y` with `k`.

References
----------
.. [1] Barry Brown, James Lovato, and Kathy Russell,
       CDFLIB: Library of Fortran Routines for Cumulative Distribution
       Functions, Inverses, and Other Parameters.
.. [2] Milton Abramowitz and Irene A. Stegun, eds.
       Handbook of Mathematical Functions with Formulas,
       Graphs, and Mathematical Tables. New York: Dover, 1972.

Examples
--------
Compute the negative binomial cumulative distribution function for an
exemplary parameter set.

>>> import numpy as np
>>> from scipy.special import nbdtr, nbdtrik
>>> k, n, p = 5, 2, 0.5
>>> cdf_value = nbdtr(k, n, p)
>>> cdf_value
0.9375

Verify that `nbdtrik` recovers the original value for `k`.

>>> nbdtrik(cdf_value, n, p)
5.0

Plot the function for different parameter sets.

>>> import matplotlib.pyplot as plt
>>> p_parameters = [0.2, 0.5, 0.7, 0.5]
>>> n_parameters = [30, 30, 30, 80]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(p_parameters, n_parameters, linestyles))
>>> cdf_vals = np.linspace(0, 1, 1000)
>>> fig, ax = plt.subplots(figsize=(8, 8))
>>> for parameter_set in parameters_list:
...     p, n, style = parameter_set
...     nbdtrik_vals = nbdtrik(cdf_vals, n, p)
...     ax.plot(cdf_vals, nbdtrik_vals, label=rf"$n={n},\ p={p}$",
...             ls=style)
>>> ax.legend()
>>> ax.set_ylabel("$k$")
>>> ax.set_xlabel("$CDF$")
>>> ax.set_title("Negative binomial percentile function")
>>> plt.show()

The negative binomial distribution is also available as
`scipy.stats.nbinom`. The percentile function  method ``ppf``
returns the result of `nbdtrik` rounded up to integers:

>>> from scipy.stats import nbinom
>>> q, n, p = 0.6, 5, 0.5
>>> nbinom.ppf(q, n, p), nbdtrik(q, n, p)
(5.0, 4.800428460273882)


Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé