hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_inv_cdf_normal_vector (g01ta)

Purpose

nag_stat_inv_cdf_normal_vector (g01ta) returns a number of deviates associated with given probabilities of the Normal distribution.

Syntax

[x, ivalid, ifail] = g01ta(tail, p, xmu, xstd, 'ltail', ltail, 'lp', lp, 'lxmu', lxmu, 'lxstd', lxstd)
[x, ivalid, ifail] = nag_stat_inv_cdf_normal_vector(tail, p, xmu, xstd, 'ltail', ltail, 'lp', lp, 'lxmu', lxmu, 'lxstd', lxstd)

Description

The deviate, xpixpi associated with the lower tail probability, pipi, for the Normal distribution is defined as the solution to
xpi
P(Xixpi) = pi = Zi(Xi)dXi,
P(Xixpi)=pi=-xpiZi(Xi)dXi,
where
Zi(Xi) = 1/(sqrt(2πσi2))e(Xiμi)2 / (2σi2), ​ < Xi < .
Zi(Xi)=12πσi2e-(Xi-μi)2/(2σi2), ​-<Xi< .
The method used is an extension of that of Wichura (1988). pipi is first replaced by qi = pi0.5qi=pi-0.5.
(a) If |qi|0.3|qi|0.3, zizi is computed by a rational Chebyshev approximation
zi = si(Ai(si2))/(Bi(si2)),
zi=siAi(si2) Bi(si2) ,
where si = sqrt(2π)qisi=2πqi and AiAi, BiBi are polynomials of degree 77.
(b) If 0.3 < |qi|0.420.3<|qi|0.42, zizi is computed by a rational Chebyshev approximation
zi = signqi ((Ci(ti))/(Di(ti))) ,
zi=signqi (Ci(ti) Di(ti) ) ,
where ti = |qi|0.3ti=|qi|-0.3 and CiCi, DiDi are polynomials of degree 55.
(c) If |qi| > 0.42|qi|>0.42, zizi is computed as
zi = signqi [((Ei(ui))/(Fi(ui))) + ui] ,
zi=signqi [ (Ei(ui) Fi(ui) )+ui] ,
where ui = sqrt( 2 × log(min (pi,1pi)) ) ui = -2 × log( min(pi,1-pi) )  and EiEi, FiFi are polynomials of degree 66.
xpixpi is then calculated from zizi, using the relationsship zpi = ( xi μi )/(σi) zpi = xi - μi σi .
For the upper tail probability xpi-xpi is returned, while for the two tail probabilities the value xipi*xipi* is returned, where pi*pi* is the required tail probability computed from the input value of pipi.
The input arrays to this function are designed to allow maximum flexibility in the supply of vector parameters by re-using elements of any arrays that are shorter than the total number of evaluations required. See Section [Vectorized s] 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
Wichura (1988) Algorithm AS 241: the percentage points of the Normal distribution Appl. Statist. 37 477–484

Parameters

Compulsory Input Parameters

1:     tail(ltail) – cell array of strings
ltail, the dimension of the array, must satisfy the constraint ltail > 0ltail>0.
Indicates which tail the supplied probabilities represent. Letting ZZ denote a variate from a standard Normal distribution, and zi = ( xpi μi )/(σi) zi = xpi - μi σi , then for j = ((i1)  mod  ltail) + 1 j= ( (i-1) mod ltail ) +1 , for i = 1,2,,max (ltail,lp,lxmu,lxstd)i=1,2,,max(ltail,lp,lxmu,lxstd):
tail(j) = 'L'tailj='L'
The lower tail probability, i.e., pi = P(Zzi)pi=P(Zzi).
tail(j) = 'U'tailj='U'
The upper tail probability, i.e., pi = P(Zzi)pi=P(Zzi).
tail(j) = 'C'tailj='C'
The two tail (confidence interval) probability, i.e., pi = P(Z|zi|)P(Z|zi|)pi=P(Z|zi|)-P(Z-|zi|).
tail(j) = 'S'tailj='S'
The two tail (significance level) probability, i.e., pi = P(Z|zi|) + P(Z|zi|)pi=P(Z|zi|)+P(Z-|zi|).
Constraint: tail(j) = 'L'tailj='L', 'U''U', 'C''C' or 'S''S', for j = 1,2,,ltailj=1,2,,ltail.
2:     p(lp) – double array
lp, the dimension of the array, must satisfy the constraint lp > 0lp>0.
pipi, the probabilities for the Normal distribution as defined by tail with pi = p(j)pi=pj, j = (i1)  mod  lp + 1j=(i-1) mod lp+1.
Constraint: 0.0 < p(j) < 1.00.0<pj<1.0, for j = 1,2,,lpj=1,2,,lp.
3:     xmu(lxmu) – double array
lxmu, the dimension of the array, must satisfy the constraint lxmu > 0lxmu>0.
μiμi, the means with μi = xmu(j)μi=xmuj, j = ((i1)  mod  lxmu) + 1j=((i-1) mod lxmu)+1.
4:     xstd(lxstd) – double array
lxstd, the dimension of the array, must satisfy the constraint lxstd > 0lxstd>0.
σiσi, the standard deviations with σi = xstd(j)σi=xstdj, j = ((i1)  mod  lxstd) + 1j=((i-1) mod lxstd)+1.
Constraint: xstd(j) > 0.0xstdj>0.0, for j = 1,2,,lxstdj=1,2,,lxstd.

