Sax1x2x3x4x5x6x7x8x9x10129.691.4010.3314.42115.3152.3041.6021.68102.945462.8723247.940.472.9522.343939.661972.711524.3" />
文档库 最新最全的文档下载
当前位置:文档库 › R语言代码

R语言代码

R语言代码
R语言代码

R语言代码

> Sa<-read.table("789.txt",header=T)

> names(Sa)=c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10")

> Sa

x1 x2 x3 x4 x5 x6 x7 x8 x9 x10

1 29.69 1.40 10.33 14.4

2 115.31 52.30 41.60 21.68 102.94 5462.87

2 3247.94 0.47 2.95 22.34 3939.66 1972.71 1524.39 10.47 3209.1

3 159592.49

3 2500.11 0.76 4.79 22.1

4 4290.43 2452.33 1902.98 7.83 5441.50 167358.63

4 341.53 1.08 6.76 22.71 999.16 493.49 367.78 10.40 916.50 37693.41

5 114.25 1.37 11.09 17.20 546.51 207.48 156.94 34.18 441.34 21443.58

6 467.8

7 0.69 5.35 18.10 925.6

8 430.93 322.80 4.60 971.80 40458.87

7 466.79 0.50 3.70 18.88 579.30 306.77 233.22 7.65 540.88 25814.18

8 2887.31 0.45 3.48 18.03 3463.34 1783.35 1311.33 9.09 3991.89 154279.57

9 89.05 1.48 10.81 14.47 408.19 176.19 131.77 18.39 338.91 17840.92

10 186.53 1.87 12.40 15.92 897.73 458.59 347.99 16.70 660.88 39566.42

11 3534.94 0.62 4.04 21.52 4885.89 2882.31 2204.64 7.26 6395.36 201509.56

12 190.52 2.01 12.28 17.54 908.50 497.80 383.04 15.72 1230.92 39955.77

13 252.20 1.82 11.97 21.33 1250.27 603.72 458.04 15.97 1411.49 47226.48

14 742.63 0.69 6.14 15.58 1351.69 670.15 515.22 5.78 644.37 62127.18

15 105.60 1.19 8.70 14.82 278.00 160.96 125.92 14.33 333.65 14906.53

> library(psych)

> correlations<-cor(Sa)

> correlations

x1 x2 x3 x4 x5 x6

x1 1.0000000 -0.6667775 -0.7401095 0.5789184 0.9732298 0.9599145

x2 -0.6667775 1.0000000 0.9745525 -0.3509073 -0.5628535 -0.5436345

x3 -0.7401095 0.9745525 1.0000000 -0.4912423 -0.6547471 -0.6379326

x4 0.5789184 -0.3509073 -0.4912423 1.0000000 0.6555767 0.6433708

x5 0.9732298 -0.5628535 -0.6547471 0.6555767 1.0000000 0.9954507 x6 0.9599145 -0.5436345 -0.6379326 0.6433708 0.9954507 1.0000000 x7 0.9566966 -0.5395982 -0.6343701 0.6459218 0.9945113 0.9997206 x8 -0.4684530 0.6239307 0.7196857 -0.3866380 -0.4661090 -0.4690802 x9 0.9212494 -0.4866480 -0.5847642 0.6299637 0.9695516 0.9839234 x10 0.9807758 -0.5803394 -0.6679110 0.6195539 0.9973690 0.9914986 x7 x8 x9 x10

x1 0.9566966 -0.4684530 0.9212494 0.9807758

x2 -0.5395982 0.6239307 -0.4866480 -0.5803394

x3 -0.6343701 0.7196857 -0.5847642 -0.6679110

x4 0.6459218 -0.3866380 0.6299637 0.6195539

x5 0.9945113 -0.4661090 0.9695516 0.9973690

x6 0.9997206 -0.4690802 0.9839234 0.9914986

x7 1.0000000 -0.4671442 0.9824863 0.9893044

x8 -0.4671442 1.0000000 -0.4326942 -0.4806761

x9 0.9824863 -0.4326942 1.0000000 0.9648264

x10 0.9893044 -0.4806761 0.9648264 1.0000000

> fa.parallel(correlations,n.obs=112,fa="both",n.iter=100,main="Scree plots with parallel analysis")

Loading required package: parallel

Loading required package: MASS

Parallel analysis suggests that the number of factors = 2 and the number of components = 2

> cortest.bartlett(cor(Sa),n=length(Sa))

$chisq

[1] 172.5306

$p.value

[1] 7.965454e-17

$df

[1] 45

> fa<-factanal(~.,factors=2,data=Sa,scores="regression");fa

Call:

factanal(x = ~., factors = 2, data = Sa, scores = "regression")

Uniquenesses:

x1 x2 x3 x4 x5 x6 x7 x8 x9 x10

0.041 0.035 0.005 0.578 0.005 0.005 0.005 0.497 0.038 0.009

Loadings:

Factor1 Factor2

x1 0.870 -0.450

x2 -0.269 0.945

x3 -0.374 0.925

x4 0.586 -0.281

x5 0.943 -0.327

x6 0.951 -0.305

x7 0.952 -0.301

x8 -0.277 0.653

x9 0.949 -0.247

x10 0.933 -0.346

Factor1 Factor2

SS loadings 5.858 2.927

Proportion Var 0.586 0.293

Cumulative Var 0.586 0.879

Test of the hypothesis that 2 factors are sufficient.

The chi square statistic is 81.07 on 26 degrees of freedom. The p-value is 1.43e-07

> factor.plot(fa.promax,labels=rownames(fa.promax$loadings)) > fa$scores

Factor1 Factor2

1 -0.81129429 0.47156393

2 1.01537048 -1.01826961

3 1.70412369 -0.16473226

4 -0.60589597 -0.46588663

5 -0.4919520

6 0.79151829

6 -0.83762269 -1.02852372

7 -1.21920381 -1.64871742

8 0.80029922 -0.96364935

9 -0.57521405 0.70361665

10 -0.01489917 1.43058430

11 2.15472224 -0.23201257

12 0.03646288 1.45884293

13 0.15033798 1.37199098

14 -0.45034003 -0.67968701

15 -0.85489441 -0.02663853

相关文档