scipy.special.chndtr#

scipy.special.chndtr(x, df, nc, out=None) = <wrapped_ufunc 'chndtr'>#

Non-central chi-squared cumulative distribution function.

The cumulative distribution function is given by

\[F_{\nu,\lambda}(x) = \sum_{j=0}^{\infty} e^{-\lambda / 2} \frac{(\lambda / 2)^j}{j!} F_{\chi^2_{\nu + 2j}}(x),\]

where \(\nu > 0\) is the degrees of freedom (df), \(\lambda \geq 0\) is the non-centrality parameter (nc), and \(F_{\chi^2_{\nu + 2j}}\) is the CDF of the central chi-squared distribution with \(\nu + 2j\) degrees of freedom.

Parameters:
xarray_like

Upper bound of the integral; must satisfy x >= 0.

dfarray_like

Degrees of freedom; must satisfy df > 0.

ncarray_like

Non-centrality parameter; must satisfy nc >= 0.

outndarray, optional

Optional output array for the function results.

Returns:
cdfscalar or ndarray

Value of the non-central chi-squared cumulative distribution function.

See also

chndtrix

Noncentral Chi Squared distribution quantile

chndtridf

Inverse of chndtr with respect to df

chndtrinc

Inverse of chndtr with respect to nc

scipy.stats.ncx2

Non-central chi-squared distribution

Notes

The noncentral chi squared distribution is also available in scipy.stats.ncx2. scipy.stats.ncx2.cdf is equivalent to chndtr.

This function wraps routines from the Boost Math C++ library [1].

Array API Standard Support

chndtr has support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.

Library

CPU

GPU

NumPy

✅

n/a

CuPy

n/a

⛔

PyTorch

✅

⛔

JAX

✅

⛔

Dask

✅

n/a

For the NumPy backend, this function supports all NumPy ufunc keyword arguments. Other backends may support out, but typically none of the other ufunc kwargs. out is typically supported for CuPy and PyTorch, but not currently in cases where SciPy relies on a generic Array API implementation or, for PyTorch on CPU, falls back to the NumPy backend. out is never supported for JAX because JAX arrays are immutable. chndtr does not currently support out for the PyTorch backend.

See Support for the array API standard for more information.

References

[1]

The Boost Developers. “Boost C++ Libraries”. https://www.boost.org/.

Examples

>>> import numpy as np
>>> import scipy.special as sc

Compute the noncentral chi squared distribution CDF at one point.

>>> x = 4.0
>>> df = 1.0
>>> nc = 5.0
>>> sc.chndtr(x, df, nc)
0.40667858759710945

Plot the noncentral chi squared distribution CDF for different parameters.

>>> import matplotlib.pyplot as plt
>>> x = np.linspace(0, 40, 1000)
>>> plt.plot(x, sc.chndtr(x, 1, 5), label=r"$df=1,\ nc=5$")
>>> plt.plot(x, sc.chndtr(x, 5, 10), label=r"$df=5,\ nc=10$")
>>> plt.legend()
>>> plt.show()
../../_images/scipy-special-chndtr-1.png