English Français

Documentation / User's manual in Python : PDF version

XII.2. Tests based on the Empirical Distribution Function ("EDF tests")

XII.2. Tests based on the Empirical Distribution Function ("EDF tests")

The implemented tests are the Kolmogorov-Smirnov () test, the Cramer-VonMises () test and the Anderson-Darling () test. Their aim is to compare a given attribute to a bunch of implemented laws among the following list: the normal, lognormal and uniform law. The details of the computation is given in [metho]. The following piece of code gives an example of what can be achieved using these three classes and the usage of their options defined in the summary block below. Figure XII.1 shows the results of such a script.

"""
Example of distribution testing with different quality criteria
"""
from rootlogon import ROOT, DataServer, Sampler, UncertModeler

# Create a TDS with 3 kind of distributions
tds0 = DataServer.TDataServer()
tds0.addAttribute(DataServer.TNormalDistribution("n", 1.3, 4.5))
tds0.addAttribute(DataServer.TLogNormalDistribution("ln", 1.3, 4.5))
tds0.addAttribute(DataServer.TUniformDistribution("u", -1.3, 4.5))

# Create the sample
fsamp = Sampler.TBasicSampling(tds0, "lhs", 1000)
fsamp.generateSample()

# Create the canvas
c = ROOT.TCanvas("c1", "", 5, 20, 1300, 600)
apad = ROOT.TPad("apad", "apad", 0, 0.03, 1, 1)
apad.Draw()
apad.cd()
apad.Divide(3)

apad.cd(1)
tks_n = UncertModeler.TTestKolmogorovSmirnov(tds0, "n")
tcvm_n = UncertModeler.TTestCramerVonMises(tds0, "n")
tad_n = UncertModeler.TTestAndersonDarling(tds0, "n")
# Test wrt to a normal distribution whose mu and sigma are taken from
# the original distribution
tks_n.computeScore("same:normal")
tad_n.computeScore("same:normal(0.8,4.5))")  # put wrong mu
tcvm_n.computeScore("same:normal(1.3,5.5)")  # put wrong sigma

apad.cd(2)
tks_ln = UncertModeler.TTestKolmogorovSmirnov(tds0, "ln")
tcvm_ln = UncertModeler.TTestCramerVonMises(tds0, "ln")
tad_ln = UncertModeler.TTestAndersonDarling(tds0, "ln")
# Test wrt to a lognormal distribution whose mu and sigma are taken from
# the original distribution
tks_ln.computeScore("same:lognormal")
tad_ln.computeScore("same:lognormal(1.2,4.5))")  # put wrong mu
tcvm_ln.computeScore("same:lognormal(1.3,3.5)")  # put wrong sigma

apad.cd(3)
tks_u = UncertModeler.TTestKolmogorovSmirnov(tds0, "u")
tcvm_u = UncertModeler.TTestCramerVonMises(tds0, "u")
tad_u = UncertModeler.TTestAndersonDarling(tds0, "u")
# Test wrt to an uniform distribution whose min and max are taken from
# the original distribution (and compared to a normal as well, for fun)
tks_u.computeScore("same:uniform")
tad_u.computeScore("same:uniform(-1.2,4.5)")  # put wrong min
tcvm_u.computeScore("same:uniform(-1.3,4.6)")  # put wrong max

Figure XII.1. Results of the macro defined previously to produce variety of test of already implemented distributions

Results of the macro defined previously to produce variety of test of already implemented distributions


/language/en