 |
Calculations of normalised factorial moments of several distributions
Source code name: "stat_normalized_moments.py"
Programming language: Python
Topic: Statistics/Advanced
DMelt Version 1. Last modified: 12/12/2015. License: Pro
https://datamelt.org/code/cache/stat_normalized_moments_4950.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from jhplot import *
from jhpro.stat import *
from cern.jet.random.engine import *
from cern.jet.random import *
from jhplot.shapes import Line
from java.awt import Color
c1 = HPlot("Canvas",600,400)
c1.visible(1)
c1.setNameX("q (Moment order)")
c1.setNameY("Normalized moment value")
c1.setRange(0,5,0,5)
# show a line in the NDC system
line = Line(0.0,1, 5., 1.)
line.setPosCoord("USER")
line.setColor(Color.gray)
line.setTransparency(0.5)
c1.add(line)
# build a random engine
engine=MersenneTwister()
poisson=Poisson(10,engine)
m=MomentsNorm(4) # calculates moments up to 4th order
# use a Poissonian random numbers
for i in range(100):
m.process( poisson.nextInt())
p1=m.getResults()
p1.setTitle("/^{q} for Poissson")
p1.setSymbol(4)
p1.setSymbolSize(10)
c1.draw(p1)
print(p1.toString())
## Binomial distribution
binomial=Binomial(10, 0.2, engine)
m=MomentsNorm(4) # calculates moments up to 4th order
for i in range(200):
m.process( binomial.nextInt())
p2=m.getResults()
p2.setTitle("/^{q} for Binomial")
p2.setSymbol(5)
p2.setSymbolSize(10)
c1.draw(p2)
print(p2.toString())
## NegativeBinomial distribution (NBD)
nbinom=NegativeBinomial(10, 0.4, engine)
m=MomentsNorm(4)
for i in range(300):
m.process( nbinom.nextInt())
p3=m.getResults()
p3.setTitle("/^{q} for NBD")
p3.setSymbol(6)
p3.setSymbolSize(10)
c1.draw(p3)
print(p3.toString())
You see the box below because you did not login.