2
$\begingroup$

How can I generate a random matrix $\mathbf{M}$ such that $\operatorname{cov}(\mathbf{M}) = \mathbf{I}$ (identity). I use matlab to generate $\mathbf{M}$.

$\endgroup$
  • $\begingroup$ mvrnd(zeros(d), eye(d)) $\endgroup$ – valtron Jan 21 '13 at 16:32
3
$\begingroup$

Hmm, I don't have matlab, but a sequence of my MatMatecode might be translatable:

n=1000    // 1000 cases
v=10      // 10 variables

data = randomn(v,n,0,2)   // generate random data of stddev 2,mean=0
                          // this shall have some random-correlation

c1=data *' / n            // covariance-matrix of the data
t1=gettrans(c1 ,"pca")'   // this mimicks SVD-decomposition; the matrix t1 is
                          // the left one of the S D V - matrices and
                          //      is orthogonal. Note: the apostroph-symbol means
                          //      transposition
data1 = t1 * data         // t1 * data gives uncorrelated data as can be seen
c2 = data1  *' / n        //   since the covariance c2 is diagonal 
$\endgroup$
  • $\begingroup$ What do you mean of "t1=gettrans(c1 ,"pca")'", Do you mean I must do PCA on the covariance matrix? $\endgroup$ – remo Jan 21 '13 at 16:30
  • $\begingroup$ @remo: it gives the rotation-matrix, which rotates (columnwise) any matrix to "pca"-position. In this case, where c1 is symmetric it is as well as rotating the rows (which is what we want). I think in matlab this should be implemented as SVD-procedure, which gives two rotation-matrices and the diagonal for a SVD-decomposition. Again - as c1 is symmetric, the first of the three SVD-matrices should be identical to my matrix t1 here (maybe transposed) $\endgroup$ – Gottfried Helms Jan 21 '13 at 16:37
  • $\begingroup$ ... adding explanation: the term "pca-position" means here, that the columns are rotated such that they become mutually orthogonal. If you use that t1 then as rotation for the rows of "data", the rows of "data" become mutually orthogonal - thus zero-correlated $\endgroup$ – Gottfried Helms Jan 21 '13 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.