#### Topic: BinomialRandomVariable p<.5

BinomialRandomVariable appears to give off results for P<.5

p>0.5 looks fine, I don't seem to be able to attach more that one file so I have attached the P<0.5 version.
With P=0.501 the mean was 10.059E00 but with P=0.499 it is 11.498E00 as you can see from the attached pdf a big dip where the bigest value would be expected.

I may have done something silly but can't see where to look for it.

Plotting the values from d1 in excel shows the same as the plot produced here.

this is my script:

from jhplot.math.num.random import *
from jhplot  import HPlot,H1D,HTable,HLabel,P0D
from jhplot.io.csv import *
p=0.5-0.001
s=20
n=1000
x1= BinomialRandomVariable(s,p)
d1=P0D("%s/%s"%(s,p))

c1 = HPlot("Canvas",600,400,1, 1)
c1.visible(1)
#c1.setAutoRange()
h1 = H1D("%s/%s"%(s,p),2*s+1, 0, s)

z=[]
for i in range(2*s+1+2):
z.append(0)

for i in range(n):
y1=x1.nextRandomVariable()
h1.fill(y1)
h1.setErrors(z)
c1.draw(h1)
c1.setAutoRange()
c1.drawStatBox(h1)
lab=HLabel("%s samples"%n, 0.15, 0.7, "NDC")
c1.update()

#### Re: BinomialRandomVariable p<.5

Hello,

Thanks. This does look like an error in the implementation but we will need to look at.

For now, please use several other implementations:

cern.jet.random.Binomial

or

umontreal.iro.lecuyer.randvar.BinomialGen

or

org.apache.commons.math.distribution.BinomialDistributionImpl

See details in : http://jwork.org/jhepwork/api_extra/

best wishes, Sergei

#### Re: BinomialRandomVariable p<.5

Just to confirm: this implementation does not have this problem:

``````from jhplot  import *
from jhplot.io.csv import *

p=0.5-0.01
s=20
n=1000
# x1= BinomialRandomVariable(s,p) # error

from cern.jet.random.engine import *
from cern.jet.random import *
engine = MersenneTwister()
x1=Binomial(s, p, engine)

c1 = HPlot("Canvas",600,400,1, 1)
c1.visible(1)
c1.setAutoRange()
h1 = H1D("%s/%s"%(s,p),2*s+1, 0, s)
h1.setErrAll(0)
for i in range(n):
y1=x1.nextInt()
h1.fill(y1)

c1.draw(h1)
c1.drawStatBox(h1,375,30)
lab=HLabel("%s samples"%n, 0.15, 0.7, "NDC")