测试数据:
PopulationIncomeIlliteracyLife ExpMurderHS Grad
361536242.169.0515.141.3
36563151.569.3111.366.7
221245301.870.557.858.1
211033781.970.6610.139.9
2119851141.171.7110.362.6
254148840.772.066.863.9
310053481.172.483.156
57948090.970.066.254.6
827748151.370.6610.752.6
《
R语言实战》学习笔记:
#读取数据
EFAdata<-
read.table('C:/Users/Administrator/Desktop/applicant.data')
#加载psych包
library(psych)
#判断需提取的公共因子数
fa.parallel(EFAdata,n.obs=112,fa='both',n.iter=100,
main='Scree plots with
parallel analysis')
#提取公共因子
EFAdata.fa <- fa(EFAdata,nfactors=2,rotate='none',fm='pa')
EFAdata.fa
#绘制因子分析的结果
factor.plot(EFAdata.fa,labels=rownames(EFAdata.fa$loadings))
#绘制因子分析的载荷矩阵
fa.diagram(EFAdata.fa,simple=TRUE)
#因子得分权重
dataweights=EFAdata.fa$weights
#各样本因子得分
datascores=EFAd