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∣v) , of a chi-squared random variable x = chiSquared
with ν = df
degrees of freedom, where:
and Γ (⋅) 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>v_{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 v_{max}\), chiSquaredCdf
uses series expansions to
evaluate
p: for \(x<\nu\), chiSquaredCdf
calculates p using A&S series
6.5.29, and for \(x>\nu\), chiSquaredCdf
calculates p using the
continued fraction expansion of the incomplete gamma function given in A&S
equation 6.5.31.
Figure 11.3 — 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.stat.chiSquaredCdf import chiSquaredCdf
chi_squared = 0.15
df = 2.0
pr1 = chiSquaredCdf(chi_squared, df)
print("The probability that chi-squared")
print(" with 2 df is less than 0.15 is %6.4f" % pr1)
chi_squared = 3.0
pr2 = 1.0 - chiSquaredCdf(chi_squared, df)
print("The probability that chi-squared")
print(" with 2 df is greater than 3.0 is %6.4f" % pr2)
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 greater than 3.0 is 0.2231
Informational Errors¶
IMSLS_ARG_LESS_THAN_ZERO |
Since “chiSquared ” = # is less
than zero, the distribution function
is zero at “chiSquared .” |
Alert Errors¶
IMSLS_NORMAL_UNDERFLOW |
Using the normal distribution for large degrees of freedom, underflow would have occurred. |