g01 Chapter Contents
g01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_prob_chi_sq (g01ecc)

## 1  Purpose

nag_prob_chi_sq (g01ecc) returns the lower or upper tail probability for the ${\chi }^{2}$-distribution with real degrees of freedom.

## 2  Specification

 #include #include
 double nag_prob_chi_sq (Nag_TailProbability tail, double x, double df, NagError *fail)

## 3  Description

The lower tail probability for the ${\chi }^{2}$-distribution with $\nu$ degrees of freedom, $P\left(X\le x:\nu \right)$ is defined by:
 $PX≤x:ν=12ν/2Γν/2 ∫0.0xXν/2-1e-X/2dX, x≥0,ν>0.$
To calculate $P\left(X\le x:\nu \right)$ a transformation of a gamma distribution is employed, i.e., a ${\chi }^{2}$-distribution with $\nu$ degrees of freedom is equal to a gamma distribution with scale parameter $2$ and shape parameter $\nu /2$.

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

## 5  Arguments

1:     tailNag_TailProbabilityInput
On entry: indicates whether the upper or lower tail probability is required.
${\mathbf{tail}}=\mathrm{Nag_LowerTail}$
The lower tail probability is returned, i.e., $P\left(X\le x:\nu \right)$.
${\mathbf{tail}}=\mathrm{Nag_UpperTail}$
The upper tail probability is returned, i.e., $P\left(X\ge x:\nu \right)$.
Constraint: ${\mathbf{tail}}=\mathrm{Nag_LowerTail}$ or $\mathrm{Nag_UpperTail}$.
2:     xdoubleInput
On entry: $x$, the value of the ${\chi }^{2}$ variate with $\nu$ degrees of freedom.
Constraint: ${\mathbf{x}}\ge 0.0$.
3:     dfdoubleInput
On entry: $\nu$, the degrees of freedom of the ${\chi }^{2}$-distribution.
Constraint: ${\mathbf{df}}>0.0$.
4:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

On any of the error conditions listed below except NE_ALG_NOT_CONV nag_prob_chi_sq (g01ecc) returns $0.0$.
NE_ALG_NOT_CONV
The series used to calculate the gamma probabilities has failed to converge. The result returned should represent an approximation to the solution.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL_ARG_LE
On entry, ${\mathbf{df}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{df}}>0.0$.
NE_REAL_ARG_LT
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\ge 0.0$.

## 7  Accuracy

A relative accuracy of five significant figures is obtained in most cases.

For higher accuracy the transformation described in Section 3 may be used with a direct call to nag_incomplete_gamma (s14bac).

## 9  Example

Values from various ${\chi }^{2}$-distributions are read, the lower tail probabilities calculated, and all these values printed out, until the end of data is reached.

### 9.1  Program Text

Program Text (g01ecce.c)

### 9.2  Program Data

Program Data (g01ecce.d)

### 9.3  Program Results

Program Results (g01ecce.r)