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)


类似的还可以在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

用法大致一样。


卡方呢??

解答:

Pearson (χ2)
用这个函数rchisq(n, df)

rnorm(n,mean=x,sd=y)
n:生成n个随机数
mean:随机数的均值
sd:标准差
 
rnorm(10,mean=0,sd=1)   #产生10个平均值为0,方差为1的随机数
 [1]  0.08934727 -0.95494386 -0.19515038  0.92552126  0.48297852 -0.59631064 -2.18528684
[8] -0.67486594 -2.11906119 -1.26519802
 
runif(10,min=3,max=11)  #产生10个最小值为3,最大值为11
 [1]  3.604562  7.275414  8.130853  7.205915  3.314251  7.366879  5.982105 10.690419
 [9]  5.058733  4.663613

r 随机数的更多相关文章

  1. R语言:常用函数【转】

    数据结构 一.数据管理vector:向量 numeric:数值型向量 logical:逻辑型向量 character:字符型向量list:列表 data.frame:数据框 c:连接为向量或列表len ...

  2. 简单介绍一下R中的几种统计分布及常用模型

    统计学上分布有很多,在R中基本都有描述.因能力有限,我们就挑选几个常用的.比较重要的简单介绍一下每种分布的定义,公式,以及在R中的展示. 统计分布每一种分布有四个函数:d――density(密度函数) ...

  3. R9—R常用函数分类汇总

    数据结构 一.数据管理 vector:向量 numeric:数值型向量 logical:逻辑型向量 character:字符型向量 list:列表 data.frame:数据框 c:连接为向量或列表 ...

  4. R语言编程艺术(4)R对数据、文件、字符串以及图形的处理

    本文对应<R语言编程艺术> 第8章:数学运算与模拟: 第10章:输入与输出: 第11章:字符串操作: 第12章:绘图 =================================== ...

  5. 【R】R语言常用函数

    R语言常用函数 基本 一.数据管理vector:向量 numeric:数值型向量 logical:逻辑型向量character:字符型向量 list:列表 data.frame:数据框c:连接为向量或 ...

  6. R中基本函数学习[转载]

    转自:https://www.douban.com/note/511740050/ 1.数据管理 numeric:数值型向量 logical:逻辑型向量 character:字符型向量list:列表 ...

  7. R 基本函数总结

    基本一.数据管理 vector:向量 numeric:数值型向量 logical:逻辑型向量 character:字符型向量 list:列表 data.frame:数据框 c:连接为向量或列表 len ...

  8. R语言实战(第二版)-part 1笔记

    说明: 1.本笔记对<R语言实战>一书有选择性的进行记录,仅用于个人的查漏补缺 2.将完全掌握的以及无实战需求的知识点略去 3.代码直接在Rsudio中运行学习 R语言实战(第二版) pa ...

  9. Xdebug文档(四)函数跟踪

    Xdebug能让你把所有函数调用,包括参数和返回值以不同的格式记录到文件中. 这些号称“函数跟踪”功能能帮助你面对一个新应用程序,亦或者在程序运行时你想弄清楚它在做什么.函数跟踪功能可以选择性地显示函 ...

随机推荐

  1. Microsoft Corporation 去掉 windows 修改 启动加载 版权

    windows 修改 开机界面 boot启动界面 windows 修改 启动加载 版权 windows 系统如何修改开机画面的版权文字“Microsoft Corporation ... ◎Micro ...

  2. pojA Star not a Tree?

    题目链接 pojA Star not a Tree? 题解 啊,模拟退火是个好东西 模拟退火即可 代码 #include<cmath> #include<cstdio> #in ...

  3. 潭州课堂25班:Ph201805201 WEB 之 CSS 第二课 (课堂笔记)

    CSS 的引入方法: 第一种 : <!--直接在标签仙设置--><p style="color: yellow">CSS的第一种引入方法</p> ...

  4. post请求的header

    HTTP Headers 中的 HTTP请求 Accept-Encoding Accept-Encoding: gzip,deflate 大部分的现代浏览器都支持gzip压缩,并会把这一信息报告给服务 ...

  5. Voltage Translation for Analog to Digital Interface ADC

    Voltage Translation for Analog to Digital Interface 孕龙逻辑分析仪 ZeroPlus Logic Analyzer How to modify an ...

  6. 你现在还在手动生成set,get方法吗?使用lombok

    JAVA面向对象编程中的封闭性和安全性.封闭性即对类中的域变量进行封闭操作,即用private来修饰他们,如此一来其他类则不能对该变量访问.这样我们就将这些变量封闭在了类内部,这样就提高了数据的安全性 ...

  7. App架构师实践指南六之性能优化三

    App架构师实践指南六之性能优化三 2018年08月02日 13:57:57 nicolelili1 阅读数:190   内存性能优化1.内存机制和原理 1.1 内存管理内存时一个基础又高深的话题,从 ...

  8. Spring Boot中CrudRepository与JpaRepository Dao中JpaRepository和JpaSpecificationExecutor查询

    原文地址  https://blog.csdn.net/xuemengrui12/article/details/80525227?utm_source=blogxgwz0 https://www.i ...

  9. 【T05】套接字接口比XTI_TLI更好用

    1.用于网络编程的API接口有两种: Berkeley套接字 XTL 2.套接字是加州大学伯克利分校为其Unix操作系统版本开发的,TLI是AT&T(贝尔实验室)为Unix系统V3.0开发的 ...

  10. Spring ActiveMQ 整合(三): 确认机制ACK(收到消息后,应该有一个回应也就是确认答复)

    https://blog.csdn.net/dly1580854879/article/details/68490197