{"id":185,"date":"2011-05-09T09:22:46","date_gmt":"2011-05-09T17:22:46","guid":{"rendered":"http:\/\/zhanxw.com\/blog\/?p=185"},"modified":"2011-05-09T09:22:46","modified_gmt":"2011-05-09T17:22:46","slug":"%e5%a6%82%e4%bd%95%e6%a3%80%e9%aa%8c%e4%b8%80%e7%bb%b4%e6%95%b0%e6%8d%ae%e7%9a%84%e5%88%86%e5%b8%83","status":"publish","type":"post","link":"https:\/\/zhanxw.com\/blog\/2011\/05\/%e5%a6%82%e4%bd%95%e6%a3%80%e9%aa%8c%e4%b8%80%e7%bb%b4%e6%95%b0%e6%8d%ae%e7%9a%84%e5%88%86%e5%b8%83\/","title":{"rendered":"\u5982\u4f55\u68c0\u9a8c\u4e00\u7ef4\u6570\u636e\u7684\u5206\u5e03"},"content":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\uff32\u8f6f\u4ef6\u6765\u5206\u6790\u4e00\u7ef4\u968f\u673a\u53d8\u91cf\u3002\u5206\u6790\u7684\u5185\u5bb9\u5305\u62ec\u5982\u4f55\u67e5\u627e\u4e00\u7ef4\u6570\u636e\u7684\u5206\u5e03\u7c7b\u578b\uff0c\u5982\u4f55\u4f30\u8ba1\u5206\u5e03\u53c2\u6570\u4ee5\u53ca\u5982\u4f55\u7528\u5047\u8bbe\u68c0\u9a8c\u6765\u6d4b\u8bd5\u4e00\u7ef4\u6570\u636e\u7684\u5206\u5e03\u7c7b\u578b\u3002<br \/>\nHow to find, fit, test the distribution of univariate variable in R?<br \/>\n\u6211\u4eec\u7ecf\u5e38\u89c1\u5230\u4e00\u7ef4\u968f\u673a\u53d8\u91cf\uff0c\u6bd4\u5982\u7ebf\u6027\u6a21\u578b\u7684\u54cd\u5e94\uff0c\u6211\u4eec\u901a\u5e38\u9700\u8981\u68c0\u9a8c\u5b83\u662f\u5426\u662f\u6b63\u6001\u5206\u5e03\u6765\u51b3\u5b9a\u6a21\u578b\u4e2d\u76f4\u63a5\u7528\uff39\u8fd8\u662f\u7528log\uff08\uff39\uff09\uff0c\u6216\u8005\u5176\u4ed6\u7684transformation\u3002<br \/>\n\u672c\u6587\u4e3b\u8981\u53c2\u8003\u30101\u3011\uff0c\u6211\u4f1a\u4ecb\u7ecd\u4e00\u4e9b\u57fa\u672c\u7684\u65b9\u6cd5\uff0c\u4f46\u5efa\u8bae\u8bfb\u8005\u53c2\u8003\u539f\u6587\u83b7\u5f97\u66f4\u591a\u7684\u4fe1\u606f\u3002<\/p>\n<p>1. \u753b\u5bc6\u5ea6\u56fe\uff0c\uff23\uff24\uff26\u56fe<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n\u76f4\u65b9\u56fe\uff1ahistory(x)\r\n\u5bc6\u5ea6\u56fe\uff1aplot(density(x))\r\nCDF\u56fe\uff1aplot(ecdf(x))\r\n<\/pre>\n<p>\u68c0\u67e5\u662f\u5426\u662f\u6b63\u6001\u5206\u5e03\uff1a<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\nz= (x-mean(x))\/sd(x)\r\nqqnorm(z)\r\nabline(0,1)\r\n<\/pre>\n<p>\u7c7b\u4f3c\u7684\u53ef\u4ee5\u68c0\u67e5\u5176\u4ed6\u5206\u5e03\uff08\u5148\u6784\u9020\u4e00\u4e2a\u7406\u8bba\u5206\u5e03\uff0c\u518dqqnorm\uff09<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\nx.wei &lt;- rweibull(200, shape=2.1, scale=1.1)\r\nx.teo &lt;- rweibull(200, shape=2.1, scale=1.0)\r\nqqplot(x.teo, x.wei)\r\nabline(0,1)\r\n<\/pre>\n<p>http:\/\/www.statsoft.com\/textbook\/distribution-fitting\/<\/p>\n<p>2. \u5229\u7528\u77e9\u4f30\u8ba1\u731c\u6d4b\u5206\u5e03\u7c7b\u578b<br \/>\n\u4e3b\u8981\u662fstandardize\u4e4b\u540e\u8ba1\u7b97\u4e00\u4e8c\u4e09\u56db\u9636\u77e9\uff08moment\uff09\uff0c\u7136\u540e\u5bf9\u6bd4\u4e0b\u9762\u7f51\u9875\u5217\u4e3e\u7684\u5e38\u89c1\u5206\u5e03\uff0c\u731c\u51fa\u5230\u5e95\u662f\u54ea\u4e00\u79cd\u5206\u5e03\uff1a<br \/>\n<a href=\"http:\/\/www.itl.nist.gov\/div898\/handbook\/eda\/section3\/eda35b.htm\">NIST 1.3.5.11. Measures of Skewness and Kurtosis<\/a><\/p>\n<p>3. \u4f30\u8ba1\u5206\u5e03\u53c2\u6570<br \/>\n\u5f53\u6211\u4eec\u77e5\u9053\u5206\u5e03\u7c7b\u578b\u540e\uff0c\u53ef\u4ee5\u4f30\u8ba1\u5206\u5e03\u53c2\u6570\uff0c\u5e38\u89c1\u7684\u6709\u77e9\u4f30\u8ba1\u548c\u6700\u5927\u4f3c\u7136\u4f30\u8ba1\u3002<br \/>\n\u77e9\u4f30\u8ba1\u76f8\u5bf9\u7b80\u5355\uff0c\u53ef\u4ee5\u7528mean\uff0cvar\u51fd\u6570\u8ba1\u7b97\uff0c\u4f46\u53ef\u80fd\u4e0d\u5177\u6709\u65e0\u504f\u7684\u6027\u8d28\u3002<br \/>\n\u6700\u5927\u4f3c\u7136\u4f30\u8ba1\u6709<br \/>\n1) mle() \u5728 stats4 \u5305\u91cc<br \/>\n2) fitdistr() \u5728 MASS \u5305\u91cc<br \/>\n1\uff09\u7684\u65b9\u6cd5\u663e\u7136\u66f4\u57fa\u672c\uff0c\u4f46\u80fd\u9002\u7528\u4e8e\u5404\u79cd\u5206\u5e03\uff0c2\uff09\u7684\u65b9\u6cd5\u4f7f\u7528\u7b80\u5355\uff0c\u5bf9Gamma, Weibull, Normal\u7b49\u5206\u5e03\u53ea\u9700\u8981\u4e00\u4e2a\u547d\u4ee4\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\nfitdistr(x.norm,&quot;normal&quot;) ## fitting gaussian pdf parameters \r\nmean\tsd\r\n9.9355373 2.0101691 \r\n(0.1421404) (0.1005085)\r\n<\/pre>\n<p>4. \u68c0\u67e5\u5206\u5e03\u662f\u5426\u5408\u9002\uff1f<br \/>\n\u5728\u505aGoodness of fit tests\u4e4b\u524d\uff0c\u53ef\u4ee5\u5148\u753b\u51fa\u76f4\u65b9\u56fe\u548c\u7406\u8bba\u5bc6\u5ea6\u5206\u5e03\u56fe\u3002<br \/>\n\u4e4b\u540e\uff0c\u53ef\u4ee5\u5229\u7528\u5361\u65b9\u68c0\u9a8c\u6765\u505aGoodness of fit tests\u3002\u5177\u4f53\u6765\u8bb2\uff1a<br \/>\ni) \u5bf9\u4e8ePoisson, binomial, negative binomail, \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528vcd\u5305\u4e2d\u7684goodfit\u51fd\u6570\u3002<br \/>\nii) \u5bf9\u4e8e\u4e00\u822c\u7684\u5206\u5e03\uff0c\u53ef\u4ee5\u628a\u53d8\u91cf\u5f52\u7c7b\uff0c\u7136\u540e\u5229\u7528\u5361\u65b9\u68c0\u9a8c\u516c\u793a\u8ba1\u7b97\u89c2\u5bdf\u5230\u53d8\u91cf\u6570\u91cf\u548c\u7406\u8bba\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\uff0c\u7136\u540e\u8ba1\u7b97pvalue<br \/>\niii) \u5bf9\u4e8e\u4e00\u822c\u7684\u5206\u5e03\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528Kolmogorov-Smirnov test\u6765\u505a\u7edf\u8ba1\u68c0\u9a8c<\/p>\n<p>\u5bf9\u7b2c\u4e09\u79cd\u60c5\u51b5\u4e3e\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n&gt; x.wei &lt;- rweibull(n=200, shape=2.1, scale = 1.1)\r\n&gt; ks.test(x.wei, &quot;pweibull&quot;, shape=2, scale= 1)\r\n\r\n\tOne-sample Kolmogorov-Smirnov test\r\n\r\ndata:  x.wei \r\nD = 0.1042, p-value = 0.02591\r\nalternative hypothesis: two-sided \r\n<\/pre>\n<p>\u7279\u522b\u7684\uff0c\u6211\u4eec\u9700\u8981\u68c0\u67e5\u6570\u636e\u662f\u5426\u662f\u6b63\u6001\u5206\u5e03\u3002<br \/>\n\u6700\u5e38\u7528\u7684\u662fShapiro\uff0dWilk test\uff1ashapiro.test()<br \/>\n\u6b64\u5916\uff0cR\u91cc\u9762\u6709\u4e00\u4e2apackage nortest\uff0c\u63d0\u4f9b\u4e86\u53e6\u59165\u79cd\u68c0\u67e5\u6b63\u6001\u5206\u5e03\u7684\u51fd\u6570\uff1a<br \/>\ni) Shapiro-Francia test: sf.test()<br \/>\nii) Anderson-Darling test: ad.test()<br \/>\niii) Cramer-Von Mises test: cvm.test()<br \/>\niv) Lilliefors test: lillie.test() \u9002\u7528\u4e8e\u5c0f\u6837\u672c\uff0c\u53c2\u6570\u672a\u77e5\u7684\u6b63\u6001\u5206\u5e03<br \/>\nv) pearson.test: pearson.test()<br \/>\n\u8fd95\u79cdtest\u5404\u6709\u7ec6\u81f4\u7684\u5dee\u5f02\uff0c\u4f7f\u7528\u7684\u65f6\u5019\u9700\u81ea\u5df1\u533a\u5206\u3002<\/p>\n<p>\u53c2\u8003\u6587\u732e\uff1a<br \/>\n\u30101\u3011 http:\/\/cran.r-project.org\/doc\/contrib\/Ricci-distributions-en.pdf<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\uff32\u8f6f\u4ef6\u6765\u5206\u6790\u4e00\u7ef4\u968f\u673a\u53d8\u91cf\u3002\u5206\u6790\u7684\u5185\u5bb9\u5305\u62ec\u5982\u4f55\u67e5\u627e\u4e00\u7ef4\u6570\u636e\u7684\u5206\u5e03\u7c7b\u578b\uff0c\u5982\u4f55\u4f30\u8ba1\u5206\u5e03\u53c2\u6570\u4ee5\u53ca\u5982\u4f55\u7528\u5047\u8bbe\u68c0\u9a8c\u6765\u6d4b\u8bd5\u4e00\u7ef4\u6570\u636e\u7684\u5206\u5e03\u7c7b\u578b\u3002 How to find, fit, test the distribution of univariate variable in R? \u6211\u4eec\u7ecf\u5e38\u89c1\u5230\u4e00\u7ef4\u968f\u673a\u53d8\u91cf\uff0c\u6bd4\u5982\u7ebf\u6027\u6a21\u578b\u7684\u54cd\u5e94\uff0c\u6211\u4eec\u901a\u5e38\u9700\u8981\u68c0\u9a8c\u5b83\u662f\u5426\u662f\u6b63\u6001\u5206\u5e03\u6765\u51b3\u5b9a\u6a21\u578b\u4e2d\u76f4\u63a5\u7528\uff39\u8fd8\u662f\u7528log\uff08\uff39\uff09\uff0c\u6216\u8005\u5176\u4ed6\u7684transformation\u3002 \u672c\u6587\u4e3b\u8981\u53c2\u8003\u30101\u3011\uff0c\u6211\u4f1a\u4ecb\u7ecd\u4e00\u4e9b\u57fa\u672c\u7684\u65b9\u6cd5\uff0c\u4f46\u5efa\u8bae\u8bfb\u8005\u53c2\u8003\u539f\u6587\u83b7\u5f97\u66f4\u591a\u7684\u4fe1\u606f\u3002 1. \u753b\u5bc6\u5ea6\u56fe\uff0c\uff23\uff24\uff26\u56fe \u76f4\u65b9\u56fe\uff1ahistory(x) \u5bc6\u5ea6\u56fe\uff1aplot(density(x)) CDF\u56fe\uff1aplot(ecdf(x)) \u68c0\u67e5\u662f\u5426\u662f\u6b63\u6001\u5206\u5e03\uff1a z= (x-mean(x))\/sd(x) qqnorm(z) abline(0,1) \u7c7b\u4f3c\u7684\u53ef\u4ee5\u68c0\u67e5\u5176\u4ed6\u5206\u5e03\uff08\u5148\u6784\u9020\u4e00\u4e2a\u7406\u8bba\u5206\u5e03\uff0c\u518dqqnorm\uff09 x.wei &lt;- rweibull(200, shape=2.1, scale=1.1) x.teo &lt;- rweibull(200, shape=2.1, scale=1.0) qqplot(x.teo, x.wei) abline(0,1) http:\/\/www.statsoft.com\/textbook\/distribution-fitting\/ 2. \u5229\u7528\u77e9\u4f30\u8ba1\u731c\u6d4b\u5206\u5e03\u7c7b\u578b \u4e3b\u8981\u662fstandardize\u4e4b\u540e\u8ba1\u7b97\u4e00\u4e8c\u4e09\u56db\u9636\u77e9\uff08moment\uff09\uff0c\u7136\u540e\u5bf9\u6bd4\u4e0b\u9762\u7f51\u9875\u5217\u4e3e\u7684\u5e38\u89c1\u5206\u5e03\uff0c\u731c\u51fa\u5230\u5e95\u662f\u54ea\u4e00\u79cd\u5206\u5e03\uff1a NIST 1.3.5.11. Measures of Skewness and Kurtosis 3. \u4f30\u8ba1\u5206\u5e03\u53c2\u6570 \u5f53\u6211\u4eec\u77e5\u9053\u5206\u5e03\u7c7b\u578b\u540e\uff0c\u53ef\u4ee5\u4f30\u8ba1\u5206\u5e03\u53c2\u6570\uff0c\u5e38\u89c1\u7684\u6709\u77e9\u4f30\u8ba1\u548c\u6700\u5927\u4f3c\u7136\u4f30\u8ba1\u3002 \u77e9\u4f30\u8ba1\u76f8\u5bf9\u7b80\u5355\uff0c\u53ef\u4ee5\u7528mean\uff0cvar\u51fd\u6570\u8ba1\u7b97\uff0c\u4f46\u53ef\u80fd\u4e0d\u5177\u6709\u65e0\u504f\u7684\u6027\u8d28\u3002 \u6700\u5927\u4f3c\u7136\u4f30\u8ba1\u6709 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[44,45,46,19,43],"class_list":["post-185","post","type-post","status-publish","format-standard","hentry","category-statistics","tag-distribution","tag-r","tag-stat","tag-statistics-2","tag-univariate"],"_links":{"self":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/comments?post=185"}],"version-history":[{"count":0,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/185\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/media?parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/categories?post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/tags?post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}