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.
More User Documentation: Download and Installation, Statistical Algorithms, List of all GoF tests
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 required by the analysis system you are using: for instance, the ones for AIDA, if you use an AIDA-compliant analysis system
#include “AIDA/AIDA.h”
// Include the header files for the Statistics Toolkit classes #include “StatisticsComparator.h” #include “Chi2ComparisonAlgorithm.h” #include “ComparisonResult.h"
// Namespace directive, for convenience
using namespace StatisticsTesting;
// Perform any initialization required by the analysis system you are using: for instance, if you use an AIDA-compliant analysis system create the AIDA factories and tree
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 with the analysis system of your choice (an AIDA-compliant one or ROOT)
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 with the analysis system of your choice (an AIDA-compliant one or ROOT)
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, number of degrees of freedom and p-value
std::cout << “ distance=“ << result.distance() << “ ndf=“ << result.ndf() << “ p-value=“ << result.quality();
The example below compares two clouds (unbinned distributions)
applying the Kolmogorov-Smirnov test. For convenience, the creation
and filling of user's analysis objects (clouds) is performed with an AIDA-compliant
analysis system; however, the instantiation and the usage of the Statistical
Toolkit objects shown below is independent from the analysis system chosen by
the user.
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();
If you need user support or wish to submit a problem report, please contact us.
Last modified 10 April 2006 - Maria Grazia Pia