English Français

Documentation / User's manual in C++ : 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.

{
 // Create a TDS with 3 kind of distributions
 TDataServer *tds0 = new TDataServer();
 tds0->addAttribute(new TNormalDistribution("n", 1.3, 4.5));
 tds0->addAttribute(new TLogNormalDistribution("ln", 1.3, 4.5));
 tds0->addAttribute(new TUniformDistribution("u", -1.3, 4.5));
 
 // Create the sample
 TBasicSampling *fsamp = new TBasicSampling(tds0, "lhs", 1000);
 fsamp->generateSample();
 
 //Create the canvas
 TCanvas *c = new TCanvas("c1","",5,20,1300,600);
 TPad *apad = new TPad("apad","apad",0, 0.03, 1, 1); apad->Draw(); apad->cd();
 apad->Divide(3);		
 
 apad->cd(1);
 TTestKolmogorovSmirnov *tks_n = new TTestKolmogorovSmirnov(tds0, "n");
 TTestCramerVonMises *tcvm_n = new TTestCramerVonMises(tds0, "n");
 TTestAndersonDarling *tad_n = new 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);
 TTestKolmogorovSmirnov *tks_ln = new TTestKolmogorovSmirnov(tds0, "ln");
 TTestCramerVonMises *tcvm_ln = new TTestCramerVonMises(tds0, "ln");
 TTestAndersonDarling *tad_ln = new 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);
 TTestKolmogorovSmirnov *tks_u = new TTestKolmogorovSmirnov(tds0, "u");
 TTestCramerVonMises *tcvm_u = new TTestCramerVonMises(tds0, "u");
 TTestAndersonDarling *tad_u = new 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