hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_prob_chisq (g01ec)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_stat_prob_chisq (g01ec) returns the lower or upper tail probability for the χ2-distribution with real degrees of freedom.

Syntax

[result, ifail] = g01ec(x, df, 'tail', tail)
[result, ifail] = nag_stat_prob_chisq(x, df, 'tail', tail)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: tail was made optional (default 'L')

Description

The lower tail probability for the χ2-distribution with ν degrees of freedom, PXx:ν is defined by:
PXx:ν=12ν/2Γν/2 0.0xXν/2-1e-X/2dX,  x0,ν>0.  
To calculate PXx:ν a transformation of a gamma distribution is employed, i.e., a χ2-distribution with ν degrees of freedom is equal to a gamma distribution with scale parameter 2 and shape parameter ν/2.

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

Parameters

Compulsory Input Parameters

1:     x – double scalar
x, the value of the χ2 variate with ν degrees of freedom.
Constraint: x0.0.
2:     df – double scalar
ν, the degrees of freedom of the χ2-distribution.
Constraint: df>0.0.

Optional Input Parameters

1:     tail – string (length ≥ 1)
Default: 'L'
Indicates whether the upper or lower tail probability is required.
tail='L'
The lower tail probability is returned, i.e., PXx:ν.
tail='U'
The upper tail probability is returned, i.e., PXx:ν.
Constraint: tail='L' or 'U'.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Note: nag_stat_prob_chisq (g01ec) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
If ifail=1, 2 or 3 on exit, then nag_stat_prob_chisq (g01ec) returns 0.0.
   ifail=1
On entry,tail'L' or 'U'.
   ifail=2
On entry,x<0.0.
   ifail=3
On entry,df0.0.
   ifail=4
The solution has failed to converge while calculating the gamma variate. The result returned should represent an approximation to the solution.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

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

Further Comments

For higher accuracy the transformation described in Description may be used with a direct call to nag_specfun_gamma_incomplete (s14ba).

Example

Values from various χ2-distributions are read, the lower tail probabilities calculated, and all these values printed out, until the end of data is reached.
function g01ec_example


fprintf('g01ec example results\n\n');

% Lower tail probabilities for Chi^2 distribution
x  = [ 8.26; 6.2; 55.76];
df = [20.00; 7.5; 45.00];
tail = {'Lower'; 'Lower'; 'Lower';};

fprintf('  Tail    x      df    probability\n');
for j = 1:numel(x);

  [p, ifail] = g01ec( ...
                      x(j), df(j), 'tail', tail{j});

  fprintf('%4s%8.3f%8.1f%12.4f\n',tail{j}(1), x(j), df(j), p);
end


g01ec example results

  Tail    x      df    probability
   L   8.260    20.0      0.0100
   L   6.200     7.5      0.4279
   L  55.760    45.0      0.8694

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015