Eigenvalue decomposition of correlation matrix [closed]

别来无恙 提交于 2019-12-12 02:53:39

问题


I have a correlation matrix:

cor.table <- matrix( sample( c(0.9,-0.9) , 2500 , prob = c( 0.8 , 0.2 ) , repl = TRUE ) , 50 , 50 )
diag(cor.table) <- 1

I try to do eigenvalue decomposition:

library(psych)
fit<-principal(cor.table, nfactors=50,rotate="none")

or

stopifnot( eigen( cor.table )$values > 0 )

In both cases I get the error:

Error in eigens$values < .Machine$double.eps : 
  invalid comparison with complex values

What am I doing wrong?


回答1:


This is the same problem you for which you asked a question previously. You need a symmetric matrix.

set.seed(1)
cor.table <- matrix(sample(c(0.9,-0.9),2500,prob=c(0.8,0.2),repl=TRUE),50,50)
ind <- lower.tri(cor.table)
cor.table[ind] <- t(cor.table)[ind]
diag(cor.table) <- 1

Now when you try using eigen you do not get an error.

your.eigen <- eigen(cor.table)
> summary(your.eigen)
Length Class  Mode   
values    50   -none- numeric
vectors 2500   -none- numeric


来源:https://stackoverflow.com/questions/18831058/eigenvalue-decomposition-of-correlation-matrix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!