Sample the Wishart Distribution for Random Covariance Matrices

WISHART is a C++ library which produces sample matrices from the Wishart or Bartlett distributions, useful for sampling random covariance matrices.

The Wishart distribution is a probability distribution for random nonnegative-definite NxN matrices that can be used to select random covariance matrices.

The objects of the distribution are NxN matrices which are the sum of DF rank-one matrices X*X' constructed from N-vectors X, where the vectors X have zero mean and covariance SIGMA. This implies that the expected value of a Wishart matrix is DF * SIGMA.

A simplified version of the Wishart distribution assumes that SIGMA is the identity matrix. We will call this the "unit Wishart distribution".

Because any Wishart matrix W is symmetric nonnegative definite, there is an upper triangular factor T so that W = T' * T. There is a corresponding Bartlett distribution of the matrices T, so that one can alternatively sample the Bartlett distribution by sampling the Bartlett distribution for T, and then forming W.

In order to generate the necessary random values, the library relies on the PDFLIB and RNGLIB libraries.


The computer code and data files made available on this web page are distributed under the GNU LGPL license.


WISHART is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

ASA053, a C++ library which produces sample matrices from the Wishart distribution, by William Smith and Ronald Hocking. This is a version of Applied Statistics Algorithm 53.

PDFLIB, a C++ library which evaluates Probability Density Functions (PDF's) and produces random samples from them, including beta, binomial, chi, exponential, gamma, inverse chi, inverse gamma, multinomial, normal, scaled inverse chi, and uniform.

RANLIB, a C++ library which produces random samples from Probability Density Functions (PDF's), including Beta, Chi-square Exponential, F, Gamma, Multivariate normal, Noncentral chi-square, Noncentral F, Univariate normal, random permutations, Real uniform, Binomial, Negative Binomial, Multinomial, Poisson and Integer uniform, by Barry Brown and James Lovato.

RNGLIB, a C++ library which implements a random number generator (RNG) with splitting facilities, allowing multiple independent streams to be computed, by L'Ecuyer and Cote.


Source Code:

Examples and Tests:

List of Routines:

You can go up one level to the C++ source codes.

Last revised on 02 August 2013.