nag_deviates_chi_sq (g01fcc) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_deviates_chi_sq (g01fcc)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_deviates_chi_sq (g01fcc) returns the deviate associated with the given lower tail probability of the χ2-distribution with real degrees of freedom.

2  Specification

#include <nag.h>
#include <nagg01.h>
double  nag_deviates_chi_sq (double p, double df, NagError *fail)

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
PXxp:ν=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 doubleInput
On entry: p, the lower tail probability from the required χ2-distribution.
Constraint: 0.0p<1.0.
2:     df doubleInput
On entry: ν, the degrees of freedom of the χ2-distribution.
Constraint: df>0.0.
3:     fail NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

6  Error Indicators and Warnings

On any of the error conditions listed below except fail.code= NE_ALG_NOT_CONV nag_deviates_chi_sq (g01fcc) returns 0.0.
NE_ALG_NOT_CONV
The algorithm has failed to converge in value iterations. The result should be a reasonable approximation.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_GAM_NOT_CONV
The series used to calculate the gamma function has failed to converge. This is an unlikely error exit.
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.
An unexpected error has been triggered by this function. Please contact NAG.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_PROBAB_CLOSE_TO_TAIL
The probability is too close to 0.0  or 1.0 .
NE_REAL_ARG_GE
On entry, p=value.
Constraint: p<1.0.
NE_REAL_ARG_LE
On entry, df=value.
Constraint: df>0.0.
NE_REAL_ARG_LT
On entry, p=value.
Constraint: p0.0.

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

nag_deviates_chi_sq (g01fcc) 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 nag_deviates_gamma_dist (g01ffc) 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 (g01fcce.c)

10.2  Program Data

Program Data (g01fcce.d)

10.3  Program Results

Program Results (g01fcce.r)


nag_deviates_chi_sq (g01fcc) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2016