2016-03-10 42 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