2016-03-10 40 views
2

我尝试在perl中完成我在R中成功完成的任务,但很难与我的下游需求相结合。perl中的随机二项式分布式数据集

R中我做了以下

library("MASS") 
d <- rnegbin(100000, mu = 250, theta = 2) 
hist(d, breaks=1000, xlim=c(0,1000)) 

产生很好的图形,我需要有一个峰值一轮180-200和尾部右侧。

enter image description here

有人能帮助我的代码中使用数学::随机

我试过,但没有得到正确的形状perl的等效

use Math::Random qw(random_negative_binomial); 

# random_negative_binomial($n, $ne, $p) 
# When called in an array context, returns an array of $n outcomes 
# generated from the negative binomial distribution with number of 
# events $ne and probability of an event in each trial $p. 
# When called in a scalar context, generates and returns only one 
# such outcome as a scalar, regardless of the value of $n. 
# Argument restrictions: $ne is rounded using int(), the result must be positive. 
# $p must be between 0 and 1 exclusive. 

# I tried different variable values but never got the right shape 
my @dist = random_negative_binomial($n, $ne, $p); 

什么样的价值观,我需要模仿R结果? 我需要在同一范围内的X和总体形状相同

感谢您的帮助值,我没有找到那个包的说明例子

斯特凡

回答

1

我不知道很多有关统计,但是由于没有其他人提出:我会使用Perl数据语言PDL(我用于其他事情)并获取PDL :: Stats :: Distr模块。你可以在这里找到一个和你的有点相似的例子http://pdl-stats.sourceforge.net/Distr.htm。该模块包括pmf_binomial(mass函数)和mme_binomial(分布)。您还需要PGPLOT模块。

您将需要一些随机数据:

$data = pdl 1..100000; ## generate linear 1 - 100000 
    $data = $data->random;  ## make them random between 0..1