从 svyfactanal 中提取因子分数
Extracting factor scores from svyfactanal
我试图通过使用 svyfactanal()
函数并获得因子得分来 运行 因子分析。 运行ning因子分析没有问题。
library(survey)
factor1 <- svyfactanal(~ var1 + var2 + var3 ... + var12,
design = design, factors = 4, rotation = "promax",
scores = "regression")
但是,当我想为每个观察提取因子分数时,我收到一条错误消息:
data1 <- cbind(data, factor1$scores)
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 1297, 0
然后我手动检查因子得分,我收到了这条消息:
factor1$scores
# NULL
有没有办法从 svyfactanal()
函数中提取这些分数?
svyfactanal 只是将不同的协方差矩阵传递给 factanal。在 factanal 的文档中,分数以 $scores 为单位,例如(来自帮助):
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)
我试图通过使用 svyfactanal()
函数并获得因子得分来 运行 因子分析。 运行ning因子分析没有问题。
library(survey)
factor1 <- svyfactanal(~ var1 + var2 + var3 ... + var12,
design = design, factors = 4, rotation = "promax",
scores = "regression")
但是,当我想为每个观察提取因子分数时,我收到一条错误消息:
data1 <- cbind(data, factor1$scores)
Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 1297, 0
然后我手动检查因子得分,我收到了这条消息:
factor1$scores
# NULL
有没有办法从 svyfactanal()
函数中提取这些分数?
svyfactanal 只是将不同的协方差矩阵传递给 factanal。在 factanal 的文档中,分数以 $scores 为单位,例如(来自帮助):
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)