因子分析

Reads: 931 Edit

1 数据说明

根据100位学生6门课程成绩的可观测数据,构建因子分析,找出影响学生成绩的潜在因素。

spss-247

2 因子分析

> library(haven)
> examData=read_sav("D:/Desktop/考试成绩.sav")
> examDataScale=scale(examData[,-1])
> fit_fact=factanal(examDataScale, 2, rotation="varimax",scores="regression")
> fit_fact

Call:
factanal(x = examDataScale, factors = 2, rotation = "varimax")

Uniquenesses:
 数学  物理  化学  语文  历史  英语 
0.245 0.451 0.479 0.136 0.215 0.181 

Loadings:
     Factor1 Factor2
数学 -0.355   0.793 
物理 -0.201   0.713 
化学 -0.216   0.689 
语文  0.850  -0.376 
历史  0.854  -0.235 
英语  0.872  -0.242 

               Factor1 Factor2
SS loadings      2.425   1.868
Proportion Var   0.404   0.311
Cumulative Var   0.404   0.716

Test of the hypothesis that 2 factors are sufficient.
The chi square statistic is 0.39 on 4 degrees of freedom.
The p-value is 0.983

说明:factanal()函数采用极大似然抽取因子。

2.1 绘制载荷图

> plot(fit_fact$loadings[,1:2],xlim=c(-1,1),ylim=c(-1,1)) 

r-89

2.2 给出计算出的因子得分

> fit_fact$scores
            Factor1       Factor2
  [1,]  1.456299363  1.0136856371
  [2,]  1.294187640  1.1863714081
  [3,]  1.040371279  0.9072936583
  [4,]  0.760641930  1.4625405421
  [5,]  0.827222616  0.5413305244
  [6,]  0.831219322  0.9320808701
  [7,] -0.005786369  2.3518467881
  [8,]  0.186394278  1.5203679004
  [9,]  0.041747108  1.2985503449
 [10,]  0.117807609  0.6172029447

2.3 计算因子总得分

> fit_fact$scores%*%c(0.404/0.716,0.311/0.716)
               [,1]
  [1,]  1.262012815
  [2,]  1.245549322
  [3,]  0.981114978
  [4,]  1.064454537
  [5,]  0.701887891
  [6,]  0.873868375
  [7,]  1.018277455
  [8,]  0.765555455
  [9,]  0.587590767
 [10,]  0.334559204 

说明:载荷平方0.404和0.311在fit_fact$loadings中,但是不能调用,需要自己打出。



获取案例数据,请关注微信公众号并回复:R_dt14


Comments

Make a comment