Statistical comparisons. Kolmogorov Smirnov (KS), Anderson-Darling, Goodman
Source code name: "stat_comparisons.py"
Programming language: Python
Topic: Statistics/Tests
DMelt Version 1. Last modified: 12/11/2015. License: Free
https://datamelt.org/code/cache/stat_comparisons_2482.py
To run this script using the DataMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from java.awt import Color
from java.util import Random
from jhplot import *
c1 = HPlotJa("Canvas")
c1.setGTitle("Statistical comparisons")
c1.setAutoRange()
c1.visible()
h1 = H1D("Histo1",20, -2, 2.0)
h1.setColor(Color.blue)
h2 = H1D("Histo2",20, -2, 2.0)
r = Random()
for i in range(500):
h1.fill(r.nextGaussian())
h2.fill(r.nextGaussian())
if (i<100): h2.fill(2*r.nextGaussian()+2)
h1.setErrAll(1)
h2.setErrAll(0)
c1.draw(h1)
c1.draw(h2)
from hep.aida.util.comparison import *
result = StatisticalComparison.compare(h1.get(), h2.get(),"AndersonDarling","")
print "AndersonDarling method=",result.quality(),"/",result.nDof()
result = StatisticalComparison.compare(h1.get(), h2.get(),"chi2","rejectionLevel=0.01")
print "Chi2 method=",result.quality() ,"/",result.nDof()
result = StatisticalComparison.compare(h1.get(), h2.get(),"Goodman","rejectionLevel=0.01")
print "Goodman method=",result.quality() ,"/",result.nDof()
result = StatisticalComparison.compare(h1.get(), h2.get(),"KolmogorovSmirnov","rejectionLevel=0.01")
print "KolmogorovSmirnov method=",result.quality() ,"/",result.nDof()