Generate a random matrix with specified eigenvalues

5

In a previous post I showed how to implement Stewart's (1980) algorithm for generating random orthogonal matrices in SAS/IML software. By using the algorithm, it is easy to generate a random matrix that contains a specified set of eigenvalues.

If D = diag(λ1, ..., λp) is a diagonal matrix and Q is a pxp orthogonal matrix, then Q`DQ has eigenvalues λ1, ..., λp. Therefore if you choose Q at random, you obtain a random matrix with a given set of eigenvalues, as shown in the following statements:

proc iml;
load module=RndOrthog; /* load or define modules here */
 
start RndMatWithEigenval(lambda);
   n = ncol(lambda); /* assume lambda is row vector */
   Q = RndOrthog(n);
return( Q`*diag(lambda)*Q );
finish;
 
lambda = {2 1 0.75 0.25};
call randseed(1234);
S1 = RndMatWithEigenval(lambda); /* eigenvalues are lambda */
eval = eigval(S1);
print eval;
print S1;

If you call the function a second time, you get a different matrix with the same eigenvalues:

S2 = RndMatWithEigenval(lambda); /* eigenvalues are lambda */
print S2;

The ability to generate random matrices with specified eigenvalues is useful in simulation studies. Stewart's original motivation was to generate matrices with arbitrary condition number. The condition number of a matrix (in the two-norm) is the square root of of the ratio of the largest eigenvalue to the smallest eigenvalue. The condition number is important in numerical analysis because matrices with large condition numbers often lead to numerical instabilities in matrix computations. The algorithm implemented in this article provides a convenient way to generate matrices with an arbitrary condition number.

You can use these matrices in statistical simulations as well. If all eigenvalues are positive, then the resulting matrix is symmetric and positive definite. Therefore, it is a covariance matrix. Thus, this article shows how to create a random covariance matrix that has a specified "spectrum" or set of (positive) eigenvalues. You can use the covariance matrix to generate random multivariate normal data.

It is possible to use this procedure in an iterative method to obtain a random correlation matrix that has a specified set of eigenvalues. For a correlation matrix, the eigenvalues must sum to 1 and be positive.

Share

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.

5 Comments

  1. Hi, thanks for the explanation on how to simulate a random matrix with specified eigenvalues. I can't find the future blog post where the random matrix is transformed into a correlation matrix with the same set of eigenvalues. Is it on this webpage?

    • Rick Wicklin

      This post is almost 13 years old, so I cannot remember what I might have been thinking back then. I cannot locate a follow-up post. When I think about this problem today, the case of a correlation matrix seems harder than the covariance case. I do not see an easy way to construct a correlation matrix with a specified set of eigenvalues (which must sum to n for an nxn matrix). You cannot merely use the spectral decomposition and try to construct Q`*diag(lambda)*Q because that matrix is not likely to be a correlation matrix with 1s on the diagonal. In short, I think my statement is wrong, which is why there was no follow-up post. Sorry about that.

  2. Pingback: Generate correlation matrices with specified eigenvalues - The DO Loop

Leave A Reply

Back to Top