[R] Use scores from factor analysis and missing values factanal(), napredict(), na.omit()

Simon Kiss sjkiss at gmail.com
Thu Apr 26 18:22:43 CEST 2012


Dear all,
I have a series of variables that looks roughly like the sample data below and I'm trying to conduct a factor analysis.  I've omitted cases with missing values for the factor analysis, but now I'd like to use the scores on each component as new variables in the *original* data set for analysis. That is, I'd like to take the scores on each of the two factors and see how they relate to the variable "trust" in the original data set. It looks like I could create a common index variable out of the rownames in each data set and then merge them, but I'm wondering if there is a less bulky way to do that perhaps via ?napredict?
Thank you for your time.
Yours, Simon J. Kiss
*********************************
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606



#Sample Data
mydat<-data.frame(trust=rnorm(100, mean=5, sd=2), v=rnorm(100, mean=1, sd=0.2), w=rnorm(100, mean=2, sd=0.5), x=rnorm(100, mean=0.2, sd=0.2), y=rnorm(100, mean=0.3, sd=0.1), z=rnorm(100, mean=0.5, sd=0.3))
#Set some missing values
mydat[52,2]<-NA
mydat[53,1]<-NA
mydat[95,3]<-NA
#Subset original data set by variables for factor analysis
my<-subset(mydat, select=c(v,w,x,y,z))
#Omit cases with missing variables
my<-na.omit(mydat)
#Factor analysis plus generate Scores
myfit<-factanal(my, 2, rotation='varimax', scores='Bartlett')

#Reintegrate Scores from two factors to original dataset for regression analysis
#?na.predict ?merge(rownames)



More information about the R-help mailing list