Reputation: 3
I was trying to run a factor analysis by using the svyfactanal()
function and getting factor scores. There is no problem with running the factor analysis.
library(survey)
factor1 <- svyfactanal(~ var1 + var2 + var3 ... + var12,
design = design, factors = 4, rotation = "promax",
scores = "regression")
However, when I want to extract the factor scores for each observation I receive an error message:
data1 <- cbind(data, factor1$scores)
Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 1297, 0
Then I check the factor scores manually, and I received this message:
factor1$scores
# NULL
Is there a way to extract these scores from the svyfactanal()
function?
Upvotes: 0
Views: 352
Reputation: 2388
svyfactanal just passes a different covariance matrix to factanal. In the documentation for factanal, the scores are in $scores e.g. (from the help):
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
If you wanted just the first factor scores, you would use:
factanal(~v1+v2+v3+v4+v5+v6, factors = 3,
scores = "Bartlett")$scores[,1]
or, for your example, something like:
factor1scores <- factor1$scores[,1]
data1 <- cbind(data, factor1scores)
Upvotes: 1