SBF
SBF

Reputation: 355

Computing integrals of correlated Gaussain random variables

Let (X,Y) be a 2-dimensional normal random variable with the 0 mean and the covariance matrix S. Further let Q = [0,1]x[0,1] be a unit square and let us grid it, uniformly each side with N grid points. As a result we obtain that Q is a union of N x N squares. I need to compute the marginal of (X,Y) over each such square in MATLAB, i.e. I need to compute a matrix I which elements are N x N integrals of the form

int1

where Qij is the element of the partition. The greedy way is to run two loops: over i and over j, and to compute numerically each of these integrals. However, in case when S is diagonal one can do much more efficient trick: first compute distribution of X (that would be one row vector), then the one of Y (the column vector) and finally take the Kronecker product of them, which will result in the correct matrix I.

However, in case when there is a correlation, i.e. S is not a diagonal matrix, such trick does not work. Is it necessary to run 2 loops in such case, or there is a better way?

Upvotes: 1

Views: 1401

Answers (2)

Andrew Mao
Andrew Mao

Reputation: 36900

The multivariate normal CDF is not easy to compute. However, the bivariate case is somewhat easier and more accurate than the univariate case, using what you mentioned above. There's both FORTRAN (see below) and pure Java libraries for it: http://www.iro.umontreal.ca/~simardr/ssj/indexe.html

More generally, WSU Professor (Alan Genz) has been researching how to do this and other multivariate integrals numerically since the 1980's. All of the code that others have implemented are derived from his algorithm and research. His code can compute the CDF and expectation of the multivariate normal and T distributions for dimensions up to 1000.

http://www.math.wsu.edu/faculty/genz/software/software.html

I've also written code to call those subroutines from Java: Compute the multivariate normal CDF in Java

Upvotes: 0

Pete
Pete

Reputation: 2344

No, there's no simple way to calculate the CDF of a multi-variate Normal distribution in general - see:

http://en.wikipedia.org/wiki/Multivariate_normal_distribution#Cumulative_distribution_function

If you have the MATLAB Statistics Toolbox, you can use mvncdf:

http://www.mathworks.com/help/stats/mvncdf.html

There are C/C++ versions available you might be able to MEX:

multivariate normal cdf in C, C++, or Fortran

Or, if you want to do everything in MATLAB, try integral2, which has a lot of optimizations.

Upvotes: 0

Related Questions