{"id":1241,"date":"2023-07-27T04:23:20","date_gmt":"2023-07-27T04:23:20","guid":{"rendered":"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/"},"modified":"2023-07-27T04:23:20","modified_gmt":"2023-07-27T04:23:20","slug":"r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/","title":{"rendered":"R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u4e3b\u6210\u5206\u5206\u6790\uff08\u901a\u5e38\u7f29\u5199\u4e3a PCA\uff09\u662f\u4e00\u79cd<a href=\"https:\/\/statorials.org\/cn\/\u76d1\u7763\u5b66\u4e60\u4e0e\u65e0\u76d1\u7763\u5b66\u4e60\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u65e0\u76d1\u7763<\/a>\u673a\u5668\u5b66\u4e60\u6280\u672f\uff0c\u65e8\u5728\u627e\u5230\u4e3b\u6210\u5206\uff08\u539f\u59cb\u9884\u6d4b\u53d8\u91cf\u7684\u7ebf\u6027\u7ec4\u5408\uff09\u6765\u89e3\u91ca\u6570\u636e\u96c6\u4e2d\u7684\u5927\u90e8\u5206\u53d8\u5316\u3002<\/span><\/p>\n<p> <span style=\"color: #000000;\">PCA \u7684\u76ee\u6807\u662f\u7528\u6bd4\u539f\u59cb\u6570\u636e\u96c6\u66f4\u5c11\u7684\u53d8\u91cf\u6765\u89e3\u91ca\u6570\u636e\u96c6\u4e2d\u7684\u5927\u90e8\u5206\u53d8\u5f02\u6027\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u5bf9\u4e8e\u5177\u6709<em>p \u4e2a<\/em>\u53d8\u91cf\u7684\u7ed9\u5b9a\u6570\u636e\u96c6\uff0c\u6211\u4eec\u53ef\u4ee5\u68c0\u67e5\u6bcf\u4e2a\u53d8\u91cf\u6210\u5bf9\u7ec4\u5408\u7684\u6563\u70b9\u56fe\uff0c\u4f46\u6563\u70b9\u56fe\u7684\u6570\u91cf\u53ef\u80fd\u4f1a\u5f88\u5feb\u53d8\u5f97\u5f88\u5927\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u5bf9\u4e8e<em>p \u4e2a<\/em>\u9884\u6d4b\u53d8\u91cf\uff0c\u5b58\u5728 p(p-1)\/2 \u4e2a\u70b9\u4e91\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u56e0\u6b64\uff0c\u5bf9\u4e8e\u5177\u6709 p = 15 \u4e2a\u9884\u6d4b\u53d8\u91cf\u7684\u6570\u636e\u96c6\uff0c\u5c06\u6709 105 \u4e2a\u4e0d\u540c\u7684\u6563\u70b9\u56fe\uff01<\/span><\/p>\n<p><span style=\"color: #000000;\">\u5e78\u8fd0\u7684\u662f\uff0cPCA \u63d0\u4f9b\u4e86\u4e00\u79cd\u627e\u5230\u6570\u636e\u96c6\u4f4e\u7ef4\u8868\u793a\u7684\u65b9\u6cd5\uff0c\u8be5\u8868\u793a\u53ef\u4ee5\u6355\u83b7\u5c3d\u53ef\u80fd\u591a\u7684\u6570\u636e\u53d8\u5316\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u5982\u679c\u6211\u4eec\u80fd\u591f\u6355\u83b7\u4e8c\u7ef4\u4e2d\u7684\u5927\u90e8\u5206\u53d8\u5316\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u539f\u59cb\u6570\u636e\u96c6\u4e2d\u7684\u6240\u6709\u89c2\u5bdf\u7ed3\u679c\u6295\u5f71\u5230\u4e00\u4e2a\u7b80\u5355\u7684\u6563\u70b9\u56fe\u4e0a\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u627e\u5230\u4e3b\u8981\u7ec4\u4ef6\u7684\u65b9\u5f0f\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span style=\"color: #000000;\"><sub>\u7ed9\u5b9a<\/sub><sub>\u4e00\u4e2a<\/sub><sub>\u5177\u6709<\/sub><em>p \u4e2a<\/em><sub>\u9884\u6d4b\u53d8\u91cf\u7684<\/sub><sub>\u6570\u636e\u96c6<\/sub><em>\uff1a<\/em> <em>_<\/em><\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><sub>Z<\/sub> <sub>m<\/sub> <sub>=<\/sub> <sub>\u03a3\u03a6<\/sub> <sub>jm<\/sub> <sub>_<\/sub><\/span><\/li>\n<li> <span style=\"color: #000000;\">Z <sub>1<\/sub>\u662f\u9884\u6d4b\u53d8\u91cf\u7684\u7ebf\u6027\u7ec4\u5408\uff0c\u53ef\u6355\u83b7\u5c3d\u53ef\u80fd\u591a\u7684\u65b9\u5dee\u3002<\/span><\/li>\n<li> <span style=\"color: #000000;\">Z <sub>2<\/sub>\u662f\u9884\u6d4b\u53d8\u91cf\u7684\u4e0b\u4e00\u4e2a\u7ebf\u6027\u7ec4\u5408\uff0c\u5b83\u6355\u83b7\u6700\u5927\u65b9\u5dee\uff0c\u540c\u65f6\u4e0e Z <sub>1<\/sub><em>\u6b63\u4ea4<\/em>\uff08\u5373\u4e0d\u76f8\u5173\uff09\u3002<\/span><\/li>\n<li> <span style=\"color: #000000;\">Z <sub>3<\/sub>\u662f\u9884\u6d4b\u53d8\u91cf\u7684\u4e0b\u4e00\u4e2a\u7ebf\u6027\u7ec4\u5408\uff0c\u5b83\u5728\u4e0e Z <sub>2<\/sub>\u6b63\u4ea4\u7684\u540c\u65f6\u6355\u83b7\u6700\u5927\u65b9\u5dee\u3002<\/span><\/li>\n<li><span style=\"color: #000000;\">\u7b49\u7b49\u3002<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #000000;\">\u5728\u5b9e\u8df5\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u6765\u8ba1\u7b97\u539f\u59cb\u9884\u6d4b\u53d8\u91cf\u7684\u7ebf\u6027\u7ec4\u5408\uff1a<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>1.<\/strong>\u5bf9\u6bcf\u4e2a\u53d8\u91cf\u8fdb\u884c\u7f29\u653e\uff0c\u4f7f\u5176\u5e73\u5747\u503c\u4e3a 0\uff0c\u6807\u51c6\u5dee\u4e3a 1\u3002<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>2.<\/strong>\u8ba1\u7b97\u7f29\u653e\u53d8\u91cf\u7684\u534f\u65b9\u5dee\u77e9\u9635\u3002<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>3.<\/strong>\u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635\u7684\u7279\u5f81\u503c\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4f7f\u7528\u7ebf\u6027\u4ee3\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u8bc1\u660e\u6700\u5927\u7279\u5f81\u503c\u5bf9\u5e94\u7684\u7279\u5f81\u5411\u91cf\u662f\u7b2c\u4e00\u4e3b\u6210\u5206\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u8fd9\u79cd\u7279\u5b9a\u7684\u9884\u6d4b\u53d8\u91cf\u7ec4\u5408\u89e3\u91ca\u4e86\u6570\u636e\u4e2d\u7684\u6700\u5927\u65b9\u5dee\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u7b2c\u4e8c\u5927\u7279\u5f81\u503c\u5bf9\u5e94\u7684\u7279\u5f81\u5411\u91cf\u662f\u7b2c\u4e8c\u4e3b\u6210\u5206\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u672c\u6559\u7a0b\u63d0\u4f9b\u4e86\u5982\u4f55\u5728 R \u4e2d\u6267\u884c\u6b64\u8fc7\u7a0b\u7684\u5206\u6b65\u793a\u4f8b\u3002<\/span><\/p>\n<h3><span style=\"color: #000000;\"><strong>\u7b2c 1 \u6b65\uff1a\u52a0\u8f7d\u6570\u636e<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u9996\u5148\u52a0\u8f7d<strong>Tidyverse<\/strong>\u5305\uff0c\u5176\u4e2d\u5305\u542b\u51e0\u4e2a\u7528\u4e8e\u53ef\u89c6\u5316\u548c\u64cd\u4f5c\u6570\u636e\u7684\u6709\u7528\u51fd\u6570\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\">library<\/span> (tidyverse)\n<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528 R \u4e2d\u5185\u7f6e\u7684<em>USArrests<\/em>\u6570\u636e\u96c6\uff0c\u5176\u4e2d\u5305\u542b 1973 \u5e74\u7f8e\u56fd\u5404\u5dde\u6bcf 100,000 \u540d\u5c45\u6c11\u56e0<em>\u8c0b\u6740<\/em>\u3001<em>\u88ad\u51fb<\/em>\u548c<em>\u5f3a\u5978<\/em>\u800c\u88ab\u6355\u7684\u4eba\u6570\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u5b83\u8fd8\u5305\u62ec\u6bcf\u4e2a\u5dde\u5c45\u4f4f\u5728\u57ce\u5e02\u5730\u533a\u7684\u4eba\u53e3\u767e\u5206\u6bd4<em>UrbanPop<\/em> \u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4ee5\u4e0b\u4ee3\u7801\u663e\u793a\u5982\u4f55\u52a0\u8f7d\u548c\u663e\u793a\u6570\u636e\u96c6\u7684\u7b2c\u4e00\u884c\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\"><span style=\"color: #008080;\">#load data<\/span>\n<span style=\"color: #000000;\">data<\/span><\/span> <span style=\"color: #000000;\">(\"USArrests\")<\/span>\n\n<span style=\"color: #008080;\">#view first six rows of data<\/span>\nhead(USArrests)\n\n           Murder Assault UrbanPop Rape\nAlabama 13.2 236 58 21.2\nAlaska 10.0 263 48 44.5\nArizona 8.1 294 80 31.0\nArkansas 8.8 190 50 19.5\nCalifornia 9.0 276 91 40.6\nColorado 7.9 204 78 38.7\n<\/strong><\/pre>\n<h3><strong>\u6b65\u9aa4 2\uff1a\u8ba1\u7b97\u4e3b\u6210\u5206<\/strong><\/h3>\n<p><span style=\"color: #000000;\">\u52a0\u8f7d\u6570\u636e\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528R\u7684\u5185\u7f6e\u51fd\u6570<strong>prcomp()<\/strong>\u6765\u8ba1\u7b97\u6570\u636e\u96c6\u7684\u4e3b\u6210\u5206\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u8bf7\u52a1\u5fc5\u6307\u5b9a<strong>scale = TRUE<\/strong> \uff0c\u4ee5\u4fbf\u5728\u8ba1\u7b97\u4e3b\u6210\u5206\u4e4b\u524d\u5c06\u6570\u636e\u96c6\u4e2d\u7684\u6bcf\u4e2a\u53d8\u91cf\u7f29\u653e\u4e3a\u5e73\u5747\u503c\u4e3a0\u3001\u6807\u51c6\u5dee\u4e3a1\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u53e6\u8bf7\u6ce8\u610f\uff0cR \u4e2d\u7684\u7279\u5f81\u5411\u91cf\u9ed8\u8ba4\u6307\u5411\u8d1f\u65b9\u5411\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u4e58\u4ee5 -1 \u6765\u53cd\u8f6c\u7b26\u53f7\u3002<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate main components\n<\/span>results &lt;- prcomp(USArrests, scale = <span style=\"color: #008000;\">TRUE<\/span> )\n\n<span style=\"color: #008080;\">#reverse the signs\n<\/span>results$rotation &lt;- -1*results$rotation\n\n<span style=\"color: #008080;\">#display main components\n<\/span>results$rotation\n\n               PC1 PC2 PC3 PC4\nMurder 0.5358995 -0.4181809 0.3412327 -0.64922780\nAssault 0.5831836 -0.1879856 0.2681484 0.74340748\nUrbanPop 0.2781909 0.8728062 0.3780158 -0.13387773\nRape 0.5434321 0.1673186 -0.8177779 -0.08902432<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u7b2c\u4e00\u4e3b\u6210\u5206\uff08PC1\uff09\u5bf9\u4e8e\u8c0b\u6740\u3001\u88ad\u51fb\u548c\u5f3a\u5978\u5177\u6709\u5f88\u9ad8\u7684\u503c\uff0c\u8868\u660e\u8be5\u4e3b\u6210\u5206\u63cf\u8ff0\u4e86\u8fd9\u4e9b\u53d8\u91cf\u4e2d\u6700\u5927\u7684\u53d8\u5f02\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u5230\uff0c\u7b2c\u4e8c\u4e3b\u6210\u5206\uff08PC2\uff09\u5bf9\u4e8e UrbanPop \u5177\u6709\u8f83\u9ad8\u7684\u503c\uff0c\u8868\u660e\u8be5\u4e3b\u6210\u5206\u5f3a\u8c03\u57ce\u5e02\u4eba\u53e3\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u8bf7\u6ce8\u610f\uff0c\u6bcf\u4e2a\u5dde\u7684\u4e3b\u6210\u5206\u5206\u6570\u5b58\u50a8\u5728<strong>results$x<\/strong>\u4e2d\u3002\u6211\u4eec\u8fd8\u5c06\u8fd9\u4e9b\u5206\u6570\u4e58\u4ee5 -1 \u4ee5\u53cd\u8f6c\u7b26\u53f7\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#reverse the signs of the scores\n<\/span>results$x &lt;- -1*results$x\n\n<span style=\"color: #008080;\">#display the first six scores\n<span style=\"color: #000000;\">head(results$x)<\/span>\n<\/span><span style=\"color: #000000;\">\n                  PC1 PC2 PC3 PC4\nAlabama 0.9756604 -1.1220012 0.43980366 -0.154696581\nAlaska 1.9305379 -1.0624269 -2.01950027 0.434175454\nArizona 1.7454429 0.7384595 -0.05423025 0.826264240\nArkansas -0.1399989 -1.1085423 -0.11342217 0.180973554\nCalifornia 2.4986128 1.5274267 -0.59254100 0.338559240\nColorado 1.4993407 0.9776297 -1.08400162 -0.001450164\n<\/span><\/strong><\/pre>\n<h3><strong>\u7b2c 3 \u6b65\uff1a\u4f7f\u7528\u53cc\u56fe\u53ef\u89c6\u5316\u7ed3\u679c<\/strong><\/h3>\n<p><span style=\"color: #000000;\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a<strong>\u53cc\u56fe<\/strong>\u2014\u2014\u5c06\u6570\u636e\u96c6\u4e2d\u7684\u6bcf\u4e2a\u89c2\u6d4b\u503c\u6295\u5f71\u5230\u4f7f\u7528\u7b2c\u4e00\u548c\u7b2c\u4e8c\u4e3b\u6210\u5206\u4f5c\u4e3a\u8f74\u7684\u6563\u70b9\u56fe\u4e0a\u7684\u56fe\uff1a<\/span><\/p>\n<p><span style=\"color: #000000;\">\u8bf7\u6ce8\u610f\uff0c <strong>scale = 0<\/strong>\u786e\u4fdd\u56fe\u4e2d\u7684\u7bad\u5934\u6309\u6bd4\u4f8b\u7f29\u653e\u4ee5\u8868\u793a\u8f7d\u8377\u3002<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>biplot(results, scale = <span style=\"color: #008000;\">0<\/span> )\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-12281 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/pca1.png\" alt=\"R \u4e2d\u4e3b\u6210\u5206\u5206\u6790\u7684\u53cc\u6807\u56fe\" width=\"465\" height=\"464\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p><span style=\"color: #000000;\">\u4ece\u56fe\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230 50 \u4e2a\u72b6\u6001\u4e2d\u7684\u6bcf\u4e00\u4e2a\u90fd\u5728\u4e00\u4e2a\u7b80\u5355\u7684\u4e8c\u7ef4\u7a7a\u95f4\u4e2d\u8868\u793a\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u56fe\u8868\u4e0a\u5f7c\u6b64\u63a5\u8fd1\u7684\u72b6\u6001\u5bf9\u4e8e\u539f\u59cb\u6570\u636e\u96c6\u4e2d\u7684\u53d8\u91cf\u5177\u6709\u76f8\u4f3c\u7684\u6570\u636e\u6a21\u5f0f\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u5230\uff0c\u4e00\u4e9b\u5dde\u4e0e\u67d0\u4e9b\u72af\u7f6a\u7684\u5173\u8054\u6027\u6bd4\u5176\u4ed6\u5dde\u66f4\u5f3a\u70c8\u3002\u4f8b\u5982\uff0c\u4f50\u6cbb\u4e9a\u5dde\u662f\u56fe\u4e2d\u6700\u63a5\u8fd1<em>\u8c0b\u6740<\/em>\u53d8\u91cf\u7684\u5dde\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u5982\u679c\u6211\u4eec\u67e5\u770b\u539f\u59cb\u6570\u636e\u96c6\u4e2d\u8c0b\u6740\u7387\u6700\u9ad8\u7684\u5dde\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4f50\u6cbb\u4e9a\u5dde\u5b9e\u9645\u4e0a\u4f4d\u5c45\u699c\u9996\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display states with highest murder rates in original dataset<\/span>\nhead(USArrests[ <span style=\"color: #3366ff;\">order<\/span> (-USArrests$Murder),])\n\n               Murder Assault UrbanPop Rape\nGeorgia 17.4 211 60 25.8\nMississippi 16.1 259 44 17.1\nFlorida 15.4 335 80 31.9\nLouisiana 15.4 249 66 22.2\nSouth Carolina 14.4 279 48 22.5\nAlabama 13.2 236 58 21.2<\/strong><\/pre>\n<h3><span style=\"color: #000000;\"><strong>\u6b65\u9aa4 4\uff1a\u627e\u51fa\u6bcf\u4e2a\u4e3b\u6210\u5206\u89e3\u91ca\u7684\u65b9\u5dee<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u8ba1\u7b97\u6bcf\u4e2a\u4e3b\u6210\u5206\u89e3\u91ca\u7684\u539f\u59cb\u6570\u636e\u96c6\u4e2d\u7684\u603b\u65b9\u5dee\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate total variance explained by each principal component\n<\/span>results$sdev^2 \/ <span style=\"color: #3366ff;\">sum<\/span> (results$sdev^2)\n\n[1] 0.62006039 0.24744129 0.08914080 0.04335752\n<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u4ece\u7ed3\u679c\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u89c2\u5bdf\u5230\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/span><\/p>\n<ul>\n<li><span style=\"color: #000000;\">\u7b2c\u4e00\u4e2a\u4e3b\u6210\u5206\u89e3\u91ca\u4e86\u6570\u636e\u96c6\u4e2d\u603b\u65b9\u5dee\u7684<strong>62%<\/strong> \u3002<\/span><\/li>\n<li><span style=\"color: #000000;\">\u7b2c\u4e8c\u4e2a\u4e3b\u6210\u5206\u89e3\u91ca\u4e86\u6570\u636e\u96c6\u4e2d\u603b\u65b9\u5dee\u7684<strong>24.7%<\/strong> \u3002<\/span><\/li>\n<li><span style=\"color: #000000;\">\u7b2c\u4e09\u4e3b\u6210\u5206\u89e3\u91ca\u4e86\u6570\u636e\u96c6\u4e2d\u603b\u65b9\u5dee\u7684<strong>8.9%<\/strong> \u3002<\/span><\/li>\n<li><span style=\"color: #000000;\">\u7b2c\u56db\u4e2a\u4e3b\u6210\u5206\u89e3\u91ca\u4e86\u6570\u636e\u96c6\u4e2d\u603b\u65b9\u5dee\u7684<strong>4.3%<\/strong> \u3002<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #000000;\">\u56e0\u6b64\uff0c\u524d\u4e24\u4e2a\u4e3b\u6210\u5206\u89e3\u91ca\u4e86\u6570\u636e\u4e2d\u603b\u65b9\u5dee\u7684\u5927\u90e8\u5206\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u8fd9\u662f\u4e00\u4e2a\u597d\u5146\u5934\uff0c\u56e0\u4e3a\u4e4b\u524d\u7684\u53cc\u56fe\u5c06\u539f\u59cb\u6570\u636e\u4e2d\u7684\u6bcf\u4e2a\u89c2\u6d4b\u503c\u6295\u5f71\u5230\u4ec5\u8003\u8651\u524d\u4e24\u4e2a\u4e3b\u6210\u5206\u7684\u6563\u70b9\u56fe\u4e0a\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u56e0\u6b64\uff0c\u68c0\u67e5\u53cc\u56fe\u4e2d\u7684\u6a21\u5f0f\u4ee5\u8bc6\u522b\u5f7c\u6b64\u76f8\u4f3c\u7684\u72b6\u6001\u662f\u6709\u6548\u7684\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u8fd8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a<strong>\u788e\u77f3\u56fe<\/strong>\u2014\u2014\u663e\u793a\u6bcf\u4e2a\u4e3b\u6210\u5206\u89e3\u91ca\u7684\u603b\u65b9\u5dee\u7684\u56fe\u8868\u2014\u2014\u4ee5\u53ef\u89c6\u5316 PCA \u7ed3\u679c\uff1a<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate total variance explained by each principal component\n<\/span>var_explained = results$sdev^2 \/ <span style=\"color: #3366ff;\">sum<\/span> (results$sdev^2)\n\n<span style=\"color: #008080;\">#create scree plot\n<\/span>qplot(c(1:4), var_explained) + \n  geom_line() + \n  xlab(\" <span style=\"color: #008000;\">Principal Component<\/span> \") + \n  ylab(\" <span style=\"color: #008000;\">Variance Explained<\/span> \") +\n  ggtitle(\" <span style=\"color: #008000;\">Scree Plot<\/span> \") +\n  ylim(0, 1)<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-12282 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/pca2.png\" alt=\"R\u5f62\u788e\u77f3\u5730\u5f62\" width=\"427\" height=\"428\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3><span style=\"color: #000000;\"><strong>\u4e3b\u6210\u5206\u5206\u6790\u5b9e\u8df5<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">\u5728\u5b9e\u8df5\u4e2d\uff0cPCA \u6700\u5e38\u7528\u7684\u539f\u56e0\u6709\u4e24\u4e2a\uff1a<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>1. \u63a2\u7d22\u6027\u6570\u636e\u5206\u6790<\/strong>\u2013 \u5f53\u6211\u4eec\u7b2c\u4e00\u6b21\u63a2\u7d22\u6570\u636e\u96c6\u5e76\u60f3\u8981\u4e86\u89e3\u6570\u636e\u4e2d\u7684\u54ea\u4e9b\u89c2\u5bdf\u7ed3\u679c\u5f7c\u6b64\u6700\u76f8\u4f3c\u65f6\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528 PCA\u3002<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>2. \u4e3b\u6210\u5206\u56de\u5f52<\/strong>\u2014\u2014\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528PCA\u8ba1\u7b97\u4e3b\u6210\u5206\uff0c\u7136\u540e\u5c06\u5176\u7528\u4e8e<a href=\"https:\/\/statorials.org\/cn\/r-\u4e2d\u7684\u4e3b\u6210\u5206\u56de\u5f52\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u4e3b\u6210\u5206\u56de\u5f52<\/a>\u3002\u5f53\u6570\u636e\u96c6\u4e2d\u7684\u9884\u6d4b\u53d8\u91cf\u4e4b\u95f4\u5b58\u5728<a href=\"https:\/\/statorials.org\/cn\/\u591a\u91cd\u5171\u7ebf\u6027\u56de\u5f52\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u591a\u91cd\u5171\u7ebf\u6027<\/a>\u65f6\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528\u8fd9\u79cd\u7c7b\u578b\u7684\u56de\u5f52\u3002<\/span><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u672c\u6559\u7a0b\u4e2d\u4f7f\u7528\u7684\u5b8c\u6574 R \u4ee3\u7801\u53ef\u4ee5<a href=\"https:\/\/github.com\/Statorials\/R-Guides\/blob\/main\/pca.R\" target=\"_blank\" rel=\"noopener noreferrer\">\u5728\u6b64\u5904<\/a>\u627e\u5230\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3b\u6210\u5206\u5206\u6790\uff08\u901a\u5e38\u7f29\u5199\u4e3a PCA\uff09\u662f\u4e00\u79cd\u65e0\u76d1\u7763\u673a\u5668\u5b66\u4e60\u6280\u672f\uff0c\u65e8\u5728\u627e\u5230\u4e3b\u6210\u5206\uff08\u539f\u59cb\u9884\u6d4b\u53d8\u91cf\u7684\u7ebf\u6027\u7ec4\u5408\uff09\u6765\u89e3\u91ca\u6570\u636e\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-1241","post","type-post","status-publish","format-standard","hentry","category-11"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b<\/title>\n<meta name=\"description\" content=\"\u672c\u6559\u7a0b\u63d0\u4f9b\u4e86\u5982\u4f55\u5728 R \u4e2d\u6267\u884c\u4e3b\u6210\u5206\u5206\u6790\u7684\u5206\u6b65\u793a\u4f8b\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/cn\/r\u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6559\u7a0b\u63d0\u4f9b\u4e86\u5982\u4f55\u5728 R \u4e2d\u6267\u884c\u4e3b\u6210\u5206\u5206\u6790\u7684\u5206\u6b65\u793a\u4f8b\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/cn\/r\u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-27T04:23:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/pca1.png\" \/>\n<meta name=\"author\" content=\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/\",\"url\":\"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/\",\"name\":\"R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/cn\/#website\"},\"datePublished\":\"2023-07-27T04:23:20+00:00\",\"dateModified\":\"2023-07-27T04:23:20+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261\"},\"description\":\"\u672c\u6559\u7a0b\u63d0\u4f9b\u4e86\u5982\u4f55\u5728 R \u4e2d\u6267\u884c\u4e3b\u6210\u5206\u5206\u6790\u7684\u5206\u6b65\u793a\u4f8b\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u5bb6\",\"item\":\"https:\/\/statorials.org\/cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/cn\/#website\",\"url\":\"https:\/\/statorials.org\/cn\/\",\"name\":\"Statorials\",\"description\":\"\u60a8\u7684\u7edf\u8ba1\u7d20\u517b\u6307\u5357\uff01\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261\",\"name\":\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\"},\"description\":\"\u5927\u5bb6\u597d\uff0c\u6211\u662f\u672c\u6770\u660e\uff0c\u4e00\u4f4d\u9000\u4f11\u7684\u7edf\u8ba1\u5b66\u6559\u6388\uff0c\u540e\u6765\u6210\u4e3a Statorials \u7684\u70ed\u5fc3\u6559\u5e08\u3002 \u51ed\u501f\u5728\u7edf\u8ba1\u9886\u57df\u7684\u4e30\u5bcc\u7ecf\u9a8c\u548c\u4e13\u4e1a\u77e5\u8bc6\uff0c\u6211\u6e34\u671b\u5206\u4eab\u6211\u7684\u77e5\u8bc6\uff0c\u901a\u8fc7 Statorials \u589e\u5f3a\u5b66\u751f\u7684\u80fd\u529b\u3002\u4e86\u89e3\u66f4\u591a\",\"sameAs\":[\"https:\/\/statorials.org\/cn\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b","description":"\u672c\u6559\u7a0b\u63d0\u4f9b\u4e86\u5982\u4f55\u5728 R \u4e2d\u6267\u884c\u4e3b\u6210\u5206\u5206\u6790\u7684\u5206\u6b65\u793a\u4f8b\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/cn\/r\u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\/","og_locale":"zh_CN","og_type":"article","og_title":"R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b","og_description":"\u672c\u6559\u7a0b\u63d0\u4f9b\u4e86\u5982\u4f55\u5728 R \u4e2d\u6267\u884c\u4e3b\u6210\u5206\u5206\u6790\u7684\u5206\u6b65\u793a\u4f8b\u3002","og_url":"https:\/\/statorials.org\/cn\/r\u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\/","og_site_name":"Statorials","article_published_time":"2023-07-27T04:23:20+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/pca1.png"}],"author":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/","url":"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/","name":"R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b","isPartOf":{"@id":"https:\/\/statorials.org\/cn\/#website"},"datePublished":"2023-07-27T04:23:20+00:00","dateModified":"2023-07-27T04:23:20+00:00","author":{"@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261"},"description":"\u672c\u6559\u7a0b\u63d0\u4f9b\u4e86\u5982\u4f55\u5728 R \u4e2d\u6267\u884c\u4e3b\u6210\u5206\u5206\u6790\u7684\u5206\u6b65\u793a\u4f8b\u3002","breadcrumb":{"@id":"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/cn\/r%e4%b8%ad%e7%9a%84%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u5bb6","item":"https:\/\/statorials.org\/cn\/"},{"@type":"ListItem","position":2,"name":"R \u4e2d\u7684\u4e3b\u6210\u5206\u5206\u6790\uff1a\u5206\u6b65\u793a\u4f8b"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/cn\/#website","url":"https:\/\/statorials.org\/cn\/","name":"Statorials","description":"\u60a8\u7684\u7edf\u8ba1\u7d20\u517b\u6307\u5357\uff01","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261","name":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a"},"description":"\u5927\u5bb6\u597d\uff0c\u6211\u662f\u672c\u6770\u660e\uff0c\u4e00\u4f4d\u9000\u4f11\u7684\u7edf\u8ba1\u5b66\u6559\u6388\uff0c\u540e\u6765\u6210\u4e3a Statorials \u7684\u70ed\u5fc3\u6559\u5e08\u3002 \u51ed\u501f\u5728\u7edf\u8ba1\u9886\u57df\u7684\u4e30\u5bcc\u7ecf\u9a8c\u548c\u4e13\u4e1a\u77e5\u8bc6\uff0c\u6211\u6e34\u671b\u5206\u4eab\u6211\u7684\u77e5\u8bc6\uff0c\u901a\u8fc7 Statorials \u589e\u5f3a\u5b66\u751f\u7684\u80fd\u529b\u3002\u4e86\u89e3\u66f4\u591a","sameAs":["https:\/\/statorials.org\/cn"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts\/1241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/comments?post=1241"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts\/1241\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/media?parent=1241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/categories?post=1241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/tags?post=1241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}