NAG Library Routine Document

g01hbf  (prob_multi_normal)


    1  Purpose
    7  Accuracy


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


Fortran Interface
Function g01hbf ( tail, n, a, b, xmu, sig, ldsig, tol, wk, lwk, ifail)
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
C Header Interface
#include nagmk26.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)


Let the vector random variable X = X1,X2,,XnT  follow an n-dimensional multivariate Normal distribution with mean vector μ and n by n variance-covariance matrix Σ, then the probability density function, fX:μ,Σ, is given by
fX:μ,Σ = 2π - 1/2 n Σ -1/2 exp -12 X-μT Σ-1 X-μ .  
The lower tail probability is defined by:
PX1b1,,Xnbn: μ ,Σ=- b1- bnfX : μ ,Σ dXndX1.  
The upper tail probability is defined by:
The central probability is defined by:
Pa1X1b1,,anXnbn: μ ,Σ=a1b1anbnfX : μ ,Σ dXndX1.  
To evaluate the probability for n3, the probability density function of X1,X2,,Xn is considered as the product of the conditional probability of X1,X2,,Xn-2 given Xn-1 and Xn and the marginal bivariate Normal distribution of Xn-1 and Xn. 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.


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


1:     tail – Character(1)Input
On entry: indicates which probability is to be returned.
The lower tail probability is returned.
The upper tail probability is returned.
The central probability is returned.
Constraint: tail='L', 'U' or 'C'.
2:     n – IntegerInput
On entry: n, the number of dimensions.
Constraint: 1n10.
3:     an – Real (Kind=nag_wp) arrayInput
On entry: if tail='C' or 'U', the lower bounds, ai, for i=1,2,,n.
If tail='L', a is not referenced.
4:     bn – Real (Kind=nag_wp) arrayInput
On entry: if tail='C' or 'L', the upper bounds, bi, for i=1,2,,n.
If tail='U', b is not referenced.
Constraint: if tail='C', ai<bi, for i=1,2,,n.
5:     xmun – Real (Kind=nag_wp) arrayInput
On entry: μ, the mean vector of the multivariate Normal distribution.
6:     sigldsign – Real (Kind=nag_wp) arrayInput
On entry: Σ, the variance-covariance matrix of the multivariate Normal distribution. Only the lower triangle is referenced.
Constraint: Σ must be positive definite.
7:     ldsig – IntegerInput
On entry: the first dimension of the array sig as declared in the (sub)program from which g01hbf is called.
Constraint: ldsign.
8:     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: tol=0.0001.
Constraint: if n>1, tol>0.0.
9:     wklwk – Real (Kind=nag_wp) arrayWorkspace
10:   lwk – IntegerInput
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 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 αlwk/n-1, where α=2n-2+2 n-2 2+2n-2+1.
If n=1​ or ​2, wk will not be used.
Suggested value: 2000 if n>3 and 1000 if n=3.
  • if n2, lwk1;
  • if n3, lwk4×n.
11:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if ifail0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Note: g01hbf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
If on exit ifail=1, 2 or 3, then g01hbf returns zero.
On entry, ldsig=value and n=value.
Constraint: ldsign.
On entry, lwk=value.
Constraint: if n2, lwk1.
On entry, lwk=value.
Constraint: if n3, lwk4×n.
On entry, n=value.
Constraint: 1n10.
On entry, tail=value.
Constraint: tail='L', 'U' or 'C'.
On entry, tol=value.
Constraint: tol>0.0.
On entry, the value value in b is less than or equal to the corresponding value in a.
On entry, sig is not positive definite.
Full accuracy not achieved, relative accuracy =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.
Accuracy requested by tol is too strict: tol=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.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


The accuracy should be as specified by tol. When on exit ifail=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 Φ-1tol/10×n, where Φ-1 is the inverse univariate Normal distribution function.

Parallelism and Performance

g01hbf is not threaded in any implementation.

Further Comments

The time taken is related to the number of dimensions, the range over which the integration takes place (bi-ai, for i=1,2,,n) and the value of Σ 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 Xn-1 and Xn.


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

Program Text

Program Text (g01hbfe.f90)

Program Data

Program Data (g01hbfe.d)

Program Results

Program Results (g01hbfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017