Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_inv_cdf_normal (g01fa)

## Purpose

nag_stat_inv_cdf_normal (g01fa) returns the deviate associated with the given probability of the standard Normal distribution.

## Syntax

[result, ifail] = g01fa(p, 'tail', tail)
[result, ifail] = nag_stat_inv_cdf_normal(p, '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 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$.

## 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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{p}$ – double scalar
$p$, the probability from the standard Normal distribution as defined by tail.
Constraint: $0.0<{\mathbf{p}}<1.0$.

### Optional Input Parameters

1:     $\mathrm{tail}$ – string (length ≥ 1)
Default: $\text{'L'}$
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'}$.

### Output Parameters

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

## Error Indicators and Warnings

Errors or warnings detected by the function:
If on exit ${\mathbf{ifail}}\ne {\mathbf{0}}$, then nag_stat_inv_cdf_normal (g01fa) 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$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The accuracy is mainly limited by the machine precision.

None.

## Example

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

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

p    = [ 0.975;    0.025;        0.950;   0.050];
tail = {'Lower'; 'Upper'; 'Confidence'; 'Significance'};

fprintf('  Tail    probability    deviate\n');
for j = 1:numel(p);

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

fprintf('%4s%14.3f%14.4f\n', tail{j}(1), p(j), x);
end

```
```g01fa example results

Tail    probability    deviate
L         0.975        1.9600
U         0.025        1.9600
C         0.950        1.9600
S         0.050        1.9600
```