[英]How to get the structure matrix in R using the factanal() function?
這是我在這個論壇上的第一篇文章。 我是 R 和因子分析的新手,我想我有一個非常簡單的問題。 我正在關注 Andy Field 的“Discovering Statistics Using R”一書(2012 年)以獲得一般指導。 Field 建議在使用傾斜旋轉進行因子分析時同時提供模式和結構矩陣。
雖然模式矩陣只是載荷表,但我在使用factanal()
函數獲取 R 中的結構矩陣時遇到了更多困難。
為了使用principal()
函數獲取 PCA 的結構矩陣,Field 提供了以下公式: fit$loadings %*% fit$Phi
,它將因子加載矩陣乘以因子相關矩陣。 盡管factanal()
確實將因子相關性存儲在某處——因為它在一般輸出的一部分(負載下)中提供它們——但我在輸出中找不到名為“Phi”、“因子相關性”或等效物的對象擬合模型(在 R Studio 中)。 因此,我不知道在 Field 的公式中放入什么術語來替換 Phi 以獲得結構矩陣。
我在這里和這里看到,之前, factanal()
沒有提供因子相關性——但現在它確實在輸出中提供了; 我只是不知道訪問它的正確術語。 感謝您對此的任何幫助!
編輯:根據這本書,我使用以下公式與四個因子和 PCA 的傾斜旋轉:
pc4 <- principal(raqData, nfactors = 4, rotate = "oblimin").
在這種情況下,當我在 R Studio 中雙擊對象“pc4”時,有一個名為“Phi”的對象,我可以pc4$loadings %*% pc4$Phi
使用pc4$loadings %*% pc4$Phi
獲取結構矩陣。
接下來,我嘗試使用 EFA,而不是 PCA,再次使用四個因子和傾斜旋轉 (promax)。 這一步有效,我可以得到因子相關性(為了簡潔起見,減少一些輸出):
> fit <- factanal(mydata, 4, rotation="promax")
> fit
Call...
Uniquenesses...
Loadings...
SS loadings...
Factor Correlations:
Factor1 Factor2 Factor3 Factor4
Factor1 1.000 -0.874 0.632 0.571
Factor2 -0.874 1.000 -0.118 -0.438
Factor3 0.632 -0.118 1.000 0.356
Factor4 0.571 -0.438 0.356 1.000
Test of the hypothesis that 4 factors are sufficient...
接下來,我嘗試結構矩陣公式並得到以下錯誤:
> fit$loadings %*% fit$Phi
Error in fit$loadings %*% fit$Phi :
requires numeric/complex matrix/vector arguments
但是,當我檢查與所獲得的“適合”的對象factanal()
不存在所謂的“披”對象(因為有對principal()
不知道如何解釋上述任何錯誤。我已經看到了這個錯誤討論在這里和這里,但我不清楚如何在這里解決它。
雖然這是一篇舊帖子,但為了幫助其他人,實際輸出中的兩個組件負載和 psi(不是 phi)是 fit$loadings 和 fit$uniqueness。 您可以通過編寫 fit$loadings[,1:q] 來訪問負載矩陣,其中 q 是您使用的因子。 例如 - 我在 R 工作室中的 Harman23.cor 數據上運行了 factanal。 並檢查負載以低於輸出。
> Harman23.FA <- factanal(factors = 3, covmat = Harman23.cor)
> Harman23.FA$loadings
Loadings:
Factor1 Factor2 Factor3
height 0.886 0.267 -0.130
arm.span 0.937 0.195 0.280
forearm 0.874 0.188
lower.leg 0.877 0.230 -0.145
weight 0.242 0.916 -0.106
bitro.diameter 0.193 0.777
chest.girth 0.137 0.755
chest.width 0.261 0.646 0.159
Factor1 Factor2 Factor3
SS loadings 3.379 2.628 0.162
Proportion Var 0.422 0.329 0.020
Cumulative Var 0.422 0.751 0.771
顯然 $loadings 沒有返回矩陣。 相反,您可以使用這個:
> as.matrix(Harman23.FA$loadings[,1:3])
Factor1 Factor2 Factor3
height 0.8859687 0.2666293 -0.130079754
arm.span 0.9371891 0.1951310 0.280364451
forearm 0.8741374 0.1876181 0.089154498
lower.leg 0.8768750 0.2303982 -0.144815728
weight 0.2422827 0.9164637 -0.106482093
bitro.diameter 0.1925419 0.7766283 -0.020581101
chest.girth 0.1368022 0.7554074 0.003677235
chest.width 0.2605798 0.6458413 0.159110501
請注意,此處使用的因子是 3,因此在訪問加載時我們提到了 1:3 列。 同樣,對於使用因子 q 運行 factanal,您應該提及 Harman23.FA$loadings[,1:q]。
另請注意,作為唯一性矩陣的 psi 是對角矩陣。 所以你應該像這樣訪問它
> psihat <- diag(Harman23.FA$uniquenesses)
> psihat
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] 0.1270475 0.000 0.000000 0.0000000 0.00000000 0.0000000 0.0000000 0.0000000
[2,] 0.0000000 0.005 0.000000 0.0000000 0.00000000 0.0000000 0.0000000 0.0000000
[3,] 0.0000000 0.000 0.192735 0.0000000 0.00000000 0.0000000 0.0000000 0.0000000
[4,] 0.0000000 0.000 0.000000 0.1570353 0.00000000 0.0000000 0.0000000 0.0000000
[5,] 0.0000000 0.000 0.000000 0.0000000 0.09005497 0.0000000 0.0000000 0.0000000
[6,] 0.0000000 0.000 0.000000 0.0000000 0.00000000 0.3593523 0.0000000 0.0000000
[7,] 0.0000000 0.000 0.000000 0.0000000 0.00000000 0.0000000 0.4106308 0.0000000
[8,] 0.0000000 0.000 0.000000 0.0000000 0.00000000 0.0000000 0.0000000 0.4896708
否則你的矩陣乘法 fit$loadings %*% fit$Phi 將是非共形的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.