Basic factor analysis in R

[This article was first published on Dataninja » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The call to perform factor analysis on a set of variables in R is:

fact1<- factanal(x,factors,scores=c(“regression”),rotation=”varimax”)

where “x” is a dataframe containing the appropriate variables, and “factors” is the number of factors to be extracted.

socres=”…” and rotation=”…” are optional, and varimax is the default rotation.

The factanal function doesn’t seem to handle missing observations well, so it’s easier to create a new dataframe based on your original, with the missing values omitted:

x1<-na.omit(x)

To view the summary of the factor analysis, simply type the name of the object under which the analysis was saved.

fact1

To view the scores, use

fact1$scores

To view a scree plot, install the “psy” package load it

install.packages(“psy”)
library(psy)

Then type

scree.plot(fact1$correlations)

The above commands and options are only the very basics. For more information, view the documentation for the factanal function. For more information about factor analysis in general, here is a nice nontechnical introduction.


To leave a comment for the author, please follow the link and comment on their blog: Dataninja » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)