# NAG FL Interfaceg01faf (inv_​cdf_​normal)

## 1Purpose

g01faf returns the deviate associated with the given probability of the standard Normal distribution.

## 2Specification

Fortran Interface
 Function g01faf ( tail, p,
 Real (Kind=nag_wp) :: g01faf Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: p Character (1), Intent (In) :: tail
#include <nag.h>
 double g01faf_ (const char *tail, const double *p, Integer *ifail, const Charlen length_tail)
The routine may be called by the names g01faf or nagf_stat_inv_cdf_normal.

## 3Description

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$.
1. (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$.
2. (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$.
3. (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$.

## 4References

NIST Digital Library of Mathematical Functions
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

## 5Arguments

1: $\mathbf{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: $\mathbf{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: $\mathbf{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 $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
If on exit ${\mathbf{ifail}}\ne {\mathbf{0}}$, then g01faf returns $0.0$.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{tail}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{tail}}=\text{'L'}$, $\text{'U'}$, $\text{'S'}$ or $\text{'C'}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}<1.0$.
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}>0.0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The accuracy is mainly limited by the machine precision.

## 8Parallelism and Performance

g01faf is not threaded in any implementation.

None.

## 10Example

Four values of tail and p are input and the deviates calculated and printed.

### 10.1Program Text

Program Text (g01fafe.f90)

### 10.2Program Data

Program Data (g01fafe.d)

### 10.3Program Results

Program Results (g01fafe.r)