yat  0.21pre
Chi2.h
1 #ifndef _theplu_yat_statistics_chi2_
2 #define _theplu_yat_statistics_chi2_
3 
4 // $Id: Chi2.h 4207 2022-08-26 04:36:28Z peter $
5 
6 /*
7  Copyright (C) 2018, 2022 Peter Johansson
8 
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include <yat/utility/Matrix.h>
26 
27 namespace theplu {
28 namespace yat {
29 namespace statistics {
30 
36  class Chi2
37  {
38  public:
42  unsigned int dof(void) const;
43 
52  const utility::Matrix& expected(void) const;
53 
57  double p_value(void) const;
58 
69  double p_value(size_t N) const;
70 
74  double operator()(void);
75 
86  double operator()(const utility::MatrixBase& data);
87 
88  private:
89  double chi2_;
90  utility::Matrix expected_;
91  utility::Vector rowsum_;
92  utility::Vector colsum_;
93  unsigned long int total_;
94 
95  void calculate_expected(const utility::MatrixBase& data);
96  void calculate_rowsum(const utility::MatrixBase& data);
97  void calculate_colsum(const utility::MatrixBase& data);
98 
99  // Create a matrix with non-negative integers such that the sum of
100  // row r is rowsum_(r) and sum of column c is colsum_(c)
101  utility::Matrix generate_random_data(void) const;
102 
103  double chi2sum(const utility::MatrixBase& data,
104  const utility::Matrix& expected) const;
105 
106  size_t draw(const utility::Vector& count, unsigned long int N) const;
107 
108  struct Calculator
109  {
110  double operator()(double x, double m) const;
111  };
112  };
113 
114 }}} // of namespace statistics, yat, and theplu
115 
116 #endif
Definition: MatrixBase.h:54
unsigned int dof(void) const
The Department of Theoretical Physics namespace as we define it.
This is the yat interface to GSL vector.
Definition: Vector.h:59
double p_value(void) const
Chi squared test.
Definition: Chi2.h:36
const utility::Matrix & expected(void) const
Interface to GSL matrix.
Definition: Matrix.h:104

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14