Here is the template I’ve been working on to fit EFA models to categorical items. Besides the packages listed at the beginning it will use the Num2Fac function.

##import your data: this example is for spss file
##remember to change data.sav for your path/filename
tt <- read.spss("data.sav", use.value.labels=TRUE, 
  max.value.labels=Inf, to.data.frame=TRUE)
#loading packages that may be used in the script
#You can get the Num2Fac function on a previous post
#save it as an R file and source it or run it to use it
#creating the dataframe with items as categorical variables ("factors")
tt.f <- Num2Fac(tt)
#using the hetcor function to run get the polychoric cors
#this will take a while
tt.polyf <- hetcor(tt.f)
tt.poly <- as.data.frame(tt.polyf$correlations)
#scree plot tests (notice that PA needs a proper simulation to run
tt.scree<-nScree(eig=NULL, x=tt.poly, aparallel=NULL, 
cor=TRUE, model="factors", criteria=NULL)
#you can also use the Very Simple Structure method to get number of 
#factors to retain
VSS(tt.poly, n=6, rotate="oblimin", diagonal=FALSE,
fm="pa", n.obs=426, plot=TRUE, title="VSS")
#fitting a one factor solution (principal axis, oblimin rotation)
tt.1f <- factor.pa(tt.poly, nfactors=1, n.obs=755,rotate="oblimin")

Created by Pretty R at inside-R.org

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

One Response to EFA

  1. matt says:

    looks good!

    One thing that I do now as convention is when I use foreign’s read.filetype I use the generic version, e.g. read.dta(file.choose()) – that way a window pops up and asks for the file I want to include. I figure I am not typically going to be always analyzing the same dataset so why should my template be hard coded for one?

    For a more interesting scree plot, you could also try fa.parallel – which produces the typical scree plot and one based upon parallel analysis, which is kind of cool.
    e.g. (with settings for basic scree) –> fa.parallel(data, n.obs=141, fm=”pa”, fa=”fa”, ntrials=30, main =”Parallel Analysis Scree Plot”, error.bars=FALSE, smc=FALSE, show.legend=FALSE)

    Also, for EFA, I really do like Kwan & Friendly’s tableplots function for visualizing the factor loadings.
    e.g. (with factor loadings from tt.lf$loadings saved to “loadings”)->
    tableplot(t(round(100*loadings)), cell.specs = list(list(cell.fill=”yellow”, back.fill=”gray90″, scale.max=100, label=1)), side.rot=90)
    plot(loadings, pch=1, main=”2 Factor Solution”)
    text(loadings[,1], loadings[,2], rownames(loadings), pos=1)
    abline(h=0, v=0, col=”gray”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s