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_vector (g01sa)

Purpose

nag_stat_prob_normal_vector (g01sa) returns a number of one or two tail probabilities for the Normal distribution.

Syntax

[p, ivalid, ifail] = g01sa(tail, x, xmu, xstd, 'ltail', ltail, 'lx', lx, 'lxmu', lxmu, 'lxstd', lxstd)
[p, ivalid, ifail] = nag_stat_prob_normal_vector(tail, x, xmu, xstd, 'ltail', ltail, 'lx', lx, 'lxmu', lxmu, 'lxstd', lxstd)

Description

The lower tail probability for the Normal distribution, $P\left({X}_{i}\le {x}_{i}\right)$ is defined by:
 $PXi≤xi = ∫ -∞ xi ZiXidXi ,$
where
 $ZiXi = 1 2πσi2 e -Xi-μi2/2σi2 , -∞ < Xi < ∞ .$
The relationship
 $P Xi ≤ xi = 12 erfc - xi - μi 2 σi$
is used, where erfc is the complementary error function, and is computed using nag_specfun_erfc_real (s15ad).
When the two tail confidence probability is required the relationship
 $P Xi≤xi - P Xi ≤ - xi = erf xi - μi 2 σi ,$
is used, where erf is the error function, and is computed using nag_specfun_erf_real (s15ae).
The input arrays to this function are designed to allow maximum flexibility in the supply of vector arguments by re-using elements of any arrays that are shorter than the total number of evaluations required. See Vectorized Routines in the G01 Chapter Introduction for further information.

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{tail}\left({\mathbf{ltail}}\right)$ – cell array of strings
Indicates which tail the returned probabilities should represent. Letting $Z$ denote a variate from a standard Normal distribution, and ${z}_{i}=\frac{{x}_{i}-{\mu }_{i}}{{\sigma }_{i}}$, then for , for $\mathit{i}=1,2,\dots ,\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{lx}},{\mathbf{ltail}},{\mathbf{lxmu}},{\mathbf{lxstd}}\right)$:
${\mathbf{tail}}\left(j\right)=\text{'L'}$
The lower tail probability is returned, i.e., ${p}_{i}=P\left(Z\le {z}_{i}\right)$.
${\mathbf{tail}}\left(j\right)=\text{'U'}$
The upper tail probability is returned, i.e., ${p}_{i}=P\left(Z\ge {z}_{i}\right)$.
${\mathbf{tail}}\left(j\right)=\text{'C'}$
The two tail (confidence interval) probability is returned, i.e., ${p}_{i}=P\left(Z\le \left|{z}_{i}\right|\right)-P\left(Z\le -\left|{z}_{i}\right|\right)$.
${\mathbf{tail}}\left(j\right)=\text{'S'}$
The two tail (significance level) probability is returned, i.e., ${p}_{i}=P\left(Z\ge \left|{z}_{i}\right|\right)+P\left(Z\le -\left|{z}_{i}\right|\right)$.
Constraint: ${\mathbf{tail}}\left(\mathit{j}\right)=\text{'L'}$, $\text{'U'}$, $\text{'C'}$ or $\text{'S'}$, for $\mathit{j}=1,2,\dots ,{\mathbf{ltail}}$.
2:     $\mathrm{x}\left({\mathbf{lx}}\right)$ – double array
${x}_{i}$, the Normal variate values with ${x}_{i}={\mathbf{x}}\left(j\right)$, .
3:     $\mathrm{xmu}\left({\mathbf{lxmu}}\right)$ – double array
${\mu }_{i}$, the means with ${\mu }_{i}={\mathbf{xmu}}\left(j\right)$, .
4:     $\mathrm{xstd}\left({\mathbf{lxstd}}\right)$ – double array
${\sigma }_{i}$, the standard deviations with ${\sigma }_{i}={\mathbf{xstd}}\left(j\right)$, .
Constraint: ${\mathbf{xstd}}\left(\mathit{j}\right)>0.0$, for $\mathit{j}=1,2,\dots ,{\mathbf{lxstd}}$.

Optional Input Parameters

1:     $\mathrm{ltail}$int64int32nag_int scalar
Default: the dimension of the array tail.
The length of the array tail.
Constraint: ${\mathbf{ltail}}>0$.
2:     $\mathrm{lx}$int64int32nag_int scalar
Default: the dimension of the array x.
The length of the array x.
Constraint: ${\mathbf{lx}}>0$.
3:     $\mathrm{lxmu}$int64int32nag_int scalar
Default: the dimension of the array xmu.
The length of the array xmu.
Constraint: ${\mathbf{lxmu}}>0$.
4:     $\mathrm{lxstd}$int64int32nag_int scalar
Default: the dimension of the array xstd.
The length of the array xstd.
Constraint: ${\mathbf{lxstd}}>0$.

Output Parameters

1:     $\mathrm{p}\left(:\right)$ – double array
The dimension of the array p will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{lx}},{\mathbf{ltail}},{\mathbf{lxmu}},{\mathbf{lxstd}}\right)$
${p}_{i}$, the probabilities for the Normal distribution.
2:     $\mathrm{ivalid}\left(:\right)$int64int32nag_int array
The dimension of the array ivalid will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{lx}},{\mathbf{ltail}},{\mathbf{lxmu}},{\mathbf{lxstd}}\right)$
${\mathbf{ivalid}}\left(i\right)$ indicates any errors with the input arguments, with
${\mathbf{ivalid}}\left(i\right)=0$
No error.
${\mathbf{ivalid}}\left(i\right)=1$
 On entry, invalid value supplied in tail when calculating ${p}_{i}$.
${\mathbf{ivalid}}\left(i\right)=2$
 On entry, ${\sigma }_{i}\le 0.0$.
3:     $\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:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W  ${\mathbf{ifail}}=1$
On entry, at least one value of tail or xstd was invalid.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{ltail}}>0$.
${\mathbf{ifail}}=3$
Constraint: ${\mathbf{lx}}>0$.
${\mathbf{ifail}}=4$
Constraint: ${\mathbf{lxmu}}>0$.
${\mathbf{ifail}}=5$
Constraint: ${\mathbf{lxstd}}>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

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, x, xmu and xstd are input and the probabilities calculated and printed.
```function g01sa_example

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

x    = [1.96; 1.96; 1.96; 1.96];
xmu  = [0; 0; 0; 0];
xstd = [1; 1; 1; 1];
tail = {'L'; 'U'; 'C'; 'S'};

% calculate probability
[prob, ivalid, ifail] = g01sa( ...
tail, x, xmu, xstd);

fprintf('tail    x       xmu      xstd    probability\n');
lx    = numel(x);
lxmu  = numel(xmu);
lxstd = numel(xstd);
ltail = numel(tail);
len   = max ([lx, lxmu, lxstd, ltail]);
for i=0:len-1
fprintf(' %c %8.2f %8.2f %8.2f %8.3f\n', tail{mod(i,ltail)+1}, ...
x(mod(i,lx)+1), xmu(mod(i,lxmu)+1), xstd(mod(i,lxstd)+1), prob(i+1));
end

```
```g01sa example results

tail    x       xmu      xstd    probability
L     1.96     0.00     1.00    0.975
U     1.96     0.00     1.00    0.025
C     1.96     0.00     1.00    0.950
S     1.96     0.00     1.00    0.050
```