# NAG FL Interfaceg01lbf (pdf_​multi_​normal_​vector)

## 1Purpose

g01lbf returns a number of values of the probability density function (PDF), or its logarithm, for the multivariate Normal (Gaussian) distribution.

## 2Specification

Fortran Interface
 Subroutine g01lbf ( ilog, k, n, x, ldx, xmu, iuld, sig, pdf, rank,
 Integer, Intent (In) :: ilog, k, n, ldx, iuld, ldsig Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: rank Real (Kind=nag_wp), Intent (In) :: x(ldx,*), xmu(n), sig(ldsig,*) Real (Kind=nag_wp), Intent (Out) :: pdf(k)
#include <nag.h>
 void g01lbf_ (const Integer *ilog, const Integer *k, const Integer *n, const double x[], const Integer *ldx, const double xmu[], const Integer *iuld, const double sig[], const Integer *ldsig, double pdf[], Integer *rank, Integer *ifail)
The routine may be called by the names g01lbf or nagf_stat_pdf_multi_normal_vector.

## 3Description

The probability density function, $f\left(X:\mu ,\Sigma \right)$ of an $n$-dimensional multivariate Normal distribution with mean vector $\mu$ and $n$ by $n$ variance-covariance matrix $\Sigma$, is given by
 $fX:μ,Σ = 2⁢π n ⁢ Σ -1/2 ⁢ exp -12 ⁢ X-μT ⁢ Σ-1 ⁢ X-μ .$
If the variance-covariance matrix, $\Sigma$, is not of full rank then the probability density function, is calculated as
 $fX:μ,Σ = 2⁢π r ⁢ pdet Σ -1/2 ⁢ exp -12 ⁢ X-μT ⁢ Σ- ⁢ X-μ$
where $\text{pdet}\left(\Sigma \right)$ is the pseudo-determinant, ${\Sigma }^{-}$ a generalized inverse of $\Sigma$ and $r$ its rank.
g01lbf evaluates the PDF at $k$ points with a single call.

None.

## 5Arguments

1: $\mathbf{ilog}$Integer Input
On entry: the value of ilog determines whether the logarithmic value is returned in PDF.
${\mathbf{ilog}}=0$
$f\left(X:\mu ,\Sigma \right)$, the probability density function is returned.
${\mathbf{ilog}}=1$
$\mathrm{log}\left(f\left(X:\mu ,\Sigma \right)\right)$, the logarithm of the probability density function is returned.
Constraint: ${\mathbf{ilog}}=0$ or $1$.
2: $\mathbf{k}$Integer Input
On entry: $k$, the number of points the PDF is to be evaluated at.
Constraint: ${\mathbf{k}}\ge 0$.
3: $\mathbf{n}$Integer Input
On entry: $n$, the number of dimensions.
Constraint: ${\mathbf{n}}\ge 2$.
4: $\mathbf{x}\left({\mathbf{ldx}},*\right)$Real (Kind=nag_wp) array Input
Note: the second dimension of the array x must be at least ${\mathbf{k}}$.
On entry: $X$, the matrix of $k$ points at which to evaluate the probability density function, with the $i$th dimension for the $j$th point held in ${\mathbf{x}}\left(i,j\right)$.
5: $\mathbf{ldx}$Integer Input
On entry: the first dimension of the array x as declared in the (sub)program from which g01lbf is called.
Constraint: ${\mathbf{ldx}}\ge {\mathbf{n}}$.
6: $\mathbf{xmu}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
7: $\mathbf{iuld}$Integer Input
On entry: indicates the form of $\Sigma$ and how it is stored in sig.
${\mathbf{iuld}}=1$
sig holds the lower triangular portion of $\Sigma$.
${\mathbf{iuld}}=2$
sig holds the upper triangular portion of $\Sigma$.
${\mathbf{iuld}}=3$
$\Sigma$ is a diagonal matrix and sig only holds the diagonal elements.
${\mathbf{iuld}}=4$
sig holds the lower Cholesky decomposition, $L$ such that $L{L}^{\mathrm{T}}=\Sigma$.
${\mathbf{iuld}}=5$
sig holds the upper Cholesky decomposition, $U$ such that ${U}^{\mathrm{T}}U=\Sigma$.
Constraint: ${\mathbf{iuld}}=1$, $2$, $3$, $4$ or $5$.
8: $\mathbf{sig}\left({\mathbf{ldsig}},*\right)$Real (Kind=nag_wp) array Input
Note: the second dimension of the array sig must be at least ${\mathbf{n}}$.
On entry: information defining the variance-covariance matrix, $\Sigma$.
${\mathbf{iuld}}=1$ or $2$
sig must hold the lower or upper portion of $\Sigma$, with ${\Sigma }_{ij}$ held in ${\mathbf{sig}}\left(i,j\right)$. The supplied variance-covariance matrix must be positive semidefinite.
${\mathbf{iuld}}=3$
$\Sigma$ is a diagonal matrix and the $i$th diagonal element, ${\Sigma }_{ii}$, must be held in ${\mathbf{sig}}\left(1,i\right)$
${\mathbf{iuld}}=4$ or $5$
sig must hold $L$ or $U$, the lower or upper Cholesky decomposition of $\Sigma$, with ${L}_{ij}$ or ${U}_{ij}$ held in ${\mathbf{sig}}\left(i,j\right)$, depending on the value of iuld. No check is made that $L{L}^{\mathrm{T}}$ or ${U}^{\mathrm{T}}U$ is a valid variance-covariance matrix. The diagonal elements of the supplied $L$ or $U$ must be greater than zero
9: $\mathbf{ldsig}$Integer Input
On entry: the first dimension of the array sig as declared in the (sub)program from which g01lbf is called.
Constraints:
• if ${\mathbf{iuld}}=3$, ${\mathbf{ldsig}}\ge 1$;
• otherwise ${\mathbf{ldsig}}\ge {\mathbf{n}}$.
10: $\mathbf{pdf}\left({\mathbf{k}}\right)$Real (Kind=nag_wp) array Output
On exit: $f\left(X:\mu ,\Sigma \right)$ or $\mathrm{log}\left(f\left(X:\mu ,\Sigma \right)\right)$ depending on the value of ilog.
11: $\mathbf{rank}$Integer Output
On exit: $r$, rank of $\Sigma$.
12: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value 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:
${\mathbf{ifail}}=11$
On entry, ${\mathbf{ilog}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ilog}}=0$ or $1$.
${\mathbf{ifail}}=21$
On entry, ${\mathbf{k}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{k}}\ge 0$.
${\mathbf{ifail}}=31$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 2$.
${\mathbf{ifail}}=51$
On entry, ${\mathbf{ldx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldx}}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=71$
On entry, ${\mathbf{iuld}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{iuld}}=1$, $2$, $3$, $4$ or $5$.
${\mathbf{ifail}}=81$
On entry, $\Sigma$ is not positive semidefinite.
${\mathbf{ifail}}=82$
On entry, at least one diagonal element of $\Sigma$ is less than or equal to $0$.
${\mathbf{ifail}}=83$
On entry, $\Sigma$ is not positive definite and eigenvalue decomposition failed.
${\mathbf{ifail}}=91$
On entry, ${\mathbf{ldsig}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{iuld}}=3$, ${\mathbf{ldsig}}\ge 1$.
${\mathbf{ifail}}=92$
On entry, ${\mathbf{ldsig}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{iuld}}\ne 3$, ${\mathbf{ldsig}}\ge {\mathbf{n}}$.
${\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.

Not applicable.

## 8Parallelism and Performance

g01lbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g01lbf 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.

None.

## 10Example

This example prints the value of the multivariate Normal PDF at a number of different points.

### 10.1Program Text

Program Text (g01lbfe.f90)

### 10.2Program Data

Program Data (g01lbfe.d)

### 10.3Program Results

Program Results (g01lbfe.r)