Nothing But Consciousness

 R-因子分析实例

心外无物, 发表于:2009-02-11 22:48:12, 分类:资料 浏览( ) 评论( )  收藏这篇日志

factnl> ## 输入六个变量分别是v1-v6
factnl> v1 <- c(1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,4,5,6)
factnl> v2 <- c(1,2,1,1,1,1,2,1,2,1,3,4,3,3,3,4,6,5)
factnl> v3 <- c(3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,5,4,6)
factnl> v4 <- c(3,3,4,3,3,1,1,2,1,1,1,1,2,1,1,5,6,4)
factnl> v5 <- c(1,1,1,1,1,3,3,3,3,3,1,1,1,1,1,6,4,5)
factnl> v6 <- c(1,1,1,2,1,3,3,3,4,3,1,1,1,2,1,6,5,4)
factnl> ## 将6个变量合成为m1
factnl> m1 <- cbind(v1,v2,v3,v4,v5,v6)
factnl> ## 相关矩阵
factnl> cor(m1)

          v1        v2        v3        v4        v5        v6
v1 1.0000000 0.9393083 0.5128866 0.4320310 0.4664948 0.4086076
v2 0.9393083 1.0000000 0.4124441 0.4084281 0.4363925 0.4326113
v3 0.5128866 0.4124441 1.0000000 0.8770750 0.5128866 0.4320310
v4 0.4320310 0.4084281 0.8770750 1.0000000 0.4320310 0.4323259
v5 0.4664948 0.4363925 0.5128866 0.4320310 1.0000000 0.9473451
v6 0.4086076 0.4326113 0.4320310 0.4323259 0.9473451 1.0000000
factnl> ##因子分析
factnl> factanal(m1, factors=3) #对m1进行因子分析,因子个数为3, 默认转轴方法为varimax

 Call:
factanal(x = m1, factors = 3)
Uniquenesses:
   v1    v2    v3    v4    v5    v6
0.005 0.101 0.005 0.224 0.084 0.005
Loadings:
   Factor1 Factor2 Factor3
v1 0.944   0.182   0.267  
v2 0.905   0.235   0.159  
v3 0.236   0.210   0.946  
v4 0.180   0.242   0.828  
v5 0.242   0.881   0.286  
v6 0.193   0.959   0.196 
               Factor1 Factor2 Factor3
SS loadings      1.893   1.886   1.797
Proportion Var   0.316   0.314   0.300
Cumulative Var   0.316   0.630   0.929
The degrees of freedom for the model is 0 and the fit was 0.4755
factnl> factanal(m1, factors=3, rotation="promax")#使用promax方法转轴
Call:
factanal(x = m1, factors = 3, rotation = "promax")
Uniquenesses:
   v1    v2    v3    v4    v5    v6
0.005 0.101 0.005 0.224 0.084 0.005
Loadings:
   Factor1 Factor2 Factor3
v1            0.985         
v2            0.951         
v3                      1.003
v4                      0.867
v5  0.910                 
v6  1.033                
               Factor1 Factor2 Factor3
SS loadings      1.903   1.876   1.772
Proportion Var   0.317   0.313   0.295
Cumulative Var   0.317   0.630   0.925
The degrees of freedom for the model is 0 and the fit was 0.4755
factnl> # The following shows the g factor as PC1
factnl> prcomp(m1)

Standard deviations:
[1] 3.0368683 1.6313757 1.5818857 0.6344131 0.3190765 0.2649086
Rotation:
         PC1         PC2        PC3        PC4        PC5         PC6
v1 0.4168038 -0.52292304  0.2354298 -0.2686501  0.5157193 -0.39907358
v2 0.3885610 -0.50887673  0.2985906  0.3060519 -0.5061522  0.38865228
v3 0.4182779  0.01521834 -0.5555132 -0.5686880 -0.4308467 -0.08474731
v4 0.3943646  0.02184360 -0.5986150  0.5922259  0.3558110  0.09124977
v5 0.4254013  0.47017231  0.2923345 -0.2789775  0.3060409  0.58397162
v6 0.4047824  0.49580764  0.3209708  0.2866938 -0.2682391 -0.57719858
factnl> ## formula interface
factnl> factanal(~v1+v2+v3+v4+v5+v6, factors = 3,

factnl+          scores = "Bartlett")$scores
      Factor1    Factor2    Factor3
