我试图通过使用svyfactanal()
函数并获得因子分数来运行因子分析。运行因子分析没有问题。
library(survey)
factor1 <- svyfactanal(~ var1 + var2 + var3 ... + var12,
design = design, factors = 4, rotation = "promax",
scores = "regression")
但是,当我想提取每个观察的因子得分时,我收到一条错误消息:
data1 <- cbind(data, factor1$scores)
data.frame(...,check.names = FALSE)出错: 参数意味着不同的行数:1297,0
然后我手动检查因子分数,我收到了这条消息:
factor1$scores
# NULL
有没有办法从svyfactanal()
函数中提取这些分数?
答案 0 :(得分:1)
svyfactanal只是将一个不同的协方差矩阵传递给factalal。在factalal的文档中,分数是$分数,例如(来自帮助):
v1 <- c(1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,4,5,6)
v2 <- c(1,2,1,1,1,1,2,1,2,1,3,4,3,3,3,4,6,5)
v3 <- c(3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,5,4,6)
v4 <- c(3,3,4,3,3,1,1,2,1,1,1,1,2,1,1,5,6,4)
v5 <- c(1,1,1,1,1,3,3,3,3,3,1,1,1,1,1,6,4,5)
v6 <- c(1,1,1,2,1,3,3,3,4,3,1,1,1,2,1,6,5,4)
m1 <- cbind(v1,v2,v3,v4,v5,v6)
cor(m1)
factanal(m1, factors = 3) # varimax is the default
factanal(m1, factors = 3, rotation = "promax")
# The following shows the g factor as PC1
prcomp(m1) # signs may depend on platform
## formula interface
factanal(~v1+v2+v3+v4+v5+v6, factors = 3,
scores = "Bartlett")$scores
如果您只想要第一个因子得分,您可以使用:
factanal(~v1+v2+v3+v4+v5+v6, factors = 3,
scores = "Bartlett")$scores[,1]
或者,例如:
factor1scores <- factor1$scores[,1]
data1 <- cbind(data, factor1scores)