nonCentralChiSqPdf

Evaluates the noncentral chi-squared probability density function.

Synopsis

nonCentralChiSqPdf (x, df, t_lambda)

Required Arguments

float x (Input)
Argument for which the noncentral chi-squared probability density function is to be evaluated. x must be greater than or equal to 0.
float df (Input)
Number of degrees of freedom of the noncentral chi-squared distribution. df must be greater than 0.
float t_lambda (Input)
Noncentrality parameter. t_lambda must be greater than or equal to 0.

Return Value

The probability density associated with a noncentral chi-squared random variable with value x.

Description

The noncentral chi‑squared distribution is a generalization of the chi-squared distribution. If \(\{X_i\}\) are k independent, normally distributed random variables with means \(\mu_i\) and variances \(\sigma^2_i\), then the random variable:

\[X = \sum_{i=1}^{k} \left(\frac{X_i}{\sigma_i}\right)^2\]

is distributed according to the noncentral chi-squared distribution. The noncentral chi-squared distribution has two parameters: k which specifies the number of degrees of freedom (i.e. the number of \(X_i\)), and λ which is related to the mean of the random variables \(X_i\) by:

\[\lambda = \sum_{i=1}^{k} \left(\frac{\mu_i}{\sigma_i}\right)^2\]

The noncentral chi-squared distribution is equivalent to a (central) chi-squared distribution with k + 2i degrees of freedom, where i is the value of a Poisson distributed random variable with parameter λ / 2. Thus, the probability density function is given by:

\[F(x|k,\lambda) = \sum_{i=0}^{\infty} \frac{e^{-\lambda/2}(\lambda/2)^i}{i!} f(x,k+2i)\]

where the (central) chi-squared PDF f(xk) is given by:

\[f(x|k) = \frac{(x/2)^{k/2} e^{-x/2}}{x\mathit{\Gamma}(k/2)} \text{ for } x > 0 \text{, else } 0\]

where Γ (⋅) is the gamma function. The above representation of F(xk, λ) can be shown to be equivalent to the representation:

\[F(x|k,\lambda) = \frac{e^{-(\lambda+x)/2} (x/2)^{k/2}}{x} \sum_{i=0}^{\infty} \phi_i\]
\[\phi_i = \frac{(\lambda x/4)^i}{i! \mathit{\Gamma} (k/2+i)}\]

Function nonCentralChiSqPdf evaluates the probability density function of a noncentral chi-squared random variable with df degrees of freedom and noncentrality parameter t_lambda, corresponding to k = df, λ = t_lambda, and x = x.

Function nonCentralChiSq evaluates the cumulative distribution function incorporating the above probability density function.

With a noncentrality parameter of zero, the noncentral chi-squared distribution is the same as the central chi-squared distribution.

Example

This example calculates the noncentral chi-squared distribution for a distribution with 100 degrees of freedom and noncentrality parameter \(\lambda=40\).

from __future__ import print_function
from numpy import *
from pyimsl.stat.nonCentralChiSqPdf import nonCentralChiSqPdf

x = [0, 8, 40, 136, 280, 400]
df = 100
lamb = 40.0

print("df: %4.0f;  lambda: %4.0f" % (df, lamb))
print("    x       pdf(x)")

for i in range(0, 6):
    pdfv = nonCentralChiSqPdf(x[i], df, lamb)
    print(" %5.0f  %12.4e" % (x[i], pdfv))

Output

df:  100;  lambda:   40
    x       pdf(x)
     0    0.0000e+00
     8    4.7548e-44
    40    3.4621e-14
   136    2.1092e-02
   280    4.0027e-10
   400    1.1250e-22