Optional Input Parameters

1:     ltail – int64int32nag_int scalar
Default: The dimension of the array tail.
The length of the array tail.
Constraint: ltail > 0ltail>0.
2:     lp – int64int32nag_int scalar
Default: The dimension of the array p.
The length of the array p.
Constraint: lp > 0lp>0.
3:     lxmu – int64int32nag_int scalar
Default: The dimension of the array xmu.
The length of the array xmu.
Constraint: lxmu > 0lxmu>0.
4:     lxstd – int64int32nag_int scalar
Default: The dimension of the array xstd.
The length of the array xstd.
Constraint: lxstd > 0lxstd>0.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     x( : :) – double array
Note: the dimension of the array x must be at least max (ltail,lxmu,lxstd,lp)max(ltail,lxmu,lxstd,lp).
xpixpi, the deviates for the Normal distribution.
2:     ivalid( : :) – int64int32nag_int array
Note: the dimension of the array ivalid must be at least max (ltail,lxmu,lxstd,lp)max(ltail,lxmu,lxstd,lp).
ivalid(i)ivalidi indicates any errors with the input arguments, with
ivalid(i) = 0ivalidi=0
No error.
ivalid(i) = 1ivalidi=1
On entry,invalid value supplied in tail when calculating xpixpi.
ivalid(i) = 2ivalidi=2
On entry,pi0.0pi0.0,
orpi1.0pi1.0.
ivalid(i) = 3ivalidi=3
On entry,σi0.0σi0.0.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 ifail = 1ifail=1
On entry, at least one value of tail, xstd or p was invalid.
Check ivalid for more information.
  ifail = 2ifail=2
Constraint: ltail > 0ltail>0.
  ifail = 3ifail=3
Constraint: lp > 0lp>0.
  ifail = 4ifail=4
Constraint: lxmu > 0lxmu>0.
  ifail = 5ifail=5
Constraint: lxstd > 0lxstd>0.
  ifail = 999ifail=-999
Dynamic memory allocation failed.

Accuracy

The accuracy is mainly limited by the machine precision.

Further Comments

None.

Example

function nag_stat_inv_cdf_normal_vector_example
p = [0.9750; 0.0250; 0.9500; 0.0500];
xmu = [0; 0; 0; 0];
xstd = [1; 1; 1; 1];
tail = {'L'; 'U'; 'C'; 'S'};
[dev, ivalid, ifail] = nag_stat_inv_cdf_normal_vector(tail, p, xmu, xstd);

fprintf('\nTail    P              XMU      XSTD      Deviate\n');
lp = numel(p);
lxmu = numel(xmu);
lxstd = numel(xstd);
ltail = numel(tail);
len = max ([lp, lxmu, lxstd, ltail]);
for i=0:len-1
 fprintf(' %c%11.3f%16.4f%8.3f%13.6f%11d\n', tail{mod(i,ltail)+1}, p(mod(i,lp)+1), ...
         xmu(mod(i,lxmu)+1), xstd(mod(i,lxstd)+1), dev(i+1),  ivalid(i+1));
end
 

Tail    P              XMU      XSTD      Deviate
 L      0.975          0.0000   1.000     1.959964          0
 U      0.025          0.0000   1.000     1.959964          0
 C      0.950          0.0000   1.000     1.959964          0
 S      0.050          0.0000   1.000     1.959964          0

function g01ta_example
p = [0.9750; 0.0250; 0.9500; 0.0500];
xmu = [0; 0; 0; 0];
xstd = [1; 1; 1; 1];
tail = {'L'; 'U'; 'C'; 'S'};
[dev, ivalid, ifail] = g01ta(tail, p, xmu, xstd);

fprintf('\nTail    P              XMU      XSTD      Deviate\n');
lp = numel(p);
lxmu = numel(xmu);
lxstd = numel(xstd);
ltail = numel(tail);
len = max ([lp, lxmu, lxstd, ltail]);
for i=0:len-1
 fprintf(' %c%11.3f%16.4f%8.3f%13.6f%11d\n', tail{mod(i,ltail)+1}, p(mod(i,lp)+1), ...
         xmu(mod(i,lxmu)+1), xstd(mod(i,lxstd)+1), dev(i+1),  ivalid(i+1));
end
 

Tail    P              XMU      XSTD      Deviate
 L      0.975          0.0000   1.000     1.959964          0
 U      0.025          0.0000   1.000     1.959964          0
 C      0.950          0.0000   1.000     1.959964          0
 S      0.050          0.0000   1.000     1.959964          0


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013