1  -0.9039949 -0.9308984  0.9475392
2  -0.8685952 -0.9328721  0.9352330
3  -0.9082818 -0.9320093  0.9616422
4  -1.0021975 -0.2529689  0.8178552
5  -0.9039949 -0.9308984  0.9475392
6  -0.7452711  0.7273960 -0.7884733
7  -0.7098714  0.7254223 -0.8007795
8  -0.7495580  0.7262851 -0.7743704
9  -0.8080740  1.4033517 -0.9304636
10 -0.7452711  0.7273960 -0.7884733
11  0.9272282 -0.9307506 -0.8371538
12  0.9626279 -0.9327243 -0.8494600
13  0.9229413 -0.9318615 -0.8230509
14  0.8290256 -0.2528211 -0.9668378
15  0.9272282 -0.9307506 -0.8371538
16  0.4224366  2.0453079  1.2864761
17  1.4713902  1.2947716  0.5451562
18  1.8822320  0.3086244  1.9547752
factnl> ## a realistic example from Barthlomew (1987, pp. 61-65)
factnl> utils::example(ability.cov)

ablty.> require(stats)
ablty.> (ability.FA <- factanal(factors = 1, covmat=ability.cov))
Call:
factanal(factors = 1, covmat = ability.cov)
Uniquenesses:
general picture  blocks    maze reading   vocab
  0.535   0.853   0.748   0.910   0.232   0.280
Loadings:
        Factor1
general 0.682  
picture 0.384  
blocks  0.502  
maze    0.300  
reading 0.877  
vocab   0.849 
               Factor1
SS loadings      2.443
Proportion Var   0.407
Test of the hypothesis that 1 factor is sufficient.
The chi square statistic is 75.18 on 9 degrees of freedom.
The p-value is 1.46e-12
ablty.> update(ability.FA, factors=2)
Call:
factanal(factors = 2, covmat = ability.cov)
Uniquenesses:
general picture  blocks    maze reading   vocab
  0.455   0.589   0.218   0.769   0.052   0.334
Loadings:
        Factor1 Factor2
general 0.499   0.543  
picture 0.156   0.622  
blocks  0.206   0.860  
maze    0.109   0.468  
reading 0.956   0.182  
vocab   0.785   0.225 
               Factor1 Factor2
SS loadings      1.858   1.724
Proportion Var   0.310   0.287
Cumulative Var   0.310   0.597
Test of the hypothesis that 2 factors are sufficient.
The chi square statistic is 6.11 on 4 degrees of freedom.
The p-value is 0.191
ablty.> update(ability.FA, factors=2, rotation="promax")
Call:
factanal(factors = 2, covmat = ability.cov, rotation = "promax")
Uniquenesses:
general picture  blocks    maze reading   vocab
  0.455   0.589   0.218   0.769   0.052   0.334
Loadings:
        Factor1 Factor2
general  0.364   0.470
picture          0.671
blocks           0.932
maze             0.508
reading  1.023         
vocab    0.811        
               Factor1 Factor2
SS loadings      1.853   1.807
Proportion Var   0.309   0.301
Cumulative Var   0.309   0.610
Test of the hypothesis that 2 factors are sufficient.
The chi square statistic is 6.11 on 4 degrees of freedom.
The p-value is 0.191




























































































































































 Ubuntu 8.10全版本下载地址 没有相关日志 
正在读取日志的评论数据,请稍后……
正在加载日志评论签写框,请稍后……
成员登录通道
正在载入成员登录通道...
BLOG 日历助手
正在载入日历助手...
BLOG 分类列表
BLOG 日志归档
BLOG 推荐日志
  • 暂时没有推荐日志
BLOG 最新评论
{$SideComment}
BLOG 最新留言
{$SideGB}
BLOG 统计信息
正在载入统计信息...