📅  最后修改于: 2023-12-03 15:20:00.197000             🧑  作者: Mango
The scipy.stats.chi()
function calculates the probability density function (PDF) and cumulative distribution function (CDF) for the chi distribution. The chi distribution is a continuous probability distribution that arises in statistics and engineering for various applications, such as testing the goodness of fit of data, analyzing the time between random events, and estimating population variances.
scipy.stats.chi(df, loc=0, scale=1)
df
: degrees of freedomloc
: location parameter (default is 0)scale
: scale parameter (default is 1)x
: array_like
Values at which to evaluate the PDF or CDFdf
: float or array_like
Degrees of freedomloc
: float or array_like
Location parameter (default is 0)scale
: float or array_like
Scale parameter (default is 1)pdf
: ndarray or float
Probability density function evaluated at xcdf
: ndarray or float
Cumulative distribution function evaluated at ximport numpy as np
import matplotlib.pyplot as plt
from scipy.stats import chi
df = 3
fig, ax = plt.subplots(1, 1)
x = np.linspace(chi.ppf(0.01, df), chi.ppf(0.99, df), 100)
ax.plot(x, chi.pdf(x, df), 'r-', lw=5, alpha=0.6, label='chi pdf')
plt.legend(loc='best')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import chi
df = 3
fig, ax = plt.subplots(1, 1)
x = np.linspace(chi.ppf(0.01, df), chi.ppf(0.99, df), 100)
ax.plot(x, chi.cdf(x, df), 'b-', lw=5, alpha=0.6, label='chi cdf')
plt.legend(loc='best')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import chi
df = 3
fig, ax = plt.subplots(1, 1)
r = chi.rvs(df, size=1000)
ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
ax.legend(loc='best', frameon=False)
plt.show()
In conclusion, the scipy.stats.chi()
function is useful for calculating the PDF and CDF of the chi distribution. The degree of freedom, location, and scale parameters can be adjusted to fit specific needs. The function can be used to test the goodness of fit of data, analyze time between random events, and estimate population variances.