chiSquaredCdf¶
Evaluates the chi‑squared cumulative distribution function (CDF).
Synopsis¶
chiSquaredCdf (chiSquared, df)
Required Arguments¶
- float
chiSquared
(Input) - Argument for which the chi‑squared distribution function is to be evaluated.
- float
df
(Input) - Number of degrees of freedom of the chi‑squared distribution. Argument
df
must be greater than 0.
Return Value¶
The probability p that a chi‑squared random variable takes a value less
than or equal to chiSquared
.
Description¶
Function chiSquaredCdf
evaluates the distribution function,
\(F(x,ν)\), of a chi‑squared random variable x = chiSquared
with ν
= df
degrees of freedom, where:
and \(\Gamma(\cdot)\) is the gamma function. The value of the distribution function at the point x is the probability that the random variable takes a value less than or equal to x.
For \(v>\nu_{max}=1.e7\), chiSquaredCdf
uses the Wilson-Hilferty
approximation (Abramowitz and Stegun [A&S] 1964, Equation 26.4.17) for p in
terms of the normal CDF, which is evaluated using function
normalCdf.
For \(v\leq\nu _{max}\), chiSquaredCdf
uses series expansions to
evaluate p: for \(x<\nu\), chiSquaredCdf
calculates p using A&S
series 6.5.29, and for \(x\geq\nu\), chiSquaredCdf
calculates p
using the continued fraction expansion of the incomplete gamma function given
in A&S equation 6.5.31.
Figure 9.21 — Plot of Fx (x, df)
Example¶
Suppose X is a chi‑squared random variable with two degrees of freedom. In this example, we find the probability that X is less than 0.15 and the probability that X is greater than 3.0.
from __future__ import print_function
from numpy import *
from pyimsl.math.chiSquaredCdf import chiSquaredCdf
chi_squared = 0.15
df = 2.0
p = chiSquaredCdf(chi_squared, df)
print("The probability that chi-squared ", end=' ')
print("with 2 df is less than 0.15 is %6.4f" % (p))
chi_squared = 3.0
p = 1.0 - chiSquaredCdf(chi_squared, df)
print("The probability that chi-squared ", end=' ')
print("with 2 df is less than 3.0 is %6.4f" % (p))
Output¶
The probability that chi-squared with 2 df is less than 0.15 is 0.0723
The probability that chi-squared with 2 df is less than 3.0 is 0.2231
Informational Errors¶
IMSL_ARG_LESS_THAN_ZERO |
Since “chiSquared ” = #is less
than zero, the distribution function is
zero at “chiSquared .” |
Alert Errors¶
IMSL_NORMAL_UNDERFLOW |
Using the normal distribution for large degrees of freedom, underflow would have occurred. |