Perl中的随机二项分布数据集

3

我尝试用Perl实现我在R中成功实现的功能,但很难与我的下游需求结合。

在R中,我进行了以下操作:

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

使用Math::Random编写perl等效代码,以产生我需要的峰值约为180-200,右侧有尾巴的漂亮图形。

enter image description here

请有经验的人帮我编写代码。
我尝试了一些代码,但是没有得到正确的形状。
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值和相似的形状。

非常感谢您的帮助,我没有找到该软件包的图示例。

Stephane

1个回答

1
我不太了解统计学,但由于没有其他人提出建议:我会使用Perl数据语言PDL(我用于其他事情),并获取PDL :: Stats :: Distr模块。您可以在此处找到一个与您的相似的示例http://pdl-stats.sourceforge.net/Distr.htm。该模块包括pmf_binomial(质量函数)和mme_binomial(分布)。您还需要PGPLOT模块。
您需要一些随机数据:
    $data = pdl  1..100000;    ## generate linear 1 - 100000
    $data = $data->random;     ## make them random between 0..1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接