CAMEL
Would you like to react to this message? Create an account in a few clicks or log in to continue.

R EFA syntax

2 posters

Go down

R EFA syntax Empty R EFA syntax

Post by pvincentruz Tue Sep 13, 2016 3:13 pm

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
pvincentruz

Posts : 2
Reputation : 0

Back to top Go down

R EFA syntax Empty Re: R EFA syntax

Post by Jeffrey Girard Wed Sep 14, 2016 12:17 am

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)
Jeffrey Girard
Jeffrey Girard
Admin

Posts : 16
Reputation : 0
Location : 4325 Sennott Sq

http://www.jmgirard.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum