{"id":180372,"date":"2024-05-08T20:34:02","date_gmt":"2024-05-08T12:34:02","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/180372.html"},"modified":"2024-05-08T20:34:17","modified_gmt":"2024-05-08T12:34:17","slug":"r%e8%af%ad%e8%a8%80%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90%e6%9c%8d%e4%bb%8e%e5%b8%95%e7%b4%af%e6%89%98%e5%88%86%e5%b8%83%e7%9a%84%e9%9a%8f%e6%9c%ba%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/180372.html","title":{"rendered":"R\u8bed\u8a00\u5982\u4f55\u751f\u6210\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27065600\/f944e78c-f8a6-4ed7-a1fc-6bdf5d9b9abe.webp\" alt=\"R\u8bed\u8a00\u5982\u4f55\u751f\u6210\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\" \/><\/p>\n<p><p>R\u8bed\u8a00\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u6cd5\u751f\u6210\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\uff0c<strong>\u5176\u4e2d\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528<code>rpareto<\/code>\u51fd\u6570\u3001\u901a\u8fc7\u9006\u53d8\u6362\u6cd5\u3001\u91c7\u7528\u81ea\u5b9a\u4e49\u51fd\u6570<\/strong>\u3002\u8fd9\u5176\u4e2d\uff0c<strong>\u4f7f\u7528<code>rpareto<\/code>\u51fd\u6570<\/strong>\u662f\u6700\u4e3a\u7b80\u4fbf\u76f4\u63a5\u7684\u65b9\u5f0f\uff0c\u8be5\u51fd\u6570\u5c5e\u4e8e<code>extraDistr<\/code>\u5305\uff0c\u80fd\u591f\u8ba9\u7528\u6237\u76f4\u63a5\u6307\u5b9a\u5f62\u72b6\u53c2\u6570\u548c\u5c3a\u5ea6\u53c2\u6570\u751f\u6210\u6240\u9700\u7684\u5e15\u7d2f\u6258\u5206\u5e03\u968f\u673a\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528<code>rpareto<\/code>\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>rpareto<\/code>\u51fd\u6570\u5c5e\u4e8eR\u8bed\u8a00\u7684<code>extraDistr<\/code>\u5305\uff0c\u8fd9\u4e2a\u5305\u5305\u542b\u4e86\u5927\u91cf\u7684\u5206\u5e03\u51fd\u6570\uff0c\u5305\u62ec\u5e15\u7d2f\u6258\u5206\u5e03\u3002\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u5e76\u8c03\u7528\u4e86<code>extraDistr<\/code>\u5305\u3002\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-R\">install.packages(&quot;extraDistr&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8f7d\u5165<code>extraDistr<\/code>\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-R\">library(extraDistr)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u7740\uff0c\u53ef\u4ee5\u4f7f\u7528<code>rpareto<\/code>\u51fd\u6570\u751f\u6210\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\u3002\u8be5\u51fd\u6570\u7684\u4e3b\u8981\u53c2\u6570\u5305\u62ec\u968f\u673a\u6570\u7684\u6570\u91cf\u3001\u5f62\u72b6\u53c2\u6570\uff08shape\uff09\uff0c\u4ee5\u53ca\u5c3a\u5ea6\u53c2\u6570\uff08scale\uff09\u3002\u5176\u4e2d\uff0c\u5f62\u72b6\u53c2\u6570\u548c\u5c3a\u5ea6\u53c2\u6570\u9700\u8981\u4e8b\u5148\u786e\u5b9a\uff0c\u5b83\u4eec\u51b3\u5b9a\u4e86\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u5177\u4f53\u5f62\u6001\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-R\"># \u751f\u6210100\u4e2a\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\uff0c\u5f62\u72b6\u53c2\u6570\u4e3a2\uff0c\u5c3a\u5ea6\u53c2\u6570\u4e3a3<\/p>\n<p>pareto_random_numbers &lt;- rpareto(n = 100, shape = 2, scale = 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u901a\u8fc7\u9006\u53d8\u6362\u6cd5<\/h3>\n<\/p>\n<p><p>\u9006\u53d8\u6362\u6cd5\u662f\u751f\u6210\u968f\u673a\u6570\u7684\u4e00\u79cd\u901a\u7528\u6280\u672f\uff0c\u9002\u7528\u4e8e\u591a\u79cd\u6982\u7387\u5206\u5e03\u3002\u5bf9\u4e8e\u5e15\u7d2f\u6258\u5206\u5e03\u800c\u8a00\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u751f\u6210\u4e00\u7cfb\u5217\u670d\u4ece[0,1]\u4e4b\u95f4\u5747\u5300\u5206\u5e03\u7684\u968f\u673a\u6570\u3002<\/li>\n<li>\u7136\u540e\uff0c\u5c06\u8fd9\u4e9b\u5747\u5300\u5206\u5e03\u968f\u673a\u6570\u901a\u8fc7\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u5206\u5e03\u51fd\u6570\u7684\u9006\u51fd\u6570\u8f6c\u6362\uff0c\u4ece\u800c\u83b7\u5f97\u76f8\u5e94\u7684\u5e15\u7d2f\u6258\u5206\u5e03\u968f\u673a\u6570\u3002<\/li>\n<\/ol>\n<p><p>\u5728R\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-R\"># \u8bbe\u5b9a\u5f62\u72b6\u53c2\u6570\u548c\u5c3a\u5ea6\u53c2\u6570<\/p>\n<p>shape &lt;- 2<\/p>\n<p>scale &lt;- 3<\/p>\n<h2><strong>\u751f\u6210100\u4e2a\u670d\u4ece[0,1]\u5747\u5300\u5206\u5e03\u7684\u968f\u673a\u6570<\/strong><\/h2>\n<p>uniform_random_numbers &lt;- runif(100)<\/p>\n<h2><strong>\u901a\u8fc7\u9006\u53d8\u6362\u6cd5\u8f6c\u6362\u4e3a\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570<\/strong><\/h2>\n<p>pareto_random_numbers_inverse &lt;- scale * (uniform_random_numbers)^(-1 \/ shape)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u91c7\u7528\u81ea\u5b9a\u4e49\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u73b0\u6210\u7684\u51fd\u6570\u548c\u9006\u53d8\u6362\u6cd5\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u6765\u751f\u6210\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\u3002\u8fd9\u79cd\u65b9\u6cd5\u5bf9\u4e8e\u7406\u89e3\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u751f\u6210\u673a\u7406\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u81ea\u5b9a\u4e49\u51fd\u6570\u793a\u4f8b\uff0c\u7528\u4e8e\u751f\u6210\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-R\"># \u5b9a\u4e49\u751f\u6210\u5e15\u7d2f\u6258\u5206\u5e03\u968f\u673a\u6570\u7684\u51fd\u6570<\/p>\n<p>generatePareto &lt;- function(n, shape, scale) {<\/p>\n<p>  u &lt;- runif(n)<\/p>\n<p>  return(scale * (u)^(-1 \/ shape))<\/p>\n<p>}<\/p>\n<h2><strong>\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u751f\u6210\u968f\u673a\u6570<\/strong><\/h2>\n<p>pareto_random_numbers_custom &lt;- generatePareto(100, 2, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7efc\u4e0a\uff0cR\u8bed\u8a00\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u65b9\u6cd5\u6765\u751f\u6210\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\uff0c\u5176\u4e2d\u4f7f\u7528<code>rpareto<\/code>\u51fd\u6570\u662f\u6700\u4e3a\u76f4\u63a5\u548c\u4fbf\u6377\u7684\u65b9\u6cd5\u3002\u540c\u65f6\uff0c\u901a\u8fc7\u9006\u53d8\u6362\u6cd5\u6216\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u7528\u6237\u53ef\u4ee5\u66f4\u6df1\u5165\u5730\u7406\u89e3\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u6027\u8d28\u548c\u968f\u673a\u6570\u751f\u6210\u7684\u539f\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u7528R\u8bed\u8a00\u751f\u6210\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\uff1f<\/strong><\/p>\n<p>\u5e15\u7d2f\u6258\u5206\u5e03\uff08Pareto Distribution\uff09\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u6982\u7387\u5206\u5e03\uff0c\u7528\u4e8e\u63cf\u8ff0\u5177\u6709\u957f\u5c3e\u5206\u5e03\u7684\u6570\u636e\u3002\u5728R\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>rpareto()<\/code>\u51fd\u6570\u6765\u751f\u6210\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\u3002\u8be5\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff1a<code>n<\/code>\u8868\u793a\u8981\u751f\u6210\u7684\u968f\u673a\u6570\u7684\u6570\u91cf\uff0c<code>alpha<\/code>\u8868\u793a\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u5f62\u72b6\u53c2\u6570\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u751f\u6210100\u4e2a\u670d\u4ece\u53c2\u6570\u4e3a2\u7684\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-R\">random_numbers &lt;- rpareto(100, alpha = 2)\n<\/code><\/pre>\n<p><strong>2. \u5e15\u7d2f\u6258\u5206\u5e03\u7684\u7279\u70b9\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p>\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u7279\u70b9\u662f\u5177\u6709\u957f\u5c3e\u5206\u5e03\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u7684\u5c3e\u90e8\u90e8\u5206\uff08\u53d6\u503c\u8f83\u5927\u7684\u90e8\u5206\uff09\u4e0b\u964d\u5f97\u975e\u5e38\u7f13\u6162\u3002\u8fd9\u610f\u5473\u7740\u5927\u90e8\u5206\u7684\u6982\u7387\u8d28\u91cf\u96c6\u4e2d\u5728\u5206\u5e03\u7684\u5de6\u4fa7\uff0c\u800c\u6781\u7aef\u503c\u7684\u51fa\u73b0\u6982\u7387\u76f8\u5bf9\u8f83\u9ad8\u3002<\/p>\n<p>\u5e15\u7d2f\u6258\u5206\u5e03\u7531\u4e00\u4e2a\u5f62\u72b6\u53c2\u6570\u6765\u63a7\u5236\uff0c\u8be5\u53c2\u6570\u5f71\u54cd\u4e86\u5206\u5e03\u7684\u201c\u5c3e\u91cd\u201d\u7a0b\u5ea6\u3002\u8f83\u5c0f\u7684\u5f62\u72b6\u53c2\u6570\u4f1a\u5bfc\u81f4\u66f4\u91cd\u7684\u5c3e\u90e8\uff0c\u800c\u8f83\u5927\u7684\u5f62\u72b6\u53c2\u6570\u4f1a\u5bfc\u81f4\u5c3e\u90e8\u53d8\u5f97\u66f4\u8f7b\u3002<\/p>\n<p><strong>3. \u5e15\u7d2f\u6258\u5206\u5e03\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u6709\u54ea\u4e9b\u7528\u9014\uff1f<\/strong><\/p>\n<p>\u5e15\u7d2f\u6258\u5206\u5e03\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5177\u6709\u5e7f\u6cdb\u7684\u7528\u9014\uff0c\u7279\u522b\u662f\u5728\u63cf\u8ff0\u4e0d\u5747\u8861\u6216\u957f\u5c3e\u6570\u636e\u65f6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u9886\u57df\uff1a<\/p>\n<ul>\n<li>\u91d1\u878d\u5b66\uff1a\u5e15\u7d2f\u6258\u5206\u5e03\u53ef\u7528\u4e8e\u5efa\u6a21\u91d1\u878d\u8d44\u4ea7\u7684\u56de\u62a5\u7387\uff0c\u4e00\u4e9b\u8d22\u52a1\u6307\u6807\u7684\u5206\u5e03\u4e5f\u5f80\u5f80\u7b26\u5408\u5e15\u7d2f\u6258\u5206\u5e03\u3002<\/li>\n<li>\u7ecf\u6d4e\u5b66\uff1a\u5728\u7ecf\u6d4e\u5b66\u4e2d\uff0c\u4e00\u4e9b\u73b0\u8c61\u5982\u6536\u5165\u5206\u5e03\u3001\u57ce\u5e02\u4eba\u53e3\u5206\u5e03\u7b49\u4e5f\u53ef\u4ee5\u7528\u5e15\u7d2f\u6258\u5206\u5e03\u8fdb\u884c\u5efa\u6a21\u3002<\/li>\n<li>\u751f\u6001\u5b66\uff1a\u5e15\u7d2f\u6258\u5206\u5e03\u53ef\u4ee5\u7528\u4e8e\u63cf\u8ff0\u7269\u79cd\u4e30\u5bcc\u5ea6\u5206\u5e03\u3001\u80fd\u91cf\u6d88\u8017\u5206\u5e03\u7b49\u751f\u6001\u5b66\u73b0\u8c61\u3002<\/li>\n<li>\u7f51\u7edc\u79d1\u5b66\uff1a\u7f51\u7edc\u8fde\u63a5\u7684\u5ea6\u5206\u5e03\u901a\u5e38\u7b26\u5408\u5e15\u7d2f\u6258\u5206\u5e03\uff0c\u8fd9\u5bf9\u4e8e\u7406\u89e3\u548c\u5206\u6790\u7f51\u7edc\u7684\u62d3\u6251\u7ed3\u6784\u975e\u5e38\u91cd\u8981\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u662f\u5e15\u7d2f\u6258\u5206\u5e03\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u4e00\u4e9b\u4f8b\u5b50\uff0c\u4f46\u5b83\u8fd8\u53ef\u4ee5\u7528\u4e8e\u5176\u4ed6\u9886\u57df\uff0c\u53ea\u8981\u6570\u636e\u7684\u5206\u5e03\u5177\u6709\u957f\u5c3e\u7279\u5f81\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"R\u8bed\u8a00\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u6cd5\u751f\u6210\u670d\u4ece\u5e15\u7d2f\u6258\u5206\u5e03\u7684\u968f\u673a\u6570\uff0c\u5176\u4e2d\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528rpareto\u51fd\u6570\u3001\u901a\u8fc7\u9006\u53d8\u6362\u6cd5\u3001\u91c7\u7528 [&hellip;]","protected":false},"author":3,"featured_media":180400,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/180372"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=180372"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/180372\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/180400"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=180372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=180372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=180372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}