G01TAF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G01TAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G01TAF returns a number of deviates associated with given probabilities of the Normal distribution.

2  Specification

SUBROUTINE G01TAF ( LTAIL, TAIL, LP, P, LXMU, XMU, LXSTD, XSTD, X, IVALID, IFAIL)
INTEGER  LTAIL, LP, LXMU, LXSTD, IVALID(*), IFAIL
REAL (KIND=nag_wp)  P(LP), XMU(LXMU), XSTD(LXSTD), X(*)
CHARACTER(1)  TAIL(LTAIL)

3  Description

The deviate, xpi associated with the lower tail probability, pi, for the Normal distribution is defined as the solution to
PXixpi=pi=-xpiZiXidXi,  
where
ZiXi=12πσi2e-Xi-μi2/2σi2, ​-<Xi< .  
The method used is an extension of that of Wichura (1988). pi is first replaced by qi=pi-0.5.
(a) If qi0.3, zi is computed by a rational Chebyshev approximation
zi=siAisi2 Bisi2 ,  
where si=2πqi and Ai, Bi are polynomials of degree 7.
(b) If 0.3<qi0.42, zi is computed by a rational Chebyshev approximation
zi=signqi Citi Diti ,  
where ti=qi-0.3 and Ci, Di are polynomials of degree 5.
(c) If qi>0.42, zi is computed as
zi=signqi Eiui Fiui +ui ,  
where ui = -2 × log minpi,1-pi  and Ei, Fi are polynomials of degree 6.
xpi is then calculated from zi, using the relationsship zpi = xi - μi σi .
For the upper tail probability -xpi is returned, while for the two tail probabilities the value xipi* is returned, where pi* is the required tail probability computed from the input value of pi.
The input arrays to this routine are designed to allow maximum flexibility in the supply of vector parameters by re-using elements of any arrays that are shorter than the total number of evaluations required. See Section 2.6 in the G01 Chapter Introduction for further information.

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
Wichura (1988) Algorithm AS 241: the percentage points of the Normal distribution Appl. Statist. 37 477–484

5  Parameters

1:     LTAIL – INTEGERInput
On entry: the length of the array TAIL.
Constraint: LTAIL>0.
2:     TAILLTAIL – CHARACTER(1) arrayInput
On entry: indicates which tail the supplied probabilities represent. Letting Z denote a variate from a standard Normal distribution, and zi = xpi - μi σi , then for j= i-1 mod LTAIL +1 , for i=1,2,,maxLTAIL,LP,LXMU,LXSTD:
TAILj='L'
The lower tail probability, i.e., pi=PZzi.
TAILj='U'
The upper tail probability, i.e., pi=PZzi.
TAILj='C'
The two tail (confidence interval) probability, i.e., pi=PZzi-PZ-zi.
TAILj='S'
The two tail (significance level) probability, i.e., pi=PZzi+PZ-zi.
Constraint: TAILj='L', 'U', 'C' or 'S', for j=1,2,,LTAIL.
3:     LP – INTEGERInput
On entry: the length of the array P.
Constraint: LP>0.
4:     PLP – REAL (KIND=nag_wp) arrayInput
On entry: pi, the probabilities for the Normal distribution as defined by TAIL with pi=Pj, j=i-1 mod LP+1.
Constraint: 0.0<Pj<1.0, for j=1,2,,LP.
5:     LXMU – INTEGERInput
On entry: the length of the array XMU.
Constraint: LXMU>0.
6:     XMULXMU – REAL (KIND=nag_wp) arrayInput
On entry: μi, the means with μi=XMUj, j=i-1 mod LXMU+1.
7:     LXSTD – INTEGERInput
On entry: the length of the array XSTD.
Constraint: LXSTD>0.
8:     XSTDLXSTD – REAL (KIND=nag_wp) arrayInput
On entry: σi, the standard deviations with σi=XSTDj, j=i-1 mod LXSTD+1.
Constraint: XSTDj>0.0, for j=1,2,,LXSTD.
9:     X* – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array X must be at least maxLTAIL,LXMU,LXSTD,LP.
On exit: xpi, the deviates for the Normal distribution.
10:   IVALID* – INTEGER arrayOutput
Note: the dimension of the array IVALID must be at least maxLTAIL,LXMU,LXSTD,LP.
On exit: IVALIDi indicates any errors with the input arguments, with
IVALIDi=0
No error.
IVALIDi=1
On entry,invalid value supplied in TAIL when calculating xpi.
IVALIDi=2
On entry,pi0.0,
orpi1.0.
IVALIDi=3
On entry,σi0.0.
11:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. 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:
IFAIL=1
On entry, at least one value of TAIL, XSTD or P was invalid.
Check IVALID for more information.
IFAIL=2
On entry, array size=value.
Constraint: LTAIL>0.
IFAIL=3
On entry, array size=value.
Constraint: LP>0.
IFAIL=4
On entry, array size=value.
Constraint: LXMU>0.
IFAIL=5
On entry, array size=value.
Constraint: LXSTD>0.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

The accuracy is mainly limited by the machine precision.

8  Parallelism and Performance

Not applicable.

9  Further Comments

None.

10  Example

This example reads vectors of values for μi, σi and pi and prints the corresponding deviates.

10.1  Program Text

Program Text (g01tafe.f90)

10.2  Program Data

Program Data (g01tafe.d)

10.3  Program Results

Program Results (g01tafe.r)


G01TAF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

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