NAG FL Interface
g01fcf (inv_​cdf_​chisq)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

g01fcf returns the deviate associated with the given lower tail probability of the χ2-distribution with real degrees of freedom.

2 Specification

Fortran Interface
Function g01fcf ( p, df, ifail)
Real (Kind=nag_wp) :: g01fcf
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: p, df
C Header Interface
#include <nag.h>
double  g01fcf_ (const double *p, const double *df, Integer *ifail)
The routine may be called by the names g01fcf or nagf_stat_inv_cdf_chisq.

3 Description

The deviate, xp, associated with the lower tail probability p of the χ2-distribution with ν degrees of freedom is defined as the solution to
P(Xxp:ν)=p=12ν/2Γ(ν/2) 0xpe-X/2Xv/2-1dX,  0xp<;ν>0.  
The required xp is found by using the relationship between a χ2-distribution and a gamma distribution, i.e., a χ2-distribution with ν degrees of freedom is equal to a gamma distribution with scale parameter 2 and shape parameter ν/2.
For very large values of ν, greater than 105, Wilson and Hilferty's normal approximation to the χ2 is used; see Kendall and Stuart (1969).

4 References

Best D J and Roberts D E (1975) Algorithm AS 91. The percentage points of the χ2 distribution Appl. Statist. 24 385–388
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth
Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin

5 Arguments

1: p Real (Kind=nag_wp) Input
On entry: p, the lower tail probability from the required χ2-distribution.
Constraint: 0.0p<1.0.
2: df Real (Kind=nag_wp) Input
On entry: ν, the degrees of freedom of the χ2-distribution.
Constraint: df>0.0.
3: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value −1 is recommended since useful values can be provided in some output arguments even when ifail0 on exit. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
Note: in some cases g01fcf may return useful information.
If ifail=1, 2, 3 or 5 on exit, then g01fcf returns 0.0.
ifail=1
On entry, p=value.
Constraint: p<1.0.
On entry, p=value.
Constraint: p0.0.
ifail=2
On entry, df=value.
Constraint: df>0.0.
ifail=3
The probability is too close to 0.0 or 1.0.
ifail=4
The algorithm has failed to converge in value iterations. The result should be a reasonable approximation.
ifail=5
The series used to calculate the gamma function has failed to converge. This is an unlikely error exit.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

The results should be accurate to five significant digits for most argument values. Some accuracy is lost for p close to 0.0.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g01fcf is not threaded in any implementation.

9 Further Comments

For higher accuracy the relationship described in Section 3 may be used and a direct call to g01fff made.

10 Example

This example reads lower tail probabilities for several χ2-distributions, and calculates and prints the corresponding deviates until the end of data is reached.

10.1 Program Text

Program Text (g01fcfe.f90)

10.2 Program Data

Program Data (g01fcfe.d)

10.3 Program Results

Program Results (g01fcfe.r)