method
Draw samples from a noncentral chi-square distribution.
The noncentral \(\chi^2\) distribution is a generalization of the \(\chi^2\) distribution.
Degrees of freedom, must be > 0.
Non-centrality, must be non-negative.
Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if df and nonc are both scalars. Otherwise, np.broadcast(df, nonc).size samples are drawn.
Drawn samples from the parameterized noncentral chi-square distribution.
The probability density function for the noncentral Chi-square distribution is
where \(Y_{q}\) is the Chi-square with q degrees of freedom.
Wikipedia, “Noncentral chi-squared distribution” https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution
Draw values from the distribution and plot the histogram
>>> rng = np.random.default_rng() >>> import matplotlib.pyplot as plt >>> values = plt.hist(rng.noncentral_chisquare(3, 20, 100000), ... bins=200, density=True) >>> plt.show()
Draw values from a noncentral chisquare with very small noncentrality, and compare to a chisquare.
>>> plt.figure() >>> values = plt.hist(rng.noncentral_chisquare(3, .0000001, 100000), ... bins=np.arange(0., 25, .1), density=True) >>> values2 = plt.hist(rng.chisquare(3, 100000), ... bins=np.arange(0., 25, .1), density=True) >>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob') >>> plt.show()
Demonstrate how large values of non-centrality lead to a more symmetric distribution.
>>> plt.figure() >>> values = plt.hist(rng.noncentral_chisquare(3, 20, 100000), ... bins=200, density=True) >>> plt.show()
© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.4/reference/random/generated/numpy.random.Generator.noncentral_chisquare.html