random binomial distributed dataset in perl

Viewed 264

I try to do in perl what I succeedd in R but is difficult to combine with my downstream needs.

in R I did the following

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

producing the nice graph I need with a peak round 180-200 and a tail to the right.

enter image description here

Could someone help me code the perl equivalent using Math::Random

I tried this but do not get the right shape

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);

what values do I need to mimic the R results? I need the same range of values on X and the same general shape

Thanks for any help, I did not find illustrated examples of that package

Stephane

1 Answers
Related