主成分分析法
例
30个市经济各项水平统计如下,请针对各市经济水平做综合评价。
指标如下:GDP、居民消费水平、固定资产投资、职工平均工资、货物周转量、居民消费价格指数、商品零售价格指数、工业总产值
1 2 3 4 5 6 7 8 9 10 11
| zef_data = xlsread('zhengfu.xlsx','A1:H30'); z = zscore(zef_data)
cor = corrcoef(z)
[vec, val] = eig(cor) newval = diag(val); newy = sort(newval, 'descend')
newrate = newy./sum(newy)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| vec = 0.0109 0.5539 0.4080 -0.1042 0.0890 0.2307 0.6671 0.0977 -0.0771 -0.3504 0.3043 -0.4476 -0.4496 -0.4534 0.2001 0.3613 0.4191 0.4359 -0.5288 -0.2359 -0.2482 0.0325 -0.1290 0.4688 -0.6966 0.2717 0.0032 0.4111 -0.1323 -0.0710 -0.1781 0.4665 -0.2552 -0.2215 0.0281 -0.5299 0.4367 0.5087 -0.1960 0.3411 0.5152 -0.1608 0.5043 0.4166 0.1020 0.1151 -0.2373 0.4482 -0.0497 0.0252 0.2152 -0.0557 -0.6998 0.5873 -0.2350 -0.2401 -0.0024 -0.4806 -0.3998 0.3266 -0.1415 0.3438 0.5626 0.2183 val = 0.0119 0 0 0 0 0 0 0 0 0.0489 0 0 0 0 0 0 0 0 0.0721 0 0 0 0 0 0 0 0 0.1662 0 0 0 0 0 0 0 0 0.5028 0 0 0 0 0 0 0 0 1.1819 0 0 0 0 0 0 0 0 1.9446 0 0 0 0 0 0 0 0 4.0716 newy = 4.0716 1.9446 1.1819 0.5028 0.1662 0.0721 0.0489 0.0119 newrate = 0.5089 0.2431 0.1477 0.0629 0.0208 0.0090 0.0061 0.0015
|
由方差贡献率可知:0.5089+0.2431+0.1477>0.8,因此7、6、5后三项作为主成分。
下图所示为特征向量值,所以7、6、5倒数3列为各省主成分。
1 2 3 4 5 6 7 8 9
| vec = 0.0109 0.5539 0.4080 -0.1042 0.0890 0.2307 0.6671 0.0977 -0.0771 -0.3504 0.3043 -0.4476 -0.4496 -0.4534 0.2001 0.3613 0.4191 0.4359 -0.5288 -0.2359 -0.2482 0.0325 -0.1290 0.4688 -0.6966 0.2717 0.0032 0.4111 -0.1323 -0.0710 -0.1781 0.4665 -0.2552 -0.2215 0.0281 -0.5299 0.4367 0.5087 -0.1960 0.3411 0.5152 -0.1608 0.5043 0.4166 0.1020 0.1151 -0.2373 0.4482 -0.0497 0.0252 0.2152 -0.0557 -0.6998 0.5873 -0.2350 -0.2401 -0.0024 -0.4806 -0.3998 0.3266 -0.1415 0.3438 0.5626 0.2183
|
1 2 3 4 5
| sco = z * vec
nowsco = sco(:, end) .* newrate(1) + sco(:, end-1) .* newrate(2)+ sco(:, end-2) .* newrate(3) [a,x] = sort(nowsco, 'descend')
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| sco = -0.2671 0.4404 -0.1319 0.7683 0.0348 -1.0019 -0.8083 3.1053 -0.1212 -0.0731 0.1029 0.5436 0.9089 -1.9800 -0.7629 2.6881 -0.0113 0.4556 -0.3883 -1.0661 0.9795 2.9656 -1.0149 3.3810 0.0458 0.1186 0.2694 0.6032 0.2964 0.8737 -1.5556 1.3791 0.0503 0.0518 0.6655 0.2457 -0.0388 1.0481 -2.0285 1.0424 -0.2491 -0.7849 0.0103 -0.2186 0.6038 1.4134 0.4535 3.2715 0.2483 -0.0634 0.2053 0.5152 0.2555 -0.0685 -1.0577 1.6799 0.3040 -0.2936 0.0847 -0.0270 0.1158 0.5102 -0.2808 2.5044 0.0840 0.0376 -0.3266 -0.4305 -2.3921 -1.8753 0.8014 5.5768 0.0004 -0.0170 0.0486 0.2251 -0.0212 0.6055 3.1295 -0.2001 -0.0152 0.1412 0.3801 -0.4242 0.2755 -0.7199 1.4977 -0.4861 0.0839 0.0399 -0.4196 0.1720 1.0203 -0.7362 0.5886 -0.9374 -0.0532 0.0089 0.4601 -0.6610 -0.0587 -0.9762 0.3208 -0.8409 0.0016 0.0192 -0.1305 0.0309 -0.1090 0.0185 -0.4284 -1.5195 0.0368 -0.0624 -0.2698 0.5473 0.1708 0.8670 3.1543 -0.2973 0.0512 0.0868 -0.3433 0.4549 0.2526 0.5363 1.2403 -1.0387 -0.0414 -0.1997 -0.0449 0.1098 -0.6326 0.6207 0.7261 -1.1425 -0.0019 0.0704 -0.0080 0.0072 -0.0855 0.0907 0.3834 -1.2070 0.0062 0.2360 0.5092 -0.4653 0.7371 -0.9719 3.1392 0.2452 -0.0202 0.1367 0.0953 -0.0901 -0.3339 0.1565 -0.2945 -1.5072 0.0614 -0.1975 -0.3144 -0.3866 1.3292 -2.1673 -0.5809 -0.9178 -0.0205 0.1694 0.0782 0.2735 -0.6234 1.1873 1.3348 -1.1501 -0.0142 0.1213 -0.0579 0.0199 -0.4379 0.3117 -1.1431 -1.9150 -0.0636 -0.1021 0.0482 0.0060 -0.9963 0.7430 -0.5425 -1.7106 0.0281 0.0692 -0.1999 -0.1376 0.3650 -0.7658 -1.3861 -1.7108 -0.0311 -0.0777 -0.0733 0.0158 -0.5475 0.3302 -0.6233 -1.6505 -0.0028 -0.0617 -0.2341 0.0926 -0.2533 0.1336 -0.9374 -1.7505 -0.0382 -0.0898 0.0388 -0.3045 -0.3436 -0.4329 -1.3358 -1.7028 -0.0039 -0.0719 -0.1110 -0.2239 0.0702 -0.6892 -1.2226 -1.6105 -0.0471 -0.1084 0.0569 -0.1955 -0.5414 -0.0271 -0.7662 -1.5784
|
下面展示的为各个市按照上面计算得到的结果以及原数据排名。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| nowsco = 1.2360 0.8902 1.9122 0.4528 0.1923 1.9841 0.5877 1.2817 2.7561 0.7483 0.0103 -0.4428 -0.4942 -0.8748 0.7435 -0.1479 -0.3133 -0.5077 0.7443 -0.8155 -0.9285 -0.0855 -1.2065 -0.8927 -1.3208 -0.9428 -1.0990 -1.2553 -1.2187 -0.9936 a = 2.7561 1.9841 1.9122 1.2817 1.2360 0.8902 0.7483 0.7443 0.7435 0.5877 0.4528 0.1923 0.0103 -0.0855 -0.1479 -0.3133 -0.4428 -0.4942 -0.5077 -0.8155 -0.8748 -0.8927 -0.9285 -0.9428 -0.9936 -1.0990 -1.2065 -1.2187 -1.2553 -1.3208 x = 9 6 3 8 1 2 10 19 15 7 4 5 11 22 16 17 12 13 18 20 14 24 21 26 30 27 23 29 28 25
|
参考