从 R 中的主载荷构建分数
Constructing scores from principal loadings in R
我想了解 psych 包中的 principal() 函数如何计算 $score 元素。
我想试试协方差矩阵而不是相关矩阵。
model <- principal(mtcars[8:11],nfactors=4, rotate='none', scores=T, cov=T)
基本上,PCA的分数应该是原始中心数据的线性组合,使用加载矩阵作为权重,所以我尝试了:
test <- scale(mtcars[8:11], center=T, scale=F) %*% model$loadings / model$scores
我知道 principal()
函数在加载时使用了某种缩放比例,但是,每列的比率应该仍然相同,而 test
的情况并非如此。
如果我使用相关矩阵,这将不是问题。例如:
model <- principal(mtcars[8:11],nfactors=4, rotate='none', scores=T, cov=F)
test <- scale(mtcars[8:11], center=T, scale=T) %*% model$loadings / model$scores
帮助文档使用了因子分析的术语,让我比较困惑。希望有人能在这里启发我。
提前致谢!
您在 psych
包中发现了一个错误。未正确找到非标准化(协方差)解决方案的分数。这将在下一个版本中修复(至少一个月内不会发布)。在此期间,您可以使用负载矩阵和(居中的)原始数据手动找到分数。
model <- principal(mtcars[8:11],nfactors=4, rotate='none', scores=T, cov=T)
L <- model$loadings # Just get the loadings matrix
S <- model$scores # This gives an incorrect answer in the current version
d <- mtcars[8:11] # get your data
dc <- scale(d,scale=FALSE) # center the data but do not standardize it
sc <- dc %*% L # scores are the centered data times the loadings
lowerCor(sc) #These scores, being principal components
# should be orthogonal
PC1 PC2 PC3 PC4
PC1 1
PC2 0 1
PC3 0 0 1
PC4 0 0 0 1
当您发现 psych
的问题未在此处回答时,写信给我(包开发人员)很有用。
请注意,对于未旋转的解,分量载荷也是正交的(它们应该是)。
factor.congruence(L,L)
PC1 PC2 PC3 PC4
PC1 1 0 0 0
PC2 0 1 0 0
PC3 0 0 1 0
PC4 0 0 0 1
(Burt 的因子一致性度量,也称为 Tucker 系数,取(非中心)载荷的内积,然后除以各列的平方和)。您还可以找到 Loadings
的叉积
round( t(L) %*% L,3)
PC1 PC2 PC3 PC4
PC1 2.742 0.000 0.000 0.000
PC2 0.000 0.721 0.000 0.000
PC3 0.000 0.000 0.142 0.000
PC4 0.000 0.000 0.000 0.051
我想了解 psych 包中的 principal() 函数如何计算 $score 元素。
我想试试协方差矩阵而不是相关矩阵。
model <- principal(mtcars[8:11],nfactors=4, rotate='none', scores=T, cov=T)
基本上,PCA的分数应该是原始中心数据的线性组合,使用加载矩阵作为权重,所以我尝试了:
test <- scale(mtcars[8:11], center=T, scale=F) %*% model$loadings / model$scores
我知道 principal()
函数在加载时使用了某种缩放比例,但是,每列的比率应该仍然相同,而 test
的情况并非如此。
如果我使用相关矩阵,这将不是问题。例如:
model <- principal(mtcars[8:11],nfactors=4, rotate='none', scores=T, cov=F)
test <- scale(mtcars[8:11], center=T, scale=T) %*% model$loadings / model$scores
帮助文档使用了因子分析的术语,让我比较困惑。希望有人能在这里启发我。
提前致谢!
您在 psych
包中发现了一个错误。未正确找到非标准化(协方差)解决方案的分数。这将在下一个版本中修复(至少一个月内不会发布)。在此期间,您可以使用负载矩阵和(居中的)原始数据手动找到分数。
model <- principal(mtcars[8:11],nfactors=4, rotate='none', scores=T, cov=T)
L <- model$loadings # Just get the loadings matrix
S <- model$scores # This gives an incorrect answer in the current version
d <- mtcars[8:11] # get your data
dc <- scale(d,scale=FALSE) # center the data but do not standardize it
sc <- dc %*% L # scores are the centered data times the loadings
lowerCor(sc) #These scores, being principal components
# should be orthogonal
PC1 PC2 PC3 PC4
PC1 1
PC2 0 1
PC3 0 0 1
PC4 0 0 0 1
当您发现 psych
的问题未在此处回答时,写信给我(包开发人员)很有用。
请注意,对于未旋转的解,分量载荷也是正交的(它们应该是)。
factor.congruence(L,L)
PC1 PC2 PC3 PC4
PC1 1 0 0 0
PC2 0 1 0 0
PC3 0 0 1 0
PC4 0 0 0 1
(Burt 的因子一致性度量,也称为 Tucker 系数,取(非中心)载荷的内积,然后除以各列的平方和)。您还可以找到 Loadings
的叉积round( t(L) %*% L,3)
PC1 PC2 PC3 PC4
PC1 2.742 0.000 0.000 0.000
PC2 0.000 0.721 0.000 0.000
PC3 0.000 0.000 0.142 0.000
PC4 0.000 0.000 0.000 0.051