R中如何产生随机变量X~R(0,1)表示什么量

[整理] 利用R生成随机分布的…
[整理] 利用R生成随机分布的方法
夜里复习各种统计分布的模拟、拟合、验证的R编程,顺手整理一下。
(不懂怎么一回事,刚刚贴上了,然后一转眼就消失了。新浪博客里闹鬼?)
d: density
p: distribution function
q: quantile function
r: random deviates
rexp The Exponential Distribution
dexp(x, rate = 1, log = FALSE)
pexp(q, rate = 1, lower.tail = TRUE, log.p =
qexp(p, rate = 1, lower.tail = TRUE, log.p =
rexp(n, rate = 1)
rf The F Distribution
df1, df2, ncp, log = FALSE)
df1, df2, ncp, lower.tail = TRUE, log.p = FALSE)
df1, df2, ncp, lower.tail = TRUE, log.p = FALSE)
df1, df2, ncp)
rgamma The Gamma Distribution
dgamma(x, shape, rate = 1, scale = 1/rate, log =
pgamma(q, shape, rate = 1, scale = 1/rate,
lower.tail = TRUE, log.p = FALSE)
qgamma(p, shape, rate = 1, scale = 1/rate,
lower.tail = TRUE, log.p = FALSE)
rgamma(n, shape, rate = 1, scale = 1/rate)
rgeom The Geometric Distribution
dgeom(x, prob, log = FALSE)
pgeom(q, prob, lower.tail = TRUE, log.p =
qgeom(p, prob, lower.tail = TRUE, log.p =
rgeom(n, prob)
rhyper The Hypergeometric Distribution
dhyper(x, m, n, k, log = FALSE)
phyper(q, m, n, k, lower.tail = TRUE, log.p =
qhyper(p, m, n, k, lower.tail = TRUE, log.p =
rhyper(nn, m, n, k)
rlnorm The Log Normal Distribution
dlnorm(x, meanlog = 0, sdlog = 1, log =
plnorm(q, meanlog = 0, sdlog = 1, lower.tail =
TRUE, log.p = FALSE)
qlnorm(p, meanlog = 0, sdlog = 1, lower.tail =
TRUE, log.p = FALSE)
rlnorm(n, meanlog = 0, sdlog = 1)
rlogis The Logistic Distribution
dlogis(x, location = 0, scale = 1, log =
plogis(q, location = 0, scale = 1, lower.tail =
TRUE, log.p = FALSE)
qlogis(p, location = 0, scale = 1, lower.tail =
TRUE, log.p = FALSE)
rlogis(n, location = 0, scale = 1)
rmultinom The Multinomial Distribution
rmultinom(n, size, prob)
dmultinom(x, size = NULL, prob, log =
rnbinom The Negative Binomial Distribution
dnbinom(x, size, prob, mu, log = FALSE)
pnbinom(q, size, prob, mu, lower.tail = TRUE,
log.p = FALSE)
qnbinom(p, size, prob, mu, lower.tail = TRUE,
log.p = FALSE)
rnbinom(n, size, prob, mu)
rnorm The Normal Distribution
dnorm(x, mean = 0, sd = 1, log = FALSE)
pnorm(q, mean = 0, sd = 1, lower.tail = TRUE,
log.p = FALSE)
qnorm(p, mean = 0, sd = 1, lower.tail = TRUE,
log.p = FALSE)
rnorm(n, mean = 0, sd = 1)
rpois The Poisson Distribution
dpois(x, lambda, log = FALSE)
ppois(q, lambda, lower.tail = TRUE, log.p =
qpois(p, lambda, lower.tail = TRUE, log.p =
rpois(n, lambda)
rsignrank Distribution of the Wilcoxon Signed Rank
dsignrank(x, n, log = FALSE)
psignrank(q, n, lower.tail = TRUE, log.p =
qsignrank(p, n, lower.tail = TRUE, log.p =
rsignrank(nn, n)
rt The Student t Distribution
df, ncp, log = FALSE)
df, ncp, lower.tail = TRUE, log.p = FALSE)
df, ncp, lower.tail = TRUE, log.p = FALSE)
runif The Uniform Distribution
dunif(x, min=0, max=1, log = FALSE)
punif(q, min=0, max=1, lower.tail = TRUE, log.p =
qunif(p, min=0, max=1, lower.tail = TRUE, log.p =
runif(n, min=0, max=1)
rweibull The Weibull Distribution
dweibull(x, shape, scale = 1, log = FALSE)
pweibull(q, shape, scale = 1, lower.tail = TRUE,
log.p = FALSE)
qweibull(p, shape, scale = 1, lower.tail = TRUE,
log.p = FALSE)
rweibull(n, shape, scale = 1)
rwilcox Distribution of the Wilcoxon Rank Sum
dwilcox(x, m, n, log = FALSE)
pwilcox(q, m, n, lower.tail = TRUE, log.p =
qwilcox(p, m, n, lower.tail = TRUE, log.p =
rwilcox(nn, m, n)
sample The Discrete Uniform Distribution
sample(x, size, replace = FALSE, prob =
sample.int(n, size = n, replace = FALSE, prob =
连续型变量:
大样本:Kolmogorov-Smirnov检验
ks.test(x, y, ...,
alternative = c("two.sided", "less",
"greater"),
exact = NULL)
小样本:Shapiro-Wilk检验
shapiro.test(x)
离散型变量:方差齐次性检验
fligner.test(x, ...)
Default S3 method:
fligner.test(x, g, ...)
method for class 'formula'
fligner.test(formula, data, subset, na.action,
mood.test(x, ...)
Default S3 method:
mood.test(x, y,
alternative = c("two.sided",
"less", "greater"), ...)
method for class 'formula'
mood.test(formula, data, subset, na.action,
任意分布的随机数的产生方法
常用概率分布函数及随机特征
离散随机分布
用R生成随机数
随机分布生成
推导:通过均匀分布来产生任意分布随机数
3 概率分布与随机函数
关于用程序模拟的随机分布
python-检验33品种数据是否是正态分布
没有更多推荐了,【图文】随机变量的生成_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
享专业文档下载特权
&赠共享文档下载特权
&10W篇文档免费专享
&每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
随机变量的生成
阅读已结束,下载本文到电脑
定制HR最喜欢的简历
你可能喜欢[转载]用R语言求概率分布
用R语言求概率分布
RP(Xx)qP(Xx) & qx
Rrfunc(n,p1,p2,...)funcnp1, p2, . . .
& runif(10)
dpqr(dfunc(x, ...))(pfunc(x,...))(qfunc(p, ...)0&p&1)P5%
& qnorm(0.025)
& qnorm(0.975)
qnorm(0.05)1 - qnorm(0.95)
P{X = k} =
C400k * (0.02)^k *
(0.0=98)^(400-k)
P{X2} = 1 & P{X = 0} - P{X = 1}
& 1 - sum(pbinom(0:1, 400, 0.02))
X12X ~ N(1,
4)P{0&X1.6}
P{0&X1.6} = P{X1.6} - P{X0} = F(1.6) & F(0)
& pnorm(1.6, 1, 2) - pnorm(0, 1,
& X x2}=P{(x1-)/
(X-)/(x1-)/}=((x2-)/) -((x1-)/)
P{0&X1.6}=((1.6-1)/2) -((0-1)/2)
& pnorm((1.6-1)/2) - pnorm((0-1)/2)
#pnormmean=0,sd=1
设X是一个,x是任意,函数F(x)=P{X≤x}称为X的分布函数。
  对于任意实数x1,x2(x1<x2),有P{x1<X≤x2}=P{X≤x2}-P{X≤x1}=F(x2)-F(x1),
  因此,若已知X的分布函数,就可以知道X落在任一区间(x1,x2]上的概率,在这个意义上说,分布函数完整地描述了随机变量的。
  分布函数是一个普遍的函数,正是通过它,我们将能用数学分析的方法来研究随机变量。
如果将X看成是数轴上的随机点的,那么,分布函数F(x)在x处的就表示X落在区间(-∞,x]上的概率。
求标准正态分布的上α分位点。
X~N(0,1)Zα
P(X&Zα)=α0&α&1Zα标准正态分布的上α分位点.
注意上α分位点和R语言中qP(Xx) & qx
α=0.001、α=0.005、α=0.01、α=0.025时的上α分位点Zα
& exp &- expression_r(qnorm(1 -
& alpha = 0.001
& eval_r(exp)
& alpha = 0.005
& eval_r(exp)
& alpha = 0.01
& eval_r(exp)
& alpha = 0.025
& eval_r(exp)
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。求教大神一道关于指数随机变量的r程序【r语言吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:14,156贴子:
求教大神一道关于指数随机变量的r程序收藏
急急急!江湖救急啊。例4.8
-log(1-runif(n))
登录百度帐号苹果/安卓/wp
积分 14, 距离下一级还需 10 积分
道具: 涂鸦板, 彩虹炫, 雷达卡, 热点灯
购买后可立即获得
权限: 隐身
道具: 金钱卡, 变色卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
如下所述:
cdf 的反函数分别是x=(2u)^1/2 u是小于1/2的, x=2-(2-2u)^1/2&&u是大于等于1/2的
我的方法是先产生n个[0,1]均匀分布,再判断每一个u的大小,然后带到不同式子里,最后产生这个CDF的随机样本
simfx=function(n)
u=runif(n)
for(i in 1:n)
while(t&n)
if(u[i]&(1/2))
x=(2*u)^(1/2)
output[t]=x
else((1/2)&=u[i])
x=2-(2-2*u)^(1/ 2)
output[t]=x
程序如上,不知道 为什么总是运行不了,求高人解答,实在太感谢了。
your code has a few problems,&&try the following and see if it does what you need (i only fixed the code, you'll need to make sure the statistics is right, thanks)
simfx=function(n) {
&&output=array(0,dim=n)
&&u=runif(n)
&&for(i in 1:n) {
& &&&if(u[i]& 0.5) {
& && && &x=(2*u[i])^(1/2)
& && && &output[i]=x
& &&&else {
& && && &x=2-(2-2*u[i])^(1/2)
& && && &output[i]=x
热心帮助其他会员
总评分:&论坛币 + 30&
fortr_cc 发表于
your code has a few problems,&&try the following and see if it does what you need (i only fixed the&&...you don't need the x, can just do output=(2*u)^(1/2) for the 1st branch, and output=2-(2-2*u)^(1/2) for the 2nd.
fortr_cc 发表于
you don't need the x, can just do output=(2*u)^(1/2) for the 1st branch, and output=2-(2-2*u)^(1/2 ...I fixed it as your suggestions, but it still was not working.
anyway, thanks
错误于output[t] = 2 - (2 - 2 * u)^(1/2) : 类别为'closure'的下标不对
此外: 警告信息:
1: In output = (2 * u)^(1/2) : 被替换的项目不是替换值长度的倍数
试试这一句
ifelse(runif(100)&0.5,sqrt(2*x),2-sqrt(2-2*x))复制代码
热心帮助其他会员
总评分:&论坛币 + 10&
whx229 发表于
I fixed it as your suggestions, but it still was not working.
anyway, thanks
错误于output[t] = 2 ...sorry i forgot the u, i thought you noticed the u in my longer code,&&you only need to remove the x in the longer code.& &(without u you'll get an error)
this is certainly the basic way of writing it out,&&for someone versed in R, he could likely write it in just one line of code
热心帮助其他会员
总评分:&论坛币 + 20&
fortr_cc 发表于
sorry i forgot the u, i thought you noticed the u in my longer code,&&you only need to remove the&&...now i see why, the system automatically removed [ i ] ,&&it should be u [ i ], not u,&&the error you got is because of not using the index [ i ] for u&&(see the code above and remove x)&&
nuomin 发表于
试试这一句your answer is very neat, it only needs a minor modification to get what was asked for,
simfx=function(n) {
&&u=runif(n);&&output=ifelse(u&0.5, sqrt(2*u), 2-sqrt(2-2*u))
fortr_cc 发表于
your answer is very neat, it only needs a minor modification to get what was asked for,
simfx= ...函数不用显式的定义了,传递的参数就是虚拟函数
nuomin 发表于
函数不用显式的定义了,传递的参数就是虚拟函数not quite understand what you mean, i think he wanted sth that can be controlled by an input n, sth like
& v1=simfx(5); v1
[1] 0.....6568320
& v2=simfx(10); v2
[1] 0..........3401155
the line you provided forced n=100, also, it got an error since the x was likely undefined and not related to the runif(100).& &thanks.& &
初级热心勋章
初级热心勋章
中级热心勋章
中级热心勋章
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
论坛法律顾问:王进律师

我要回帖

更多关于 随机变量X~R(0,2) 的文章

 

随机推荐