How to use and Examples

The following examples illustrate how to use the Statistical Toolkit.
More examples how to use the system can be found in the packages/StatisticsTesting/examples directory of the Statistical Toolkit.

Compare two binned distributions
Compare two unbinned distributions
Compare two sets of points

More User Documentation: Download and Installation, Statistical Algorithms, List of all GoF tests


Compare two binned distributions (1-D histograms)

The example below compares two 1-dimensional histograms (binned distributions) applying the chi2 test
You can apply any other GoF test appropriate for binned distributions in the same way as the chi2.

List of all GoF tests available in the Statistical Toolkit

// Include the header files for AIDA and for the Statistics Toolkit classes

#include “AIDA/AIDA.h”
#include “StatisticsComparator.h”  
#include “Chi2ComparisonAlgorithm.h” 
#include “ComparisonResult.h"

// Namespace directive, for convenience

using namespace StatisticsTesting; 

// Create the AIDA factories and tree (for more information see AIDA)

std::auto_ptr<AIDA::IAnalysisFactory>  af( AIDA_createAnalysisFactory() );
std::auto_ptr<AIDA::ITreeFactory> tf( af -> createTreeFactory() ); 
std::auto_ptr<AIDA::ITree> tree( tf -> create() ); 
std::auto_ptr<AIDA::IHistogramFactory> hf( af->createHistogramFactory( *tree ) ); 

// Create two histograms

AIDA::IHistogram1D& hA = *( hf->createHistogram1D( "A", 100, 0.0, 50.0) ); 
AIDA::IHistogram1D& hB = *( hf->createHistogram1D( "B", 100, 0.0, 50.0) ); 

// Fill the histograms

hA.fill( 15.7 ); 
... 
hB.fill( 23.4 ); 
...

// Instantiate the StatisticsComparator, selecting the Goodness of Fit algorithm you want to apply (chi2 in this case)

StatisticsComparator< 
Chi2ComparisonAlgorithm > comparator; 

// Compare the two histograms and get the result of the comparison

ComparisonResult result = comparator.
compare( hA, hB ); 

// Print some statistical information about the result of the comparison: the distance, ndf and p-value

std::cout << “ distance=“ <<
result.distance()
 
          << “ ndf=“      <<
result.ndf() 
          << “ p-value=“  << result.quality();
          

Compare two unbinned distributions (clouds)

The example below compares two clouds (unbinned distributions) applying the Kolmogorov-Smirnov test
You can apply any other GoF test appropriate for binned distributions in the same way as the Kolmogorov-Smirnov.

List of all GoF tests available in the Statistical Toolkit

// Include the header files for AIDA and for the Statistics Toolkit classes

#include “AIDA/AIDA.h”
#include “StatisticsComparator.h”  
#include “Chi2ComparisonAlgorithm.h” 
#include “ComparisonResult.h"

// Namespace directive, for convenience

using namespace StatisticsTesting; 

// Create the AIDA factories and tree (for more information see AIDA)

std::auto_ptr<AIDA::IAnalysisFactory> af( AIDA_createAnalysisFactory() );
std::auto_ptr<AIDA::ITreeFactory> tf( af -> createTreeFactory() ); 
std::auto_ptr<AIDA::ITree> tree( tf -> create() ); 
std::auto_ptr<AIDA::IHistogramFactory> hf( af->createHistogramFactory( *tree ) ); 

// Create two clouds

AIDA::ICloud1D& cloudA= *( hf->createCloud1D( "A" ) );
AIDA::ICloud1D& cloudB = *( hf->createCloud1D( "B" ) );

// Fill the clouds

cloudA.fill( 15.7 );
...
cloudB.fill( 23.4 );
...

// Instantiate the StatisticsComparator, selecting the Goodness of Fit test you want to apply (Kolmogorov-Smirnov in this case)

StatisticsComparator< KolmogorovSmirnovComparisonAlgorithm > comparator;

// Compare the two distributions and get the result of the comparison

ComparisonResult result = comparator.compare( cloudA, cloudB );

// Print some statistical information about the result of the comparison: the distance and p-value

std::cout << “ K-S distance=“ << result.distance() 
          << “ p-value=“      << result.quality();

Compare two sets of points 

Work in progress: not available in the current release yet

The example below compares two sets of points applying the chi2 test

List of all GoF tests available in the Statistical Toolkit

// Include the header files for AIDA and for the Statistics Toolkit classes

#include “AIDA/AIDA.h”
#include “StatisticsComparator.h”  
#include “Chi2ComparisonAlgorithm.h” 
#include “ComparisonResult.h"

// Namespace directive, for convenience

using namespace StatisticsTesting; 

// Create the AIDA factories and tree (for more information see AIDA)

std::auto_ptr<AIDA::IAnalysisFactory>  af( AIDA_createAnalysisFactory() );
std::auto_ptr<AIDA::ITreeFactory> tf( af -> createTreeFactory() ); 
std::auto_ptr<AIDA::ITree> tree( tf -> create() ); 
std::auto_ptr<AIDA::IDataPointSetFactory> dpsf( af -> createDataPointSetFactory( *tree ) );

// The two sets of points are stored in XML files

std::auto_ptr<AIDA::ITree> treeXML1( tf -> create(“gamma_lowE_Ge.xml”, “xml”, true, false);
std::auto_ptr<AIDA::ITree> treeXML2( tf -> create(“NIST_attenuationGamma_Ge.xml”, true, false);

// The two sets of points are AIDA IDataPointSet objects

AIDA::IDataPointSet& dps1 = *( dynamic_cast<AIDA::IDataPointSet*>( treeXML1 -> find(“Gamma attenuation coefficient test” ) ) );
AIDA::IDataPointSet& dps2 = *( dynamic_cast<AIDA::IDataPointSet*>( treeXML2 -> find(“Gamma attenuation coefficient test” ) ) );

// Instantiate the StatisticsComparator, selecting the Goodness of Fit test you want to apply (chi2 in this case)

StatisticsComparator< Chi2ComparisonAlgorithm > comparator;

// Compare the two sets of points and get the result of the comparison

ComparisonResult result = comparator.compare( dps1, dps2 );

// Print some statistical information about the result of the comparison: the distance, ndf and p-value

std::cout << “ distance=“ << result.distance() 
          << “ ndf=“      << result.ndf() 
          << “ p-value=“  << result.quality();

Contact us

If you need user support or wish to submit a problem report, please contact us.


Last modified 26 March 2004 - Maria Grazia Pia