R语言中实现随机分布

非常多的应用需要用到随机数,而R语言在simulating random numbers非常的有强大的工具可供使用。

在R中各种概率函数都有统一的形式,即一套统一的 前缀+分布函数名

如:

1.  r*** function (for "random"随机函数), a d*** function (for "density"密度函数), a p*** (for "probability"分布函数), and q*** (for "quantile"分位数函数).

dbinom(x, size, prob, log = FALSE)
pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
rbinom(n, size, prob) 

2.  不同的分布函数:

rnorm(n, mean=0, sd=1) #正态分布 rf(n, df1, df2, ncp) #f 分布
rexp(n, rate=1) #指数 rchisq(n, df, ncp=0) #卡方分布
rgamma(n, shape, rate=1, scale=1/rate) #r 分布 rbinom(n, size, prob) #二项分布
rpois(n, lambda) #泊松 rweibull(n, shape, scale=1) #weibull 分布
rt(n, df, ncp) #t 分布 rbata(n, shape1, shape2) #bata 分布

 

                                                      下面会具体介绍几个非常实用的 函数:


sample()

首先介绍sample()随机抽样函数:

> sample
function (x, size, replace = FALSE, prob = NULL) 
{
    if (length(x) == 1L && is.numeric(x) && is.finite(x) && x >= 
        1) {
        if (missing(size)) 
  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值