These packages are archived in zip format. All code is available in the public domain under the GPL unless otherwise noted.

Generating Uniform Random Vectors Given Correlation Matrix

This Matlab code generates uniform random vectors while "closely" matching a given correlation matrix. The generation procedure used is the NORTA method (Normal to anything), which is essentially a Gaussian copula. It is known that NORTA cannot exactly match all correlation matrices. This code augments the usual NORTA procedure to deal with this problem. The augmentation ensures that the correlation matrix of the generated vectors is exactly the desired one in many cases, but if that is not possible, then the correlation matrix will be "close" to the desired one. The augmentation can be done in many ways. The code provides a menu of four different heuristics, three of which solve a semi-definite problem (and will need the LMI toolbox installed within Matlab) while the last one is a heuristic that provides a good feasible solution without solving a semi-definite program, and is thus recommended. For full details of why this problem occurs, and the various heuristics for dealing with them, please see Soumyadip Ghosh's thesis. Some aspects of the problem are also discussed in the references below.

The same code can be used to generate samples for general random marginals (exponentials etc.) if one aims to match rank correlations instead of product moment correlations, and uses continuous marginals. The desired rank correlation matrix is used as the input uniform vector correlation matrix, and the generated uniform vector sample is passed through a final step where each component is transformed by the appropriate inverse of the desired marginal distribution. Restricting to continuous marginal distributions ensures that the final transformation step preserves the rank correlation values. For discrete marginals, the final rank correlations will be close, but not exact.

Generating Matrices Uniformly from Space of P.S.D. Matrices

This Matlab code illustrates and implements how matrices can be generated uniformly from the space of all n-dimensional matrices that are positive semi-definite and have the a pre-selected set of diagonal values. The simplest case is where all diagonals equal 1, i.e., the set of all n-dimensional matrices that are commonly referred to as correlation matrices. An exact definition of this space and the details of this algorithm can be found in