我尝试用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,右侧有尾巴的漂亮图形。 请有经验的人帮我编写代码。
我尝试了一些代码,但是没有得到正确的形状。
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