The type double function is imsls_d_multivariate_normal_cdf.
Required Arguments
intk (Input) The number of variates in the multivariate normal distribution. The number of variates must be greater than or equal to 1 and less than or equal to 1100.
floath[] (Input) Array of length k containing the upper bounds for calculating the cumulative distribution function, .
floatmean[] (Input) Array of length k containing the mean of the multivariate normal distribution, i.e., .
floatsigma[] (Input) Array of length k by k containing the positive definite symmetric variance-covariance matrix for the multivariate normal distribution, i.e., .
Return Value
The value of the cumulative distribution function for a multivariate normal random variable, .
IMSLS_ERR_ABS, floaterr_abs (Input) The absolute accuracy requested for the calculated cumulative probability.
Default: err_abs = 1.0e-3.
IMSLS_ERR_REL, floaterr_rel (Input) The relative accuracy desired.
Default: err_rel = 1.0e-5.
IMSLS_TOLERANCE, floattolerance (Input) The minimum value for the smallest eigenvalue of sigma. If the smallest eigenvalue is less than tolerance, then the terminal error IMSLS_SIGMA_SINGULAR is issued. Default: tolerance= ɛ, where ɛ is the machine precision.
IMSLS_MAX_EVALS, intmax_evals (Input) The maximum number of function evaluations allowed. If this limit is exceeded, the IMSLS_MAX_EVALS_EXCEEDED warning message is issued and the optimization terminates.
Default: max_evals = 1000×k.
IMSLS_RANDOM_SEED, intrandom_seed (Input) The value of the random seed used for generating quadrature points. By using different seeds on different calls to this function, slightly different answers will be obtained in the digits beyond the estimated error. If random_seed = 0, then the seed is set to the value of the system clock which will automatically generate slightly different answers for each call.
Default: random_seed = 7919.
IMSLS_ERR_EST, float *err_est (Output) The estimated error.
Description
Function imsls_f_multivariate_normal_cdf evaluates the cumulative distribution function F of a multivariate normal distribution with E(X1, X2, ⋯, Xk) =μ and Var(X1, X2, ⋯, Xk) =∑. The input arrays mean and sigma are used as the values for μ and ∑, respectively. The formula for the CDF calculation is given by the multiple integral described in Johnson and Kotz (1972):
∑ must be positive definite, i.e. |∑| >0.
In the special case of non-negative equal correlations (i.e. Cov(Xm, Xn) =ρ≥0, m≠n), the above integral is transformed into a univariate integral using the transformation developed by Dunnett and Sobel(1955). This produces very accurate and fast calculations even for a large number of variates.
If k>2 and the correlations are not equal or both equal and negative, the Cholesky decomposition transformation described by Genz (1992) is used (with permission from the author). This transforms the problem into a definite integral involving k-1 variables which is solved numerically using randomized Korobov rules if k≤100, see Cranley and Patterson (1976) and Keast (1973); otherwise, the integral is solved using quasi-random Richtmeyer points described in Davis and Rabinowitz (1984).
Setting σi=Var(Xi) and denoting the correlation matrix related to ∑ by W= (ρmn), where
an integral transformation transforms F(h1, h2, ⋯, hk) into the standardized k-variate normal distribution with correlation matrix W:
Therefore, it’s also possible to compute the integral with the correlation matrix W defined in argument sigma if in addition the variances σ1, ⋯, σk are known: If, with respect to the variance-covariance matrix, the bounds of the integral are h1, ⋯, hk and the means are μ1, ⋯, μk, set required argument h to h[i] = and required argument mean to mean[i] = 0 for i = 0, ⋯, k-1 .
Examples
Example 1
This example evaluates the cumulative distribution function for a trivariate normal random variable. There are three calculations. The first calculation is of F(1.96,1.96, 1.96) for a trivariate normal variable with μ = {0, 0, 0}, and
In this case, imsls_f_multivariate_normal_cdf calculates F(1.96, 1.96, 1.96) = 0.958179.
The second calculation involves a trivariate variable with the same correlation matrix as the first calculation but with a mean of μ = {0, 1, -1}. This is the same distribution as the first example shifted by the mean. The calculation of F(1.96, 2.96, 0.96) verifies that this probability is equal to the same value as reported for the first case.
The last calculation is the same calculation reported in Genz (1992) for a trivariate normal random variable with μ = {0, 0, 0} and
In this example the calculation of F(1, 4, 2) = 0.827985.
#include <imsls.h>
#include <stdio.h>
int main()
{
float bounds1[3] = {1.96, 1.96, 1.96};
float bounds2[3] = {1.96, 2.96, 0.96};
float bounds3[3] = {1.0, 4.0, 2.0};
float mean1[3] = {0.0, 0.0, 0.0};
float mean2[3] = {0.0, 1.0, -1.0};
float stdev1[9] = {1.0, 0.9, 0.9,
0.9, 1.0, 0.9,
0.9, 0.9, 1.0};
float stdev2[9] = {1.0, 0.6, 1.0/3.0,
0.6, 1.0, 11.0/15.0,
1.0/3.0, 11.0/15.0, 1.0};
float f;
char *fmt = {"%5.3W"};
imsls_f_write_matrix("Mean Vector", 1, 3, mean1,
IMSLS_NO_ROW_LABELS,
IMSLS_NO_COL_LABELS,
IMSLS_WRITE_FORMAT, fmt,
0);
imsls_f_write_matrix("Correlation Matrix", 3, 3,
stdev1, IMSLS_NO_ROW_LABELS,
IMSLS_NO_COL_LABELS,
IMSLS_WRITE_FORMAT, fmt,
0);
f = imsls_f_multivariate_normal_cdf(3, bounds1, mean1,
This example illustrates the calculation of the cdf for a multivariate normal distribution with a mean of μ = {1, 0, -1, 0, 1, -1}, and a correlation matrix of
The optional argument IMSLS_PRINT is used to illustrate the type of intermediate output available from this function. This function sorts the variables by the limits for the cdf calculation specified in x. This improves the accuracy of the calculations, see Genz (1992). In this case, F(X1<1, X2< 2.5, X3< 2, X4< 0.5, X5< 0, X6< 0.8) = 0.087237 with an estimated error of 8.7e-05.
By increasing the correlation of X2 and X3 from 0.1 to 0.7, the correlation matrix becomes singular. This function checks for this condition and issues an error when sigma is not symmetric or positive definite.
#include <imsls.h>
#include <stdio.h>
int main()
{
float bounds[6] = {1.0, 2.5, 2.0, 0.5, 0.0, 0.8};
float mean[6] = {1.0, 0.0, -1.0, 0.0, 1.0, -1.0};
float s1[6*6] = {1.0, 0.1, 0.2, 0.3, 0.4, 0.0,
0.1, 1.0, 0.6, 0.1, 0.2, 0.5,
0.2, 0.6, 1.0, 0.0, 0.1, 0.2,
0.3, 0.1, 0.0, 1.0, 0.0, 0.5,
0.4, 0.2, 0.1, 0.0, 1.0, 0.3,
0.0, 0.5, 0.2, 0.5, 0.3, 1.0};
/* The following matrix is not positive definite */
float s2[6*6] = {1.0, 0.1, 0.2, 0.3, 0.4, 0.0,
0.1, 1.0, 0.6, 0.7, 0.2, 0.5,
0.2, 0.6, 1.0, 0.0, 0.1, 0.2,
0.3, 0.7, 0.0, 1.0, 0.0, 0.5,
0.4, 0.2, 0.1, 0.0, 1.0, 0.3,
0.0, 0.5, 0.2, 0.5, 0.3, 1.0};
float f, err;
int i, k=6;
f = imsls_f_multivariate_normal_cdf(k, bounds, mean, s1,
IMSLS_PRINT,
IMSLS_ERR_EST, &err,
0);
printf("F(X1<%2.1f, X2<%2.1f, X3<%2.1f, ",
bounds[0], bounds[1], bounds[2]);
printf("X4<%2.1f, X5<%2.1f, X6<%2.1f) = %f\n",
bounds[3], bounds[4], bounds[5], f);
printf("Estimated Error = %g\n", err);
/* example of error message when sigma is not positive definite */
f = imsls_f_multivariate_normal_cdf(k, bounds, mean, s2,