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_prob_normal (g01ea)

## Purpose

nag_stat_prob_normal (g01ea) returns a one or two tail probability for the standard Normal distribution.

## Syntax

[result, ifail] = g01ea(x, 'tail', tail)
[result, ifail] = nag_stat_prob_normal(x, '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 standard Normal distribution, $P\left(X\le x\right)$ is defined by:
 $PX≤x=∫-∞xZXdX,$
where
 $ZX=12π e-X2/2, -∞
The relationship
 $PX≤x=12erfc-x2$
is used, where erfc is the complementary error function, and is computed using nag_specfun_erfc_real (s15ad). For the upper tail probability the relationship $P\left(X\ge x\right)=P\left(X\le -x\right)$ is used and for the two tail significance level probability twice the probability obtained from the absolute value of $x$ is returned.
When the two tail confidence probability is required the relationship
 $PX≤x-PX≤-x=erfx2 ,$
is used, where erf is the error function, and is computed using nag_specfun_erf_real (s15ae).

## 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:     $\mathrm{x}$ – double scalar
$x$, the value of the standard Normal variate.

### Optional Input Parameters

1:     $\mathrm{tail}$ – string (length ≥ 1)
Default: $\text{'L'}$
Indicates which tail the returned probability should represent.
${\mathbf{tail}}=\text{'L'}$
The lower tail probability is returned, i.e., $P\left(X\le x\right)$.
${\mathbf{tail}}=\text{'U'}$
The upper tail probability is returned, i.e., $P\left(X\ge x\right)$.
${\mathbf{tail}}=\text{'S'}$
The two tail (significance level) probability is returned, i.e., $P\left(X\ge \left|x\right|\right)+P\left(X\le -\left|x\right|\right)$.
${\mathbf{tail}}=\text{'C'}$
The two tail (confidence interval) probability is returned, i.e., $P\left(X\le \left|x\right|\right)-P\left(X\le -\left|x\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 ${\mathbf{ifail}}\ne {\mathbf{0}}$, then nag_stat_prob_normal (g01ea) returns $0.0$.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{tail}}\ne \text{'L'}$, $\text{'U'}$, $\text{'S'}$ or $\text{'C'}$.
${\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

Accuracy is limited by machine precision. For detailed error analysis see nag_specfun_erfc_real (s15ad) and nag_specfun_erf_real (s15ae).

None.

## Example

Four values of tail and x are input and the probabilities calculated and printed.
```function g01ea_example

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

% Probability for Normal distribution
x     = 1.96;
tail = {'Lower'; 'Upper'; 'Confidence'; 'Significance'};

fprintf('  Tail    x      probability\n');
for j = 1:size(tail,1);

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

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

```
```g01ea example results

Tail    x      probability
L    1.96      0.9750
U    1.96      0.0250
C    1.96      0.9500
S    1.96      0.0500
```