帐号: 密码:
// 设为首页 // 收藏本站 // 请您留言 // 网址导航
远方教程-满足你的求知欲!
站内搜索:
HTML ASP PHP CSS DIV Dreamweaver Photoshop Word Excel PPT SEO技巧
您当前位置:网站首页 >> 统计之窗 >> R语言专区 >> R统计分析 >> 阅读文章

R技巧[01]:R生成各种常用分布随机数的方法

来源:远方教程 作者:远方教程 发布时间:2015-06-11 查看次数:6197 访问[新版]

  R软件一个显著的优点是它提供了丰富的随机数发生器,比SAS、Matlab方面很多,比Excel更不知方便到哪里去了。这无疑为统计学、工程学以及寿险精算学提供了很大的方便,比如我们要产生200个服从正态分布的随机数,在R里面用只需要键入“rnorm(200)”即可得到。操作如下:

>rnorm(200)

[1] -0.12071839  0.05257376 -0.23671186 -0.71413741  2.17362525 -0.25102710
[7] -1.41124223  1.78816754  0.95697026 -1.73518078 -0.71141662  1.27847876
[13] -1.50472436 -0.55267534  0.46788900  0.32977779  0.37641009 -1.22411512
[19] -1.82099431 -1.50026288......

  rnorm()函数更通用的用法是rnorm(n,mean,sd),其中n为要产生随机数的个数,mean为所产生随机数的总体所具有的均值,sd是所产生的随机数的总体所具有的标准差。

要产生服从均值为2,标准差为3的随机数100个,在R中:

>rnorm(n=100,mean=2,sd=3)

当然也可以更简便:

>rnorm(100,2,3)

  R软件生成各种常用分布随机数的方法

  类似的还可以在stat包里得到更多分布的随机数,一些对应函数如下:

rexp The Exponential Distribution
rf The F Distribution
rgamma The Gamma Distribution
rgeom The Geometric Distribution
rhyper The Hypergeometric Distribution
rlnorm The Log Normal Distribution
rlogis The Logistic Distribution
rmultinom The Multinomial Distribution
rnbinom The Negative Binomial Distribution
rnorm The Normal Distribution
rpois The Poisson Distribution
rsignrank Distribution of the Wilcoxon Signed Rank Statistic
rt The Student t Distribution
runif The Uniform Distribution
rweibull The Weibull Distribution
rwilcox Distribution of the Wilcoxon Rank Sum Statistic
rexp The Exponential Distribution
rf The F Distribution
rgamma The Gamma Distribution
rgeom The Geometric Distribution
rhyper The Hypergeometric Distribution
rlnorm The Log Normal Distribution
rlogis The Logistic Distribution
rmultinom The Multinomial Distribution
rnbinom The Negative Binomial Distribution
rnorm The Normal Distribution
rpois The Poisson Distribution
rsignrank Distribution of the Wilcoxon Signed Rank Statistic
rt The Student t Distribution
runif The Uniform Distribution
rweibull The Weibull Distribution
rwilcox Distribution of the Wilcoxon Rank Sum Statistic

用法大致一样。

打印 打印 | 关闭 关闭 评论
相关文章
图片新闻
站内搜索  
搜索
猜您喜欢  
最新更新  
阅读排行  
关于我们 | 联系方式 | 大事记 | 免责声明 | | 给我留言
部分广告源自金山联盟2345联盟 QQ咨询 站长之家QQ群:232617873
Copyright 2024 远方教程 © All Rights Reserved.

回顶部