1 | #ifndef _theplu_yat_statistics_ttest_ |
---|
2 | #define _theplu_yat_statistics_ttest_ |
---|
3 | |
---|
4 | // $Id: tTest.h 3114 2013-11-10 23:51:47Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004, 2005 Peter Johansson |
---|
8 | Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
---|
9 | Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
10 | Copyright (C) 2013 Peter Johansson |
---|
11 | |
---|
12 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
13 | |
---|
14 | The yat library is free software; you can redistribute it and/or |
---|
15 | modify it under the terms of the GNU General Public License as |
---|
16 | published by the Free Software Foundation; either version 3 of the |
---|
17 | License, or (at your option) any later version. |
---|
18 | |
---|
19 | The yat library is distributed in the hope that it will be useful, |
---|
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
22 | General Public License for more details. |
---|
23 | |
---|
24 | You should have received a copy of the GNU General Public License |
---|
25 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "AveragerWeighted.h" |
---|
29 | #include "yat/utility/deprecate.h" |
---|
30 | |
---|
31 | #include <gsl/gsl_cdf.h> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | namespace statistics { |
---|
36 | |
---|
37 | /// |
---|
38 | /// @brief Class for Student's t-test. |
---|
39 | /// |
---|
40 | /// See <a href="http://en.wikipedia.org/wiki/Student's_t-test"> |
---|
41 | /// http://en.wikipedia.org/wiki/Student's_t-test</a> for more |
---|
42 | /// details on the t-test. |
---|
43 | /// |
---|
44 | class tTest |
---|
45 | { |
---|
46 | |
---|
47 | public: |
---|
48 | /// |
---|
49 | /// @brief Default Constructor. |
---|
50 | /// |
---|
51 | tTest(void); |
---|
52 | |
---|
53 | |
---|
54 | /** |
---|
55 | Adding a data value to tTest. |
---|
56 | */ |
---|
57 | void add(double value, bool target, double weight=1.0); |
---|
58 | |
---|
59 | /** |
---|
60 | \brief Set everything to zero |
---|
61 | |
---|
62 | \since New in yat 0.5 |
---|
63 | */ |
---|
64 | void reset(void); |
---|
65 | |
---|
66 | /** |
---|
67 | Calculates the t-score, i.e. the ratio between difference in |
---|
68 | mean and standard deviation of this difference. The t-score is |
---|
69 | calculated as |
---|
70 | \f$ t = \frac{ m_x - m_y }{ |
---|
71 | s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is the |
---|
72 | weighted mean, n is the weighted version of number of data |
---|
73 | points \f$ \frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$, and |
---|
74 | \f$ s^2 \f$ is an estimation of the variance \f$ s^2 = \frac{ |
---|
75 | \sum_i w_i(x_i-m_x)^2 + \sum_i w_i(y_i-m_y)^2 }{ n_x + n_y - 2 |
---|
76 | } \f$ |
---|
77 | |
---|
78 | \see AveragerWeighted |
---|
79 | |
---|
80 | If all weights are equal to unity this boils down to |
---|
81 | \f$ t = \frac{ m_x - m_y } |
---|
82 | {s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is |
---|
83 | the mean, \f$ n \f$ is the number of data points and \f$ s^2 = |
---|
84 | \frac{ \sum_i (x_i-m_x)^2 + \sum_i (y_i-m_y)^2 }{ n_x + n_y - 2 |
---|
85 | } \f$ |
---|
86 | |
---|
87 | \see Averager |
---|
88 | |
---|
89 | \return t-score. |
---|
90 | */ |
---|
91 | double score(void) const; |
---|
92 | |
---|
93 | /** |
---|
94 | \return the probability of observing a t-score that is equal or |
---|
95 | smaller than score(). |
---|
96 | */ |
---|
97 | double p_left(void) const; |
---|
98 | |
---|
99 | /** |
---|
100 | \return the one-sided p-value, i.e., the probability of |
---|
101 | observing a t-score that is equal or greater than observed |
---|
102 | here. |
---|
103 | */ |
---|
104 | double p_right(void) const; |
---|
105 | |
---|
106 | /** |
---|
107 | Calculates the two-sided p-value, i.e., the probability to |
---|
108 | observe a t-score equal (or greater) than |t| or smaller than |
---|
109 | -|t|, where t is the observed t-score (returned by score()). |
---|
110 | |
---|
111 | \return the two-sided p-value |
---|
112 | */ |
---|
113 | double p_value() const; |
---|
114 | |
---|
115 | /** |
---|
116 | \deprecated Provided for backward compatibility with 0.10 |
---|
117 | API. Use p_right() instead. |
---|
118 | */ |
---|
119 | double p_value_one_sided(void) const YAT_DEPRECATE; |
---|
120 | |
---|
121 | private: |
---|
122 | |
---|
123 | mutable double dof_; |
---|
124 | mutable bool updated_; |
---|
125 | mutable double t_; |
---|
126 | AveragerWeighted pos_; |
---|
127 | AveragerWeighted neg_; |
---|
128 | }; |
---|
129 | |
---|
130 | }}} // of namespace statistics, yat, and theplu |
---|
131 | |
---|
132 | #endif |
---|