G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01FAF

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.

## 1  Purpose

G01FAF returns the deviate associated with the given probability of the standard Normal distribution, via the routine name.

## 2  Specification

 FUNCTION G01FAF ( TAIL, P, IFAIL)
 REAL (KIND=nag_wp) G01FAF
 INTEGER IFAIL REAL (KIND=nag_wp) P CHARACTER(1) TAIL

## 3  Description

The deviate, ${x}_{p}$ associated with the lower tail probability, $p$, for the standard Normal distribution is defined as the solution to
 $PX≤xp=p=∫-∞xpZXdX,$
where
 $ZX=12πe-X2/2, -∞
The method used is an extension of that of Wichura (1988). $p$ is first replaced by $q=p-0.5$.
(a) If $\left|q\right|\le 0.3$, ${x}_{p}$ is computed by a rational Chebyshev approximation
 $xp=sAs2 Bs2 ,$
where $s=\sqrt{2\pi }q$ and $A$, $B$ are polynomials of degree $7$.
(b) If $0.3<\left|q\right|\le 0.42$, ${x}_{p}$ is computed by a rational Chebyshev approximation
 $xp=sign⁡q Ct Dt ,$
where $t=\left|q\right|-0.3$ and $C$, $D$ are polynomials of degree $5$.
(c) If $\left|q\right|>0.42$, ${x}_{p}$ is computed as
 $xp=sign⁡q Eu Fu +u ,$
where $u=\sqrt{-2×\mathrm{log}\left(\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,1-p\right)\right)}$ and $E$, $F$ are polynomials of degree $6$.
For the upper tail probability $-{x}_{p}$ is returned, while for the two tail probabilities the value ${x}_{{p}^{*}}$ is returned, where ${p}^{*}$ is the required tail probability computed from the input value of $p$.

## 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:     TAIL – CHARACTER(1)Input
On entry: indicates which tail the supplied probability represents.
${\mathbf{TAIL}}=\text{'L'}$
The lower probability, i.e., $P\left(X\le {x}_{p}\right)$.
${\mathbf{TAIL}}=\text{'U'}$
The upper probability, i.e., $P\left(X\ge {x}_{p}\right)$.
${\mathbf{TAIL}}=\text{'S'}$
The two tail (significance level) probability, i.e., $P\left(X\ge \left|{x}_{p}\right|\right)+P\left(X\le -\left|{x}_{p}\right|\right)$.
${\mathbf{TAIL}}=\text{'C'}$
The two tail (confidence interval) probability, i.e., $P\left(X\le \left|{x}_{p}\right|\right)-P\left(X\le -\left|{x}_{p}\right|\right)$.
Constraint: ${\mathbf{TAIL}}=\text{'L'}$, $\text{'U'}$, $\text{'S'}$ or $\text{'C'}$.
2:     P – REAL (KIND=nag_wp)Input
On entry: $p$, the probability from the standard Normal distribution as defined by TAIL.
Constraint: $0.0<{\mathbf{P}}<1.0$.
3:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
If on exit ${\mathbf{IFAIL}}\ne {\mathbf{0}}$, then G01FAF returns $0.0$.
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{TAIL}}\ne \text{'L'}$, $\text{'U'}$, $\text{'S'}$ or $\text{'C'}$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{P}}\le 0.0$, or ${\mathbf{P}}\ge 1.0$.

## 7  Accuracy

The accuracy is mainly limited by the machine precision.

None.

## 9  Example

Four values of TAIL and P are input and the deviates calculated and printed.

### 9.1  Program Text

Program Text (g01fafe.f90)

### 9.2  Program Data

Program Data (g01fafe.d)

### 9.3  Program Results

Program Results (g01fafe.r)