Hauptinhalt

wishrnd

Wishart random numbers

Description

W = wishrnd(Sigma,nu) generates a matrix of random numbers drawn from the Wishart distribution with the covariance matrix Sigma and nu degrees of freedom. The inverse of W has the inverse Wishart distribution with the covariance matrix Tau = inv(Sigma) and nu degrees of freedom.

example

[W,DOut] = wishrnd(Sigma,nu) also returns the Cholesky factor D of Sigma.

W = wishrnd(Sigma,nu,D) specifies the Cholesky factor D of Sigma, which can save computation time.

Examples

collapse all

Generate a random 3-by-3 covariance matrix Sigma that is symmetric and positive definite.

rng(0,"twister") % For reproducibility
n = 3; % Number of dimensions
A = randn(n);
Sigma = A'*A
Sigma = 3×3

    8.7546    4.0020   -7.6878
    4.0020    2.5550   -4.9440
   -7.6878   -4.9440   13.1103

Generate a matrix of random numbers from a Wishart distribution with the covariance matrix Sigma and four degrees of freedom. Compute and return the Cholesky factor D.

[W,D] = wishrnd(Sigma,4)
W = 3×3

  168.3419   72.2879  -99.5880
   72.2879   31.3271  -41.3805
  -99.5880  -41.3805   66.8992

D = 3×3

    2.9588    1.3526   -2.5983
         0    0.8518   -1.6784
         0         0    1.8820

Use the Cholesky factor D to generate another matrix of random numbers from a Wishart distribution that has the same covariance matrix and degrees of freedom.

W2 = wishrnd(Sigma,4,D)
W2 = 3×3

   42.6274   16.7668  -36.5558
   16.7668    7.7111  -17.0800
  -36.5558  -17.0800   50.8886

Input Arguments

collapse all

Covariance matrix of a Wishart distribution, specified as a d-by-d symmetric, positive definite matrix, where d is the dimension of the Wishart distribution.

Data Types: single | double

Degrees of freedom, specified as a positive scalar. If nu is noninteger, it must be larger than n – 1, where n is the dimension of Sigma.

Data Types: single | double

Cholesky factor of Sigma, specified as a numeric matrix with the same dimensions as Sigma. When you specify this argument, the software uses the value of D instead of computing it directly from Sigma.

Data Types: single | double

Output Arguments

collapse all

Wishart random numbers, returned as an array of scalar values with the same dimensions as Sigma. The expected value of W is equal to Sigma*nu.

Cholesky factor of Sigma, returned as an array of scalar values with the same dimensions as Sigma.

References

[1] Krzanowski, Wojtek J. Principles of Multivariate Analysis. NY: Oxford University Press, 1990.

[2] Smith, W. B., and R. R. Hocking. “Algorithm AS 53: Wishart Variate Generator.” Applied Statistics 21, no. 3 (1972): 341.

Version History

Introduced before R2006a