Logo ROOT  
Reference Guide
ROOT::Math::GoFTest Class Reference

GoFTest class implementing the 1 sample and 2 sample goodness of fit tests for uni-variate distributions and data.

The class implements the AndersonDarling and the KolmogorovSmirnov tests

In the case of the 1-sample test the user needs to provide:

  • input data
  • theoretical distribution. The distribution can be provided as a function object (functor) or an object implementing the ROOT::Math::IGenFunction interface. One can provide either the PDF (default) of the CDF (cumulative distribution) One can also provide a pre-defined function. In that case one needs to give also the distribution parameters otherwise the default values will be used. The pre-defined distributions are:

    • kGaussian with default parameter mean=0, sigma=1
    • kExponential with default parameter rate=1
    • kLogNormal with default parameter meanlog=0, sigmalog=1

    Note that one should not use data computed distribution parameters, otherwise the test will be biased. The 1-sample KS test using data computed quantities is called Lilliefors test (see https://en.wikipedia.org/wiki/Lilliefors_test)

Definition at line 65 of file GoFTest.h.

Public Types

enum  EDistribution {
  kUndefined , kUserDefined , kGaussian , kLogNormal ,
  kExponential
}
 H0 distributions for using only with 1-sample tests. More...
 
enum  ETestType { kAD , kAD2s , kKS , kKS2s }
 Goodness of Fit test types for using with the class's unary functions as a shorthand for the in-built methods. More...
 
enum  EUserDistribution { kCDF , kPDF }
 User input distribution option. More...
 

Public Member Functions

 GoFTest (size_t sample1Size, const Double_t *sample1, size_t sample2Size, const Double_t *sample2)
 Constructor for 2-samples tests. More...
 
 GoFTest (size_t sampleSize, const Double_t *sample, const IGenFunction &dist, EUserDistribution userDist=kPDF, Double_t xmin=1, Double_t xmax=0)
 Constructor for 1-sample tests with a user specified distribution implementing the ROOT::Math::IGenFunction interface. More...
 
template<class Dist >
 GoFTest (size_t sampleSize, const Double_t *sample, Dist &dist, EUserDistribution userDist=kPDF, Double_t xmin=1, Double_t xmax=0)
 Templated constructor for 1-sample tests with a user specified distribution as a functor object implementing double operator()(double x). More...
 
 GoFTest (size_t sampleSize, const Double_t *sample, EDistribution dist=kUndefined, const std::vector< double > &distParams={})
 Constructor for 1-sample tests with a specified distribution. More...
 
virtual ~GoFTest ()
 
Double_t AndersonDarling2SamplesTest (const Char_t *option="p") const
 Anderson-Darling 2-Sample Test. More...
 
void AndersonDarling2SamplesTest (Double_t &pvalue, Double_t &testStat) const
 Performs the Anderson-Darling 2-Sample Test. More...
 
Double_t AndersonDarlingTest (const Char_t *option="p") const
 Anderson-Darling 2-Sample Test. More...
 
void AndersonDarlingTest (Double_t &pvalue, Double_t &testStat) const
 Performs the Anderson-Darling 1-Sample Test. More...
 
Double_t KolmogorovSmirnov2SamplesTest (const Char_t *option="p") const
 Kolmogorov-Smirnov 2-Samples Test. More...
 
void KolmogorovSmirnov2SamplesTest (Double_t &pvalue, Double_t &testStat) const
 Kolmogorov-Smirnov 2-Samples Test. More...
 
Double_t KolmogorovSmirnovTest (const Char_t *option="p") const
 Kolmogorov-Smirnov 1-Sample Test. More...
 
void KolmogorovSmirnovTest (Double_t &pvalue, Double_t &testStat) const
 Kolmogorov-Smirnov 1-Sample Test. More...
 
void operator() (ETestType test, Double_t &pvalue, Double_t &testStat) const
 The class's unary functions performing the gif test according to the ETestType provided. More...
 
Double_t operator() (ETestType test=kAD, const Char_t *option="p") const
 Returns default Anderson Darling 1-Sample Test and default p-value; option "t" returns the test statistic value specific to the test type. More...
 
void SetDistribution (EDistribution dist, const std::vector< double > &distParams={})
 Sets the distribution for the predefined distribution types and optionally its parameters for 1-sample tests. More...
 
void SetUserCDF (const IGenFunction &cdf, Double_t xmin=1, Double_t xmax=0)
 Specialization to set the user input distribution as a cumulative distribution function for 1-sample tests. More...
 
template<class Dist >
void SetUserCDF (Dist &cdf, Double_t xmin=1, Double_t xmax=0)
 Sets the user input distribution as a cumulative distribution function for 1-sample tests. More...
 
void SetUserDistribution (const IGenFunction &dist, GoFTest::EUserDistribution userDist=kPDF, Double_t xmin=1, Double_t xmax=0)
 Sets the user input distribution function for 1-sample test using the ROOT::Math::IGenFunction interface. More...
 
template<class Dist >
void SetUserDistribution (Dist &dist, EUserDistribution userDist=kPDF, Double_t xmin=1, Double_t xmax=0)
 Sets the user input distribution function for 1-sample test as a generic functor object. More...
 
void SetUserPDF (const IGenFunction &pdf, Double_t xmin=1, Double_t xmax=0)
 Specialization to set the user input distribution as a probability density function for 1-sample tests using the ROOT::Math::IGenFunction interface. More...
 
template<class Dist >
void SetUserPDF (Dist &pdf, Double_t xmin=1, Double_t xmax=0)
 Sets the user input distribution as a probability density function for 1-sample tests. More...
 

Static Public Member Functions

static void AndersonDarling2SamplesTest (const ROOT::Fit::BinData &data1, const ROOT::Fit::BinData &data2, Double_t &pvalue, Double_t &testStat)
 Compute the 2-Sample Anderson Darling test for binned data assuming equal data are present at the bin center values. More...
 
static Double_t PValueADKSamples (size_t nsamples, Double_t A2)
 Computation of the K-Sample Anderson-Darling Test's p-value as described in (1) More...
 

Private Member Functions

 GoFTest ()
 Disallowed default constructor. More...
 
 GoFTest (GoFTest &gof)
 Disallowed copy constructor. More...
 
Double_t ExponentialCDF (Double_t x) const
 
Double_t GaussianCDF (Double_t x) const
 
void Instantiate (const Double_t *sample, size_t sampleSize)
 
Double_t LogNormalCDF (Double_t x) const
 
void LogSample ()
 Applies the logarithm to the sample when the specified distribution to test is LogNormal. More...
 
GoFTest operator= (GoFTest &gof)
 Disallowed assign operator. More...
 
Double_t PValueAD1Sample (Double_t A2) const
 Computation of the 1-Sample Anderson-Darling Test's p-value. More...
 
void SetCDF ()
 
void SetDistributionFunction (const IGenFunction &cdf, Bool_t isPDF, Double_t xmin, Double_t xmax)
 
void SetParameters (const std::vector< double > &params)
 Sets the distribution parameters. More...
 
void SetSamples (std::vector< const Double_t * > samples, const std::vector< size_t > samplesSizes)
 set a vector of samples More...
 

Static Private Member Functions

static Double_t GetSigmaN (const std::vector< size_t > &ns, size_t N)
 Computation of sigma_N as described in (1) More...
 
static Double_t InterpolatePValues (int nsamples, Double_t A2)
 Linear interpolation used in GoFTest::PValueAD2Samples. More...
 

Private Attributes

std::unique_ptr< IGenFunctionfCDF
 Pointer to CDF used in 1-sample test. More...
 
std::vector< Double_tfCombinedSamples
 The combined data. More...
 
EDistribution fDist
 Type of distribution. More...
 
std::vector< Double_tfParams
 The distribution parameters (e.g. fParams[0] = mean, fParams[1] = sigma for a Gaussian) More...
 
std::vector< std::vector< Double_t > > fSamples
 The input data. More...
 
Bool_t fTestSampleFromH0
 

#include <Math/GoFTest.h>

Member Enumeration Documentation

◆ EDistribution

H0 distributions for using only with 1-sample tests.

One should provide the distribution parameters otherwise the default values will be used

Enumerator
kUndefined 
kUserDefined 

Default value for non templated 1-sample test. Set with SetDistribution.

kGaussian 

For internal use only within the class's template constructor.

kLogNormal 

Gaussian distribution with default mean=0, sigma=1.

kExponential 

Lognormal distribution with default meanlog=0, sigmalog=1.

Exponential distribution with default rate=1

Definition at line 70 of file GoFTest.h.

◆ ETestType

Goodness of Fit test types for using with the class's unary functions as a shorthand for the in-built methods.

Enumerator
kAD 
kAD2s 

Anderson-Darling Test. Default value.

kKS 

Anderson-Darling 2-Samples Test.

kKS2s 

Kolmogorov-Smirnov Test.

Kolmogorov-Smirnov 2-Samples Test

Definition at line 85 of file GoFTest.h.

◆ EUserDistribution

User input distribution option.

Enumerator
kCDF 
kPDF 

Input distribution is a CDF : cumulative distribution function.

Input distribution is a PDF (Default value)

Definition at line 79 of file GoFTest.h.

Constructor & Destructor Documentation

◆ GoFTest() [1/6]

ROOT::Math::GoFTest::GoFTest ( size_t  sample1Size,
const Double_t sample1,
size_t  sample2Size,
const Double_t sample2 
)

Constructor for 2-samples tests.

Definition at line 133 of file GoFTest.cxx.

◆ GoFTest() [2/6]

ROOT::Math::GoFTest::GoFTest ( size_t  sampleSize,
const Double_t sample,
EDistribution  dist = kUndefined,
const std::vector< double > &  distParams = {} 
)

Constructor for 1-sample tests with a specified distribution.

If a specific distribution is not specified it can be set later using SetDistribution.

Definition at line 160 of file GoFTest.cxx.

◆ GoFTest() [3/6]

template<class Dist >
ROOT::Math::GoFTest::GoFTest ( size_t  sampleSize,
const Double_t sample,
Dist &  dist,
EUserDistribution  userDist = kPDF,
Double_t  xmin = 1,
Double_t  xmax = 0 
)
inline

Templated constructor for 1-sample tests with a user specified distribution as a functor object implementing double operator()(double x).

Definition at line 101 of file GoFTest.h.

◆ GoFTest() [4/6]

ROOT::Math::GoFTest::GoFTest ( size_t  sampleSize,
const Double_t sample,
const IGenFunction dist,
EUserDistribution  userDist = kPDF,
Double_t  xmin = 1,
Double_t  xmax = 0 
)
inline

Constructor for 1-sample tests with a user specified distribution implementing the ROOT::Math::IGenFunction interface.

Definition at line 109 of file GoFTest.h.

◆ ~GoFTest()

ROOT::Math::GoFTest::~GoFTest ( )
virtual

Definition at line 178 of file GoFTest.cxx.

◆ GoFTest() [5/6]

ROOT::Math::GoFTest::GoFTest ( )
private

Disallowed default constructor.

◆ GoFTest() [6/6]

ROOT::Math::GoFTest::GoFTest ( GoFTest gof)
private

Disallowed copy constructor.

Member Function Documentation

◆ AndersonDarling2SamplesTest() [1/3]

Double_t ROOT::Math::GoFTest::AndersonDarling2SamplesTest ( const Char_t option = "p") const

Anderson-Darling 2-Sample Test.

Returns by default the p-value; when using option "t" returns the test statistic value "A2".

Definition at line 853 of file GoFTest.cxx.

◆ AndersonDarling2SamplesTest() [2/3]

void ROOT::Math::GoFTest::AndersonDarling2SamplesTest ( const ROOT::Fit::BinData data1,
const ROOT::Fit::BinData data2,
Double_t pvalue,
Double_t testStat 
)
static

Compute the 2-Sample Anderson Darling test for binned data assuming equal data are present at the bin center values.

Used by TH1::AndersonDarling

Definition at line 749 of file GoFTest.cxx.

◆ AndersonDarling2SamplesTest() [3/3]

void ROOT::Math::GoFTest::AndersonDarling2SamplesTest ( Double_t pvalue,
Double_t testStat 
) const

Performs the Anderson-Darling 2-Sample Test.

The Anderson-Darling K-Sample Test algorithm is described and taken from http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/andeksam.htm and from (1) Scholz F.W., Stephens M.A. (1987), K-sample Anderson-Darling Tests, Journal of the American Statistical Association, 82, 918–924. (2-samples variant implemented).

Definition at line 645 of file GoFTest.cxx.

◆ AndersonDarlingTest() [1/2]

Double_t ROOT::Math::GoFTest::AndersonDarlingTest ( const Char_t option = "p") const

Anderson-Darling 2-Sample Test.

Returns default p-value; option "t" returns the test statistic value "A2"

Definition at line 889 of file GoFTest.cxx.

◆ AndersonDarlingTest() [2/2]

void ROOT::Math::GoFTest::AndersonDarlingTest ( Double_t pvalue,
Double_t testStat 
) const

Performs the Anderson-Darling 1-Sample Test.

The Anderson-Darling 1-Sample Test algorithm for a specific distribution is described at http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/andedarl.htm and described and taken from (2) Marsaglia J.C.W., Marsaglia G. (2004), Evaluating the Anderson-Darling Distribution, Journal of Statistical Software, Volume 09, Issue i02. and described and taken from (3) Lewis P.A.W. (1961), The Annals of Mathematical Statistics, Distribution of the Anderson-Darling Statistic, Volume 32, Number 4, 1118-1124.

Definition at line 861 of file GoFTest.cxx.

◆ ExponentialCDF()

Double_t ROOT::Math::GoFTest::ExponentialCDF ( Double_t  x) const
private

Definition at line 298 of file GoFTest.cxx.

◆ GaussianCDF()

Double_t ROOT::Math::GoFTest::GaussianCDF ( Double_t  x) const
private

Definition at line 294 of file GoFTest.cxx.

◆ GetSigmaN()

Double_t ROOT::Math::GoFTest::GetSigmaN ( const std::vector< size_t > &  ns,
size_t  N 
)
staticprivate

Computation of sigma_N as described in (1)

Definition at line 310 of file GoFTest.cxx.

◆ Instantiate()

void ROOT::Math::GoFTest::Instantiate ( const Double_t sample,
size_t  sampleSize 
)
private

Definition at line 278 of file GoFTest.cxx.

◆ InterpolatePValues()

static Double_t ROOT::Math::GoFTest::InterpolatePValues ( int  nsamples,
Double_t  A2 
)
staticprivate

Linear interpolation used in GoFTest::PValueAD2Samples.

◆ KolmogorovSmirnov2SamplesTest() [1/2]

Double_t ROOT::Math::GoFTest::KolmogorovSmirnov2SamplesTest ( const Char_t option = "p") const

Kolmogorov-Smirnov 2-Samples Test.

Returns by default the p-value; option "t" returns the test statistic value "Dn".

Definition at line 912 of file GoFTest.cxx.

◆ KolmogorovSmirnov2SamplesTest() [2/2]

void ROOT::Math::GoFTest::KolmogorovSmirnov2SamplesTest ( Double_t pvalue,
Double_t testStat 
) const

Kolmogorov-Smirnov 2-Samples Test.

The Kolmogorov-Smirnov 2-Samples Test algorithm is described at http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ks2samp.htm and described and taken from http://root.cern.ch/root/html/TMath.html#TMath:KolmogorovTest

Definition at line 895 of file GoFTest.cxx.

◆ KolmogorovSmirnovTest() [1/2]

Double_t ROOT::Math::GoFTest::KolmogorovSmirnovTest ( const Char_t option = "p") const

Kolmogorov-Smirnov 1-Sample Test.

Returns default p-value; option "t" returns the test statistic value "Dn".

Definition at line 944 of file GoFTest.cxx.

◆ KolmogorovSmirnovTest() [2/2]

void ROOT::Math::GoFTest::KolmogorovSmirnovTest ( Double_t pvalue,
Double_t testStat 
) const

Kolmogorov-Smirnov 1-Sample Test.

The Kolmogorov-Smirnov 1-Sample Test algorithm for a specific distribution is described at http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/kstest.htm and described and taken from (4) Press W. H., Teukolsky S.A., Vetterling W.T., Flannery B.P. (2007), Numerical Recipes - The Art of Scientific Computing (Third Edition), Cambridge University Press

Definition at line 920 of file GoFTest.cxx.

◆ LogNormalCDF()

Double_t ROOT::Math::GoFTest::LogNormalCDF ( Double_t  x) const
private

◆ LogSample()

void ROOT::Math::GoFTest::LogSample ( )
private

Applies the logarithm to the sample when the specified distribution to test is LogNormal.

Definition at line 302 of file GoFTest.cxx.

◆ operator()() [1/2]

void ROOT::Math::GoFTest::operator() ( ETestType  test,
Double_t pvalue,
Double_t testStat 
) const

The class's unary functions performing the gif test according to the ETestType provided.

Definition at line 207 of file GoFTest.cxx.

◆ operator()() [2/2]

Double_t ROOT::Math::GoFTest::operator() ( ETestType  test = kAD,
const Char_t option = "p" 
) const

Returns default Anderson Darling 1-Sample Test and default p-value; option "t" returns the test statistic value specific to the test type.

Definition at line 224 of file GoFTest.cxx.

◆ operator=()

GoFTest ROOT::Math::GoFTest::operator= ( GoFTest gof)
private

Disallowed assign operator.

◆ PValueAD1Sample()

Double_t ROOT::Math::GoFTest::PValueAD1Sample ( Double_t  A2) const
private

Computation of the 1-Sample Anderson-Darling Test's p-value.

Definition at line 482 of file GoFTest.cxx.

◆ PValueADKSamples()

Double_t ROOT::Math::GoFTest::PValueADKSamples ( size_t  nsamples,
Double_t  A2 
)
static

Computation of the K-Sample Anderson-Darling Test's p-value as described in (1)

Definition at line 352 of file GoFTest.cxx.

◆ SetCDF()

void ROOT::Math::GoFTest::SetCDF ( )
private

Definition at line 243 of file GoFTest.cxx.

◆ SetDistribution()

void ROOT::Math::GoFTest::SetDistribution ( EDistribution  dist,
const std::vector< double > &  distParams = {} 
)

Sets the distribution for the predefined distribution types and optionally its parameters for 1-sample tests.

Definition at line 123 of file GoFTest.cxx.

◆ SetDistributionFunction()

void ROOT::Math::GoFTest::SetDistributionFunction ( const IGenFunction cdf,
Bool_t  isPDF,
Double_t  xmin,
Double_t  xmax 
)
private

Definition at line 266 of file GoFTest.cxx.

◆ SetParameters()

void ROOT::Math::GoFTest::SetParameters ( const std::vector< double > &  params)
private

Sets the distribution parameters.

Definition at line 203 of file GoFTest.cxx.

◆ SetSamples()

void ROOT::Math::GoFTest::SetSamples ( std::vector< const Double_t * >  samples,
const std::vector< size_t >  samplesSizes 
)
private

set a vector of samples

Definition at line 180 of file GoFTest.cxx.

◆ SetUserCDF() [1/2]

void ROOT::Math::GoFTest::SetUserCDF ( const IGenFunction cdf,
Double_t  xmin = 1,
Double_t  xmax = 0 
)
inline

Specialization to set the user input distribution as a cumulative distribution function for 1-sample tests.

Definition at line 147 of file GoFTest.h.

◆ SetUserCDF() [2/2]

template<class Dist >
void ROOT::Math::GoFTest::SetUserCDF ( Dist &  cdf,
Double_t  xmin = 1,
Double_t  xmax = 0 
)
inline

Sets the user input distribution as a cumulative distribution function for 1-sample tests.

The CDF must return zero for x=xmin and 1 for x=xmax.

Definition at line 142 of file GoFTest.h.

◆ SetUserDistribution() [1/2]

void ROOT::Math::GoFTest::SetUserDistribution ( const IGenFunction dist,
GoFTest::EUserDistribution  userDist = kPDF,
Double_t  xmin = 1,
Double_t  xmax = 0 
)
inline

Sets the user input distribution function for 1-sample test using the ROOT::Math::IGenFunction interface.

Definition at line 124 of file GoFTest.h.

◆ SetUserDistribution() [2/2]

template<class Dist >
void ROOT::Math::GoFTest::SetUserDistribution ( Dist &  dist,
EUserDistribution  userDist = kPDF,
Double_t  xmin = 1,
Double_t  xmax = 0 
)
inline

Sets the user input distribution function for 1-sample test as a generic functor object.

Definition at line 118 of file GoFTest.h.

◆ SetUserPDF() [1/2]

void ROOT::Math::GoFTest::SetUserPDF ( const IGenFunction pdf,
Double_t  xmin = 1,
Double_t  xmax = 0 
)
inline

Specialization to set the user input distribution as a probability density function for 1-sample tests using the ROOT::Math::IGenFunction interface.

Definition at line 135 of file GoFTest.h.

◆ SetUserPDF() [2/2]

template<class Dist >
void ROOT::Math::GoFTest::SetUserPDF ( Dist &  pdf,
Double_t  xmin = 1,
Double_t  xmax = 0 
)
inline

Sets the user input distribution as a probability density function for 1-sample tests.

Definition at line 130 of file GoFTest.h.

Member Data Documentation

◆ fCDF

std::unique_ptr<IGenFunction> ROOT::Math::GoFTest::fCDF
private

Pointer to CDF used in 1-sample test.

Definition at line 235 of file GoFTest.h.

◆ fCombinedSamples

std::vector<Double_t> ROOT::Math::GoFTest::fCombinedSamples
private

The combined data.

Definition at line 241 of file GoFTest.h.

◆ fDist

EDistribution ROOT::Math::GoFTest::fDist
private

Type of distribution.

Definition at line 238 of file GoFTest.h.

◆ fParams

std::vector<Double_t> ROOT::Math::GoFTest::fParams
private

The distribution parameters (e.g. fParams[0] = mean, fParams[1] = sigma for a Gaussian)

Definition at line 239 of file GoFTest.h.

◆ fSamples

std::vector<std::vector<Double_t> > ROOT::Math::GoFTest::fSamples
private

The input data.

Definition at line 243 of file GoFTest.h.

◆ fTestSampleFromH0

Bool_t ROOT::Math::GoFTest::fTestSampleFromH0
private

Definition at line 245 of file GoFTest.h.

Libraries for ROOT::Math::GoFTest:
[legend]

The documentation for this class was generated from the following files: