r 随机数
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)
r 随机数的更多相关文章
- R语言:常用函数【转】
数据结构 一.数据管理vector:向量 numeric:数值型向量 logical:逻辑型向量 character:字符型向量list:列表 data.frame:数据框 c:连接为向量或列表len ...
- 简单介绍一下R中的几种统计分布及常用模型
统计学上分布有很多,在R中基本都有描述.因能力有限,我们就挑选几个常用的.比较重要的简单介绍一下每种分布的定义,公式,以及在R中的展示. 统计分布每一种分布有四个函数:d――density(密度函数) ...
- R9—R常用函数分类汇总
数据结构 一.数据管理 vector:向量 numeric:数值型向量 logical:逻辑型向量 character:字符型向量 list:列表 data.frame:数据框 c:连接为向量或列表 ...
- R语言编程艺术(4)R对数据、文件、字符串以及图形的处理
本文对应<R语言编程艺术> 第8章:数学运算与模拟: 第10章:输入与输出: 第11章:字符串操作: 第12章:绘图 =================================== ...
- 【R】R语言常用函数
R语言常用函数 基本 一.数据管理vector:向量 numeric:数值型向量 logical:逻辑型向量character:字符型向量 list:列表 data.frame:数据框c:连接为向量或 ...
- R中基本函数学习[转载]
转自:https://www.douban.com/note/511740050/ 1.数据管理 numeric:数值型向量 logical:逻辑型向量 character:字符型向量list:列表 ...
- R 基本函数总结
基本一.数据管理 vector:向量 numeric:数值型向量 logical:逻辑型向量 character:字符型向量 list:列表 data.frame:数据框 c:连接为向量或列表 len ...
- R语言实战(第二版)-part 1笔记
说明: 1.本笔记对<R语言实战>一书有选择性的进行记录,仅用于个人的查漏补缺 2.将完全掌握的以及无实战需求的知识点略去 3.代码直接在Rsudio中运行学习 R语言实战(第二版) pa ...
- Xdebug文档(四)函数跟踪
Xdebug能让你把所有函数调用,包括参数和返回值以不同的格式记录到文件中. 这些号称“函数跟踪”功能能帮助你面对一个新应用程序,亦或者在程序运行时你想弄清楚它在做什么.函数跟踪功能可以选择性地显示函 ...
随机推荐
- babel和postcss引起的一点儿思考
写es6,一般都会用到babel,它能把es6转为更好的es5,而es5可以直接在浏览器上运行.postcss是css界的babel,它可以把css转为更好的css,比如autoprefixer,让不 ...
- BZOJ.3667.Rabin-Miller算法(MillerRabin PollardRho)
题目链接 Pollard_Rho:http://blog.csdn.net/thy_asdf/article/details/51347390 #include<cstdio> #incl ...
- 潭州课堂25班:Ph201805201 WEB 之 jQuery 第七课 (课堂笔记)
jq 的导入 <body> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">< ...
- 在web.xml中设置全局编码
在web.xml中配置 <filter> <filter-name>characterFilter</filter-name> <filter-class&g ...
- 429. N叉树的层序遍历
429. N叉树的层序遍历 题意 给定一个 N 叉树,返回其节点值的层序遍历. (即从左到右,逐层遍历). 解题思路 和二叉树的层次遍历的思想一样: 实现 class Solution(object) ...
- 支付宝集成遇到"_EVP_DecodeBlock",referenced from:报错
遇到问题报错如下: 调试了好多遍,始终不行,检测各种依赖库,发现并没有少什么.后来发现支付宝demo里比文档讲解里面多两个.a文件 直接加上就好了
- Hbase多版本的读写(Shell&Java API版)
Hbase是基于HDFS的NOsql数据库,它很多地方跟数据库差不多,也有很多不同的地方.这里就不一一列举了,不过Hbase有个版本控制的特性,这个特性在很多场景下都会发挥很大的作用.本篇就介绍下基于 ...
- react Immutability 理解
在开发过程中经常会遇到state里有数组和对象的情况,比如当用splice去改变数组再调用setState更新的时候,会发现并没有生效,这是因为react里的state是Immutability(不可 ...
- uva 1629切蛋糕(dp)
有一个n行m列的网格蛋糕,上面有一些樱桃.求使得每块蛋糕上都有一个樱桃的分割最小长度 思路:dp. #include<cstdio> #include<cstring> #in ...
- caffe中的fine-tuning
caffe finetune两种修改网络结构prototxt方法 第一种方法:将原来的prototxt中所有的fc8改为fc8-re.(若希望修改层的学习速度比其他层更快一点,可以将lr_mult改为 ...