psych::principal
为了测试目的,我需要以编程方式重现自动(varimax)旋转。
事实证明,对于某些数据,我无法从 再现该旋转psych
,因为显然,输出中组件的顺序会随着旋转而改变。
考虑这个可重现的例子:
# some dataset from psych
library(psych)
data("Thurstone")
principal.unrotated <- principal(r = Thurstone, nfactors = 4, rotate = "none")$loa # calculate unrotated loadings
principal.varimax <- principal(r = Thurstone, nfactors = 4, rotate = "varimax")$loa # calculate varimax rotated loadings
rot.mat.varimax <- varimax(x = principal.unrotated)$rotmat # manually calculate varimax rotmat on unrotated loadings
round(x = unclass(principal.unrotated) %*% rot.mat.varimax, digits = 12) == round(x = unclass(principal.varimax), digits = 12) # works as expected
#> [,1] [,2] [,3] [,4]
#> Sentences TRUE TRUE TRUE TRUE
#> Vocabulary TRUE TRUE TRUE TRUE
#> Sent.Completion TRUE TRUE TRUE TRUE
#> First.Letters TRUE TRUE TRUE TRUE
#> 4.Letter.Words TRUE TRUE TRUE TRUE
#> Suffixes TRUE TRUE TRUE TRUE
#> Letter.Series TRUE TRUE TRUE TRUE
#> Pedigrees TRUE TRUE TRUE TRUE
#> Letter.Group TRUE TRUE TRUE TRUE
# same procedure using some dataset from another package
library(qmethod)
data("lipset")
Lipset <- cor(x = lipset[[1]], method = "pearson") # must calculate cor matrix first
principal.unrotated <- principal(r = Lipset, nfactors = 4, rotate = "none")$loa # calculate unrotated loadings
principal.varimax <- principal(r = Lipset, nfactors = 4, rotate = "varimax")$loa # calculate varimax rotated loadings
rot.mat.varimax <- varimax(x = principal.unrotated)$rotmat # manually calculate varimax rotmat on unrotated loadings
round(x = unclass(principal.unrotated) %*% rot.mat.varimax, digits = 12) == round(x = unclass(principal.varimax), digits = 12) # fails
#> [,1] [,2] [,3] [,4]
#> US1 FALSE FALSE TRUE TRUE
#> US2 FALSE FALSE TRUE TRUE
#> US3 FALSE FALSE TRUE TRUE
#> US4 FALSE FALSE TRUE TRUE
#> JP5 FALSE FALSE TRUE TRUE
#> CA6 FALSE FALSE TRUE TRUE
#> UK7 FALSE FALSE TRUE TRUE
#> US8 FALSE FALSE TRUE TRUE
#> FR9 FALSE FALSE TRUE TRUE
round(unclass(principal.varimax)[, c(2,1,3,4)], 12) == round(unclass(principal.unrotated) %*% rot.mat.varimax, 12) # seems like the ORDER of components is reversed
#> PC1 PC2 PC3 PC4
#> US1 TRUE TRUE TRUE TRUE
#> US2 TRUE TRUE TRUE TRUE
#> US3 TRUE TRUE TRUE TRUE
#> US4 TRUE TRUE TRUE TRUE
#> JP5 TRUE TRUE TRUE TRUE
#> CA6 TRUE TRUE TRUE TRUE
#> UK7 TRUE TRUE TRUE TRUE
#> US8 TRUE TRUE TRUE TRUE
#> FR9 TRUE TRUE TRUE TRUE
- 这是预期的行为,如果是,为什么?
- 我怎样才能避免这种情况?
更新
只是一个小补充:旋转矩阵在两个过程中实际上是相同的:
principal.varimax$rot.mat == rot.mat.varimax
这意味着(有点违反直觉)rot.mat
已按原始顺序应用于主要组件的过去版本。