NAG FL Interfaceg01hbf (prob_​multi_​normal)

▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

1Purpose

g01hbf returns the upper tail, lower tail or central probability associated with a multivariate Normal distribution of up to ten dimensions.

2Specification

Fortran Interface
 Function g01hbf ( tail, n, a, b, xmu, sig, tol, wk, lwk,
 Real (Kind=nag_wp) :: g01hbf Integer, Intent (In) :: n, ldsig, lwk Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: a(n), b(n), xmu(n), sig(ldsig,n), tol Real (Kind=nag_wp), Intent (Out) :: wk(lwk) Character (1), Intent (In) :: tail
#include <nag.h>
 double g01hbf_ (const char *tail, const Integer *n, const double a[], const double b[], const double xmu[], const double sig[], const Integer *ldsig, const double *tol, double wk[], const Integer *lwk, Integer *ifail, const Charlen length_tail)
The routine may be called by the names g01hbf or nagf_stat_prob_multi_normal.

3Description

Let the vector random variable $X={\left({X}_{1},{X}_{2},\dots ,{X}_{n}\right)}^{\mathrm{T}}$ follow an $n$-dimensional multivariate Normal distribution with mean vector $\mu$ and $n×n$ variance-covariance matrix $\Sigma$, then the probability density function, $f\left(X:\mu ,\Sigma \right)$, is given by
 $f(X:μ,Σ) = (2π) - (1/2) n |Σ| -1/2 exp(-12(X-μ)TΣ-1(X-μ)) .$
The lower tail probability is defined by:
 $P(X1≤b1,…,Xn≤bn: μ ,Σ)=∫-∞ b1⋯∫-∞ bnf(X : μ ,Σ) dXn⋯dX1.$
The upper tail probability is defined by:
 $P(X1≥a1,…,Xn≥an:μ,Σ)=∫a1∞⋯∫an∞f(X:μ,Σ)dXn⋯dX1.$
The central probability is defined by:
 $P(a1≤X1≤b1,…,an≤Xn≤bn: μ ,Σ)=∫a1b1⋯∫anbnf(X : μ ,Σ) dXn⋯dX1.$
To evaluate the probability for $n\ge 3$, the probability density function of ${X}_{1},{X}_{2},\dots ,{X}_{n}$ is considered as the product of the conditional probability of ${X}_{1},{X}_{2},\dots ,{X}_{n-2}$ given ${X}_{n-1}$ and ${X}_{n}$ and the marginal bivariate Normal distribution of ${X}_{n-1}$ and ${X}_{n}$. The bivariate Normal probability can be evaluated as described in g01haf and numerical integration is then used over the remaining $n-2$ dimensions. In the case of $n=3$, d01ajf is used and for $n>3$ d01fcf is used.
To evaluate the probability for $n=1$ a direct call to g01eaf is made and for $n=2$ calls to g01haf are made.

4References

Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin

5Arguments

1: $\mathbf{tail}$Character(1) Input
On entry: indicates which probability is to be returned.
${\mathbf{tail}}=\text{'L'}$
The lower tail probability is returned.
${\mathbf{tail}}=\text{'U'}$
The upper tail probability is returned.
${\mathbf{tail}}=\text{'C'}$
The central probability is returned.
Constraint: ${\mathbf{tail}}=\text{'L'}$, $\text{'U'}$ or $\text{'C'}$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of dimensions.
Constraint: $1\le {\mathbf{n}}\le 10$.
3: $\mathbf{a}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: if ${\mathbf{tail}}=\text{'C'}$ or $\text{'U'}$, the lower bounds, ${a}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{tail}}=\text{'L'}$, a is not referenced.
4: $\mathbf{b}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: if ${\mathbf{tail}}=\text{'C'}$ or $\text{'L'}$, the upper bounds, ${b}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{tail}}=\text{'U'}$, b is not referenced.
Constraint: if ${\mathbf{tail}}=\text{'C'}$, ${\mathbf{a}}\left(\mathit{i}\right)<{\mathbf{b}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,n$.
5: $\mathbf{xmu}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
6: $\mathbf{sig}\left({\mathbf{ldsig}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: $\Sigma$, the variance-covariance matrix of the multivariate Normal distribution. Only the lower triangle is referenced.
Constraint: $\Sigma$ must be positive definite.
7: $\mathbf{ldsig}$Integer Input
On entry: the first dimension of the array sig as declared in the (sub)program from which g01hbf is called.
Constraint: ${\mathbf{ldsig}}\ge {\mathbf{n}}$.
8: $\mathbf{tol}$Real (Kind=nag_wp) Input
On entry: if $n>2$ the relative accuracy required for the probability, and if the upper or the lower tail probability is requested then tol is also used to determine the cut-off points, see Section 7.
If $n=1$, tol is not referenced.
Suggested value: ${\mathbf{tol}}=0.0001$.
Constraint: if ${\mathbf{n}}>1$, ${\mathbf{tol}}>0.0$.
9: $\mathbf{wk}\left({\mathbf{lwk}}\right)$Real (Kind=nag_wp) array Workspace
10: $\mathbf{lwk}$Integer Input
On entry: the length of workspace provided in array wk. This workspace is used by the numerical integration routines d01ajf for $n=3$ and d01fcf for $n>3$.
If $n=3$, the maximum number of sub-intervals used by d01ajf is ${\mathbf{lwk}}/4$. Note, however, increasing lwk above $1000$ will not increase the maximum number of sub-intervals above $250$.
If $n>3$ the maximum number of integrand evaluations used by d01fcf is $\alpha \left({\mathbf{lwk}}/n-1\right)$, where $\alpha ={2}^{n-2}+2{\left(n-2\right)}^{2}+2\left(n-2\right)+1$.
If $n=1$ or $2$, wk will not be used.
Suggested value: $2000$ if $n>3$ and $1000$ if $n=3$.
Constraints:
• if ${\mathbf{n}}\le 2$, ${\mathbf{lwk}}\ge 1$;
• if ${\mathbf{n}}\ge 3$, ${\mathbf{lwk}}\ge 4×{\mathbf{n}}$.
11: $\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 $-1$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. 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:
Note: in some cases g01hbf may return useful information.
If on exit ${\mathbf{ifail}}={\mathbf{1}}$, ${\mathbf{2}}$ or ${\mathbf{3}}$, then g01hbf returns zero.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ldsig}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldsig}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{lwk}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{n}}\le 2$, ${\mathbf{lwk}}\ge 1$.
On entry, ${\mathbf{lwk}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{n}}\ge 3$, ${\mathbf{lwk}}\ge 4×{\mathbf{n}}$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{n}}\le 10$.
On entry, ${\mathbf{tail}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{tail}}=\text{'L'}$, $\text{'U'}$ or $\text{'C'}$.
On entry, ${\mathbf{tol}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{tol}}>0.0$.
${\mathbf{ifail}}=2$
On entry, the $⟨\mathit{\text{value}}⟩$ value in b is less than or equal to the corresponding value in a.
${\mathbf{ifail}}=3$
On entry, sig is not positive definite.
${\mathbf{ifail}}=4$
Full accuracy not achieved, relative accuracy $\text{}=⟨\mathit{\text{value}}⟩$. A larger value of tol can be tried or the length of the workspace increased. The returned value is an approximation to the required result.
${\mathbf{ifail}}=5$
Accuracy requested by tol is too strict: ${\mathbf{tol}}=⟨\mathit{\text{value}}⟩$. Round-off error has prevented the requested accuracy from being achieved; a larger value of tol can be tried. The returned value will be an approximation to the required result.
${\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 should be as specified by tol. When on exit ${\mathbf{ifail}}={\mathbf{4}}$ the approximate accuracy achieved is given in the error message. For the upper and lower tail probabilities the infinite limits are approximated by cut-off points for the $n-2$ dimensions over which the numerical integration takes place; these cut-off points are given by ${\Phi }^{-1}\left({\mathbf{tol}}/\left(10×n\right)\right)$, where ${\Phi }^{-1}$ is the inverse univariate Normal distribution function.

8Parallelism and Performance

g01hbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g01hbf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The time taken is related to the number of dimensions, the range over which the integration takes place (${b}_{i}-{a}_{i}$, for $\mathit{i}=1,2,\dots ,n$) and the value of $\Sigma$ as well as the accuracy required. As the numerical integration does not take place over the last two dimensions speed may be improved by arranging $X$ so that the largest ranges of integration are for ${X}_{n-1}$ and ${X}_{n}$.

10Example

This example reads in the mean and covariance matrix for a multivariate Normal distribution and computes and prints the associated central probability.

10.1Program Text

Program Text (g01hbfe.f90)

10.2Program Data

Program Data (g01hbfe.d)

10.3Program Results

Program Results (g01hbfe.r)