R EFA syntax
2 posters
Page 1 of 1
R EFA syntax
This is the syntax I use to conduct EFA in R
- Code:
## Pricipal Components Analysis
# entering raw data and extracting PCs
# from the correlation matrix
fit <- princomp(na.omit(x), cor=TRUE)
summary(fit) # print variance accounted for
loadings(fit) # pc loadings
# Determine Number of Factors to Extract
library(nFactors)
ev <- eigen(cor(na.omit(x))) # get eigenvalues
ap <- parallel(subject=nrow(x),var=ncol(x),
rep=100,cent=.05)
#Get Screeplot
nS <- nScree(x=ev$values, aparallel=ap$eigen$qevpea)
plotnScree(nS)
#ONCE YOU KNOW HOW MANY FACTORS TO EXTRACT
# Maximum Likelihood Factor Analysis
# entering raw data and extracting n factors,
# with promax rotation
#EFA1
#substitue n for the number of factors to extract
fit2 <- factanal(na.omit(dataEFA), n, rotation="promax")
print(fit2, digits=2, sort=FALSE
pvincentruz- Posts : 2
Reputation : 0
Re: R EFA syntax
Thanks for sharing! One quick note: your syntax includes both PCA and EFA. If all you want is EFA, the first part isn't necessary.
- Code:
# Maximum Likelihood Factor Analysis
# entering raw data and extracting 3 factors,
# with varimax rotation
fit <- factanal(mydata, 3, rotation="varimax")
print(fit, digits=2, cutoff=.3, sort=TRUE)
# plot factor 1 by factor 2
load <- fit$loadings[,1:2]
plot(load,type="n") # set up plot
text(load,labels=names(mydata),cex=.7) # add variable names
# Determine Number of Factors to Extract
library(nFactors)
ev <- eigen(cor(mydata)) # get eigenvalues
ap <- parallel(subject=nrow(mydata),var=ncol(mydata),
rep=100,cent=.05)
nS <- nScree(x=ev$values, aparallel=ap$eigen$qevpea)
plotnScree(nS)
Similar topics
» [Fall 2017] Meeting 8 - Example Logistic Regression
» Mixture Models (Slides and Syntax): Narcissistic Personality Disorder
» Mixture Models (Slides and Syntax): Narcissistic Personality Disorder
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|