# WISHART 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.

### Languages:

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.

### Reference:

• Patrick Odell, Alan Feiveson,
A numerical procedure to generate a sample covariance matrix,
Journal of the American Statistical Association,
Volume 61, Number 313, March 1966, pages 199-203.
• Stanley Sawyer,
Wishart Distributions and Inverse-Wishart Sampling,
Washington University,
30 April 2007, 12 pages.

### List of Routines:

• BARTLETT_SAMPLE samples the Bartlett distribution.
• BARTLETT_UNIT_SAMPLE samples the unit Bartlett distribution.
• JACOBI_EIGENVALUE carries out the Jacobi eigenvalue iteration.
• R8MAT_CHOLESKY_FACTOR_UPPER: upper Cholesky factor of a symmetric R8MAT.
• R8MAT_COPY_NEW copies one R8MAT to a "new" R8MAT.
• R8MAT_DIAG_GET_VECTOR gets the value of the diagonal of an R8MAT.
• R8MAT_DIAGONAL_NEW returns a diagonal matrix.
• R8MAT_DIVIDE divides an R8MAT by a scalar.
• R8MAT_IDENTITY sets an R8MAT to the identity matrix.
• R8MAT_IDENTITY_NEW returns an identity matrix.
• R8MAT_MM_NEW multiplies two matrices.
• R8MAT_MMT_NEW computes C = A * B'.
• R8MAT_MTM_NEW computes C = A' * B.
• R8MAT_NORM_FRO_AFFINE returns the Frobenius norm of an R8MAT difference.
• R8MAT_PRINT prints an R8MAT.
• R8MAT_PRINT_SOME prints some of an R8MAT.
• R8MAT_ZERO_NEW returns a new zeroed R8MAT.
• R8UT_INVERSE computes the inverse of a R8UT matrix.
• R8VEC_PRINT prints an R8VEC.
• WISHART_SAMPLE samples the Wishart distribution.
• WISHART_SAMPLE_INVERSE returns the inverse of a sample Wishart matrix.
• WISHART_UNIT_SAMPLE samples the unit Wishart distribution.
• WISHART_UNIT_SAMPLE_INVERSE inverts a unit Wishart sample matrix.

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

Last revised on 11 October 2013.