简体   繁体   English

R psych软件包-使用mat.sort()在PCA之后对相关矩阵进行排序

[英]R psych package - Sort correlation matrix after PCA using mat.sort()

After principal component analysis I am trying to get the variables of my original correlation matrix to be sorted in the same way as in the (sorted) loadings matrix (as displayed with print.psych). 经过主成分分析后,我试图以与(已排序的)加载矩阵(与print.psych一起显示)相同的方式对原始相关矩阵的变量进行排序。 I have used the following functions from the psych package, but I can't get the two to align. 我已经使用了psych软件包中的以下函数,但无法将两者对齐。

pc <- principal(myCorrMatrix$correlations, nfactors=15, n.obs=49, rotate="oblimin")
print.psych(pc, cut=0.3, sort=TRUE)

sortedPC <- fa.sort(pc)
sortedMatrix <- mat.sort(myCorrMatrix$correlations, sortedPC)

I am not 100% sure what the second parameter of mat.sort should be, but i tried several of the elements of sortedPC to no avail. 我不是100%确定mat.sort的第二个参数应该是什么,但是我尝试了sortedPC的几个元素都没有用。 Any pointers would be much appreciated! 任何指针将不胜感激!

Don't pass fa.sort() to mat.sort() . 不要将fa.sort()传递给mat.sort() mat.sort() expects an fa object, which has the $loadings in it. mat.sort()需要一个fa对象,该对象中包含$ loadings。 Note that principal() also gives the $loadings in the resulting object. 请注意, principal()还会在结果对象中提供$ loadings。 I think this should work: 我认为这应该工作:

sortedMatrix <- mat.sort(myCorrMatrix$correlations, pc)

Here's an example: 这是一个例子:

data(Bechtoldt.1)
sorted <- mat.sort(Bechtoldt.1,principal(Bechtoldt.1,5))
cor.plot(sorted)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM