# WISHART Sample the Wishart Distribution for Random Covariance Matrices

WISHART is a FORTRAN77 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.

### Licensing:

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

### 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 FORTRAN77 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 FORTRAN77 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 FORTRAN77 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 FORTRAN77 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.
• R8_EPSILON returns the R8 roundoff unit.
• R8MAT_CHOLESKY_FACTOR_UPPER: upper Cholesky factor of a symmetric matrix.
• R8MAT_COPY copies an R8MAT.
• R8MAT_DIAG_GET_VECTOR gets the value of the diagonal of an R8MAT.
• R8MAT_DIAGONAL returns a diagonal matrix as an R8MAT.
• R8MAT_IDENTITY stores the identity matrix in an R8MAT.
• R8MAT_MM multiplies two R8MAT's.
• R8MAT_MTM multiplies computes C = A' * B for two R8MAT's.
• 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.
• R8UT_INVERSE computes the inverse of an R8UT matrix.
• R8VEC_PRINT prints an R8VEC.
• TIMESTAMP prints out the current YMDHMS date as a timestamp.
• 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 FORTRAN77 source codes.

Last revised on 10 October 2013.