npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
UnbinnedGOFTests1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_UNBINNEDGOFTESTS1D_HH_
2 #define NPSTAT_UNBINNEDGOFTESTS1D_HH_
3 
4 /*!
5 // \file UnbinnedGOFTests1D.hh
6 //
7 // \brief Some one-sample goodness-of-fit tests (KS, AD, CvM, Zhang's, etc)
8 //
9 // Author: I. Volobouev
10 //
11 // November 2020
12 */
13 
15 
16 namespace npstat {
17  /** Kolmogorov-Smirnov test */
19  {
20  public:
21  inline explicit KSTest1D(const AbsDistribution1D& d)
22  : AbsUnbinnedGOFTest1D(d) {}
23 
24  inline virtual ~KSTest1D() {}
25 
26  inline virtual std::string shortName() const {return "KS";}
27 
28  inline virtual double testStatistic(
29  const double* data, const unsigned long sz, const bool b) const
30  {return testStat(data, sz, b);}
31 
32  inline virtual double testStatistic(
33  const float* data, const unsigned long sz, const bool b) const
34  {return testStat(data, sz, b);}
35 
36  inline virtual bool hasAnalyticPValue() const {return true;}
37 
38  virtual double analyticPValue(double stat, unsigned long sz) const;
39 
40  private:
41  template<typename Numeric>
42  double testStat(const Numeric* data, unsigned long lenData,
43  bool dataIsSorted) const;
44  };
45 
46  /** Kuiper's test */
48  {
49  public:
50  inline explicit KuiperTest1D(const AbsDistribution1D& d)
51  : AbsUnbinnedGOFTest1D(d) {}
52 
53  inline virtual ~KuiperTest1D() {}
54 
55  inline virtual std::string shortName() const {return "Kuiper";}
56 
57  inline virtual double testStatistic(
58  const double* data, const unsigned long sz, const bool b) const
59  {return testStat(data, sz, b);}
60 
61  inline virtual double testStatistic(
62  const float* data, const unsigned long sz, const bool b) const
63  {return testStat(data, sz, b);}
64 
65  private:
66  template<typename Numeric>
67  double testStat(const Numeric* data, unsigned long lenData,
68  bool dataIsSorted) const;
69  };
70 
71  /** Anderson-Darling test */
73  {
74  public:
75  inline explicit ADTest1D(const AbsDistribution1D& d)
76  : AbsUnbinnedGOFTest1D(d) {}
77 
78  inline virtual ~ADTest1D() {}
79 
80  inline virtual std::string shortName() const {return "AD";}
81 
82  inline virtual double testStatistic(
83  const double* data, const unsigned long sz, const bool b) const
84  {return testStat(data, sz, b);}
85 
86  inline virtual double testStatistic(
87  const float* data, const unsigned long sz, const bool b) const
88  {return testStat(data, sz, b);}
89 
90  inline virtual bool hasAnalyticPValue() const {return true;}
91 
92  virtual double analyticPValue(double stat, unsigned long sz) const;
93 
94  private:
95  template<typename Numeric>
96  double testStat(const Numeric* data, unsigned long lenData,
97  bool dataIsSorted) const;
98  };
99 
100  /** Cramer-von Mises test */
102  {
103  public:
104  inline explicit CvMTest1D(const AbsDistribution1D& d)
105  : AbsUnbinnedGOFTest1D(d) {}
106 
107  inline virtual ~CvMTest1D() {}
108 
109  inline virtual std::string shortName() const {return "CvM";}
110 
111  inline virtual double testStatistic(
112  const double* data, const unsigned long sz, const bool b) const
113  {return testStat(data, sz, b);}
114 
115  inline virtual double testStatistic(
116  const float* data, const unsigned long sz, const bool b) const
117  {return testStat(data, sz, b);}
118 
119  inline virtual bool hasAnalyticPValue() const {return true;}
120 
121  virtual double analyticPValue(double stat, unsigned long sz) const;
122 
123  private:
124  template<typename Numeric>
125  double testStat(const Numeric* data, unsigned long lenData,
126  bool dataIsSorted) const;
127  };
128 
129  /**
130  // Jin Zhang's ZK test. For this and other Jin Zhang's tests, see
131  // Jin Zhang, "Powerful Goodness-of-Fit Tests Based on the Likelihood
132  // Ratio", Journal of the Royal Statistical Society. Series B
133  // (Statistical Methodology), Vol. 64, No. 2 (2002), pp. 281-294.
134  */
136  {
137  public:
138  inline explicit ZhangZKTest1D(const AbsDistribution1D& d)
139  : AbsUnbinnedGOFTest1D(d) {}
140 
141  inline virtual ~ZhangZKTest1D() {}
142 
143  inline virtual std::string shortName() const {return "ZK";}
144 
145  inline virtual double testStatistic(
146  const double* data, const unsigned long sz, const bool b) const
147  {return testStat(data, sz, b);}
148 
149  inline virtual double testStatistic(
150  const float* data, const unsigned long sz, const bool b) const
151  {return testStat(data, sz, b);}
152 
153  private:
154  template<typename Numeric>
155  double testStat(const Numeric* data, unsigned long lenData,
156  bool dataIsSorted) const;
157  };
158 
159  /** Jin Zhang's ZA test */
161  {
162  public:
163  inline explicit ZhangZATest1D(const AbsDistribution1D& d)
164  : AbsUnbinnedGOFTest1D(d) {}
165 
166  inline virtual ~ZhangZATest1D() {}
167 
168  inline virtual std::string shortName() const {return "ZA";}
169 
170  inline virtual double testStatistic(
171  const double* data, const unsigned long sz, const bool b) const
172  {return testStat(data, sz, b);}
173 
174  inline virtual double testStatistic(
175  const float* data, const unsigned long sz, const bool b) const
176  {return testStat(data, sz, b);}
177 
178  private:
179  template<typename Numeric>
180  double testStat(const Numeric* data, unsigned long lenData,
181  bool dataIsSorted) const;
182  };
183 
184  /** Jin Zhang's ZC test */
186  {
187  public:
188  inline explicit ZhangZCTest1D(const AbsDistribution1D& d)
189  : AbsUnbinnedGOFTest1D(d) {}
190 
191  inline virtual ~ZhangZCTest1D() {}
192 
193  inline virtual std::string shortName() const {return "ZC";}
194 
195  inline virtual double testStatistic(
196  const double* data, const unsigned long sz, const bool b) const
197  {return testStat(data, sz, b);}
198 
199  inline virtual double testStatistic(
200  const float* data, const unsigned long sz, const bool b) const
201  {return testStat(data, sz, b);}
202 
203  private:
204  template<typename Numeric>
205  double testStat(const Numeric* data, unsigned long lenData,
206  bool dataIsSorted) const;
207  };
208 }
209 
210 #include "npstat/stat/UnbinnedGOFTests1D.icc"
211 
212 #endif // NPSTAT_UNBINNEDGOFTESTS1D_HH_
Interface definition for goodness-of-fit tests for 1-d distributions.
Definition: UnbinnedGOFTests1D.hh:73
Definition: AbsUnbinnedGOFTest1D.hh:24
Definition: UnbinnedGOFTests1D.hh:102
Definition: UnbinnedGOFTests1D.hh:19
Definition: UnbinnedGOFTests1D.hh:48
Definition: UnbinnedGOFTests1D.hh:161
Definition: UnbinnedGOFTests1D.hh:186
Definition: UnbinnedGOFTests1D.hh:136
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31