2013-09-16 102 views
1

我有一個相關矩陣:特徵值分解

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

我嘗試做特徵值分解:

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

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

在這兩種情況下,我得到的錯誤:

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

我在做什麼錯?

+2

您可能需要一個對稱矩陣 - 在您的示例中您沒有這個對稱矩陣。 – dayne

+0

使你的矩陣對稱後 - 在我以前給你的答案中使用相同的方法(http://stackoverflow.com/questions/18763723/create-covariance-matrix-from-correlation-table-with-both-positively-and -negativ/18764141#18764141) - 我沒有得到'eigen(cor.table)'的錯誤。 – dayne

+1

要有一個有效的相關矩陣,還需要確保特徵值是非負的。 –

回答

1

這與您之前詢問question的問題相同。你需要一個對稱矩陣。

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 

現在,當您嘗試使用eigen時,您不會收到錯誤消息。

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

是的,這會產生一個對稱矩陣,但是主體(cor.table,nfactors = 50,rotate =「none」)仍然會產生錯誤,因爲某些特徵值是非負的。有沒有辦法來解決這個問題? – user1723765