Statistics

The package jhplot.stat can be used for descriptive analysis of random distributions

Normalised Factorial Moments (NFM)

As example, let us consider calculations of normalised factorial moments (NFM) for several distributions. They are defined as

F_q = \frac{ <n (n-1) .. (n+1-q)>}{<n>^q.

where ā€œnā€ is a random number (integer) number. According to this definition, a Poisson distribution has all moments equal to 1. A broader than a Poisson distribution have moments larger then one. Let us calculate the NFM up to 4th order for a Poisson distribution Binomial and a Negative-binomial distributions

example.py
from jhplot  import *
from jhplot.stat  import MomentsFacNorm
from cern.jet.random.engine import *
from cern.jet.random  import *
from jhplot.shapes  import Line
from java.awt import Color
 
c1 = HPlot("Canvas")
c1.visible(1)
c1.setNameX("NFM order")
c1.setNameY("Values")
c1.setRange(0,5,0,2) 
 
line = Line(0.0,1, 5., 1.) # draw  a vertical line in the NDC system
line.setPosCoord("USER"); line.setColor(Color.gray); line.setTransparency(0.5)
c1.add(line)
 
# build a random engine
engine=MersenneTwister()
 
poisson=Poisson(10,engine) # a Possonian distribution
m=MomentsFacNorm(4)        # calculates moments up to 4th order
 
for i in range(100):
        m.process( poisson.nextInt())
p1=m.getResults()
p1.setTitle("NFM for Poissson"); p1.setSymbol(4); p1.setSymbolSize(10)
c1.draw(p1)
print(p1.toString())
 
binomial=Binomial(10, 0.2, engine)  # Binomial distribution
m=MomentsFacNorm(4) # calculates moments up to 4th order
for i in range(200):
       m.process( binomial.nextInt())
p2=m.getResults(); p2.setTitle("NFM for Binomial"); p2.setSymbol(5); p2.setSymbolSize(10)
c1.draw(p2)
print(p2.toString())
 
nbinom=NegativeBinomial(10, 0.4, engine) # NegativeBinomial distribution (NBD)
m=MomentsFacNorm(4) 
for i in range(300):
       m.process( nbinom.nextInt())
p3=m.getResults(); p3.setTitle("NFM for NBD"); p3.setSymbol(6); p3.setSymbolSize(10)
c1.draw(p3)
print(p3.toString())

The output file shows the NFM for all three distributions together with statistical errors.

Read the book "Scientific data analysis using Jython scripting and Java for advanced examples.

statistics.txt · Last modified: 2010/07/03 16:58 by admin
Back to top
GNU Free Documentation License 1.2
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0