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:
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:
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)
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.   | |
| 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.   | |
| 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).   | |
| 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.   | |
| virtual | ~GoFTest () | 
| Double_t | AndersonDarling2SamplesTest (const Char_t *option="p") const | 
| Anderson-Darling 2-Sample Test.   | |
| void | AndersonDarling2SamplesTest (Double_t &pvalue, Double_t &testStat) const | 
| Performs the Anderson-Darling 2-Sample Test.   | |
| Double_t | AndersonDarlingTest (const Char_t *option="p") const | 
| Anderson-Darling 2-Sample Test.   | |
| void | AndersonDarlingTest (Double_t &pvalue, Double_t &testStat) const | 
| Performs the Anderson-Darling 1-Sample Test.   | |
| Double_t | KolmogorovSmirnov2SamplesTest (const Char_t *option="p") const | 
| Kolmogorov-Smirnov 2-Samples Test.   | |
| void | KolmogorovSmirnov2SamplesTest (Double_t &pvalue, Double_t &testStat) const | 
| Kolmogorov-Smirnov 2-Samples Test.   | |
| Double_t | KolmogorovSmirnovTest (const Char_t *option="p") const | 
| Kolmogorov-Smirnov 1-Sample Test.   | |
| void | KolmogorovSmirnovTest (Double_t &pvalue, Double_t &testStat) const | 
| Kolmogorov-Smirnov 1-Sample Test.   | |
| 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.   | |
| 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.   | |
| 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.   | |
| 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.   | |
| 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.   | |
| 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.   | |
| 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.   | |
| 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.   | |
| 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.   | |
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.   | |
| 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)   | |
Private Member Functions | |
| GoFTest () | |
| Disallowed default constructor.   | |
| GoFTest (GoFTest &gof) | |
| Disallowed copy constructor.   | |
| 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.   | |
| GoFTest | operator= (GoFTest &gof) | 
| Disallowed assign operator.   | |
| Double_t | PValueAD1Sample (Double_t A2) const | 
| Computation of the 1-Sample Anderson-Darling Test's p-value.   | |
| void | SetCDF () | 
| void | SetDistributionFunction (const IGenFunction &cdf, Bool_t isPDF, Double_t xmin, Double_t xmax) | 
| void | SetParameters (const std::vector< double > ¶ms) | 
| Sets the distribution parameters.   | |
| void | SetSamples (std::vector< const Double_t * > samples, const std::vector< size_t > samplesSizes) | 
| set a vector of samples   | |
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)   | |
| static Double_t | InterpolatePValues (int nsamples, Double_t A2) | 
| Linear interpolation used in GoFTest::PValueAD2Samples.   | |
Private Attributes | |
| std::unique_ptr< IGenFunction > | fCDF | 
| Pointer to CDF used in 1-sample test.   | |
| std::vector< Double_t > | fCombinedSamples | 
| The combined data.   | |
| EDistribution | fDist | 
| Type of distribution.   | |
| std::vector< Double_t > | fParams | 
| The distribution parameters (e.g. fParams[0] = mean, fParams[1] = sigma for a Gaussian)   | |
| std::vector< std::vector< Double_t > > | fSamples | 
| The input data.   | |
| Bool_t | fTestSampleFromH0 | 
#include <Math/GoFTest.h>
H0 distributions for using only with 1-sample tests.
One should provide the distribution parameters otherwise the default values will be used
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  | 
| 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 134 of file GoFTest.cxx.
| 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 161 of file GoFTest.cxx.
      
  | 
  inline | 
Constructor for 1-sample tests with a user specified distribution implementing the ROOT::Math::IGenFunction interface.
      
  | 
  virtual | 
Definition at line 179 of file GoFTest.cxx.
      
  | 
  private | 
Disallowed default constructor.
      
  | 
  private | 
Disallowed copy constructor.
Anderson-Darling 2-Sample Test.
Returns by default the p-value; when using option "t" returns the test statistic value "A2".
Definition at line 854 of file GoFTest.cxx.
      
  | 
  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 750 of file GoFTest.cxx.
| 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 646 of file GoFTest.cxx.
Anderson-Darling 2-Sample Test.
Returns default p-value; option "t" returns the test statistic value "A2"
Definition at line 890 of file GoFTest.cxx.
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 862 of file GoFTest.cxx.
Definition at line 299 of file GoFTest.cxx.
Definition at line 295 of file GoFTest.cxx.
      
  | 
  staticprivate | 
Computation of sigma_N as described in (1)
Definition at line 311 of file GoFTest.cxx.
Definition at line 279 of file GoFTest.cxx.
Linear interpolation used in GoFTest::PValueAD2Samples.
Kolmogorov-Smirnov 2-Samples Test.
Returns by default the p-value; option "t" returns the test statistic value "Dn".
Definition at line 913 of file GoFTest.cxx.
| 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 896 of file GoFTest.cxx.
Kolmogorov-Smirnov 1-Sample Test.
Returns default p-value; option "t" returns the test statistic value "Dn".
Definition at line 945 of file GoFTest.cxx.
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 921 of file GoFTest.cxx.
      
  | 
  private | 
Applies the logarithm to the sample when the specified distribution to test is LogNormal.
Definition at line 303 of file GoFTest.cxx.
| 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 208 of file GoFTest.cxx.
| 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 225 of file GoFTest.cxx.
Computation of the 1-Sample Anderson-Darling Test's p-value.
Definition at line 483 of file GoFTest.cxx.
Computation of the K-Sample Anderson-Darling Test's p-value as described in (1)
Definition at line 353 of file GoFTest.cxx.
      
  | 
  private | 
Definition at line 244 of file GoFTest.cxx.
| 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 124 of file GoFTest.cxx.
      
  | 
  private | 
Definition at line 267 of file GoFTest.cxx.
Sets the distribution parameters.
Definition at line 204 of file GoFTest.cxx.
      
  | 
  private | 
set a vector of samples
Definition at line 181 of file GoFTest.cxx.
      
  | 
  inline | 
      
  | 
  inline | 
Sets the user input distribution function for 1-sample test using the ROOT::Math::IGenFunction interface.
      
  | 
  inline | 
      
  | 
  inline | 
Specialization to set the user input distribution as a probability density function for 1-sample tests using the ROOT::Math::IGenFunction interface.
      
  | 
  private | 
      
  | 
  private | 
      
  | 
  private | 
      
  | 
  private | 
      
  | 
  private |