779 |
05 Mar 07 |
peter |
1 |
#ifndef _theplu_yat_statistics_ttest_ |
3023 |
06 Apr 13 |
peter |
2 |
#define _theplu_yat_statistics_ttest_ |
616 |
31 Aug 06 |
jari |
3 |
|
98 |
10 Jun 04 |
peter |
// $Id$ |
98 |
10 Jun 04 |
peter |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
831 |
27 Mar 07 |
peter |
Copyright (C) 2004, 2005 Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
3114 |
10 Nov 13 |
peter |
Copyright (C) 2013 Peter Johansson |
295 |
29 Apr 05 |
peter |
12 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
14 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
19 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
24 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
27 |
*/ |
675 |
10 Oct 06 |
jari |
28 |
|
822 |
18 Mar 07 |
peter |
29 |
#include "AveragerWeighted.h" |
3023 |
06 Apr 13 |
peter |
30 |
#include "yat/utility/deprecate.h" |
822 |
18 Mar 07 |
peter |
31 |
|
98 |
10 Jun 04 |
peter |
32 |
#include <gsl/gsl_cdf.h> |
98 |
10 Jun 04 |
peter |
33 |
|
98 |
10 Jun 04 |
peter |
34 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
35 |
namespace yat { |
3023 |
06 Apr 13 |
peter |
36 |
namespace statistics { |
414 |
01 Dec 05 |
peter |
37 |
|
98 |
10 Jun 04 |
peter |
38 |
/// |
1145 |
25 Feb 08 |
peter |
/// @brief Class for Student's t-test. |
3023 |
06 Apr 13 |
peter |
40 |
/// |
589 |
24 Aug 06 |
peter |
/// See <a href="http://en.wikipedia.org/wiki/Student's_t-test"> |
589 |
24 Aug 06 |
peter |
/// http://en.wikipedia.org/wiki/Student's_t-test</a> for more |
589 |
24 Aug 06 |
peter |
/// details on the t-test. |
3023 |
06 Apr 13 |
peter |
44 |
/// |
779 |
05 Mar 07 |
peter |
45 |
class tTest |
98 |
10 Jun 04 |
peter |
46 |
{ |
3023 |
06 Apr 13 |
peter |
47 |
|
98 |
10 Jun 04 |
peter |
48 |
public: |
98 |
10 Jun 04 |
peter |
49 |
/// |
779 |
05 Mar 07 |
peter |
/// @brief Default Constructor. |
102 |
15 Jun 04 |
peter |
51 |
/// |
822 |
18 Mar 07 |
peter |
52 |
tTest(void); |
102 |
15 Jun 04 |
peter |
53 |
|
3023 |
06 Apr 13 |
peter |
54 |
|
669 |
07 Oct 06 |
peter |
55 |
/** |
822 |
18 Mar 07 |
peter |
Adding a data value to tTest. |
669 |
07 Oct 06 |
peter |
57 |
*/ |
822 |
18 Mar 07 |
peter |
58 |
void add(double value, bool target, double weight=1.0); |
119 |
20 Jul 04 |
peter |
59 |
|
822 |
18 Mar 07 |
peter |
60 |
/** |
1451 |
28 Aug 08 |
peter |
\brief Set everything to zero |
1451 |
28 Aug 08 |
peter |
62 |
|
1451 |
28 Aug 08 |
peter |
\since New in yat 0.5 |
1451 |
28 Aug 08 |
peter |
64 |
*/ |
1451 |
28 Aug 08 |
peter |
65 |
void reset(void); |
1451 |
28 Aug 08 |
peter |
66 |
|
1451 |
28 Aug 08 |
peter |
67 |
/** |
822 |
18 Mar 07 |
peter |
Calculates the t-score, i.e. the ratio between difference in |
822 |
18 Mar 07 |
peter |
mean and standard deviation of this difference. The t-score is |
3023 |
06 Apr 13 |
peter |
calculated as |
822 |
18 Mar 07 |
peter |
\f$ t = \frac{ m_x - m_y }{ |
669 |
07 Oct 06 |
peter |
s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is the |
669 |
07 Oct 06 |
peter |
weighted mean, n is the weighted version of number of data |
669 |
07 Oct 06 |
peter |
points \f$ \frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$, and |
669 |
07 Oct 06 |
peter |
\f$ s^2 \f$ is an estimation of the variance \f$ s^2 = \frac{ |
669 |
07 Oct 06 |
peter |
\sum_i w_i(x_i-m_x)^2 + \sum_i w_i(y_i-m_y)^2 }{ n_x + n_y - 2 |
822 |
18 Mar 07 |
peter |
} \f$ |
822 |
18 Mar 07 |
peter |
78 |
|
822 |
18 Mar 07 |
peter |
\see AveragerWeighted |
822 |
18 Mar 07 |
peter |
80 |
|
3023 |
06 Apr 13 |
peter |
If all weights are equal to unity this boils down to |
822 |
18 Mar 07 |
peter |
\f$ t = \frac{ m_x - m_y } |
822 |
18 Mar 07 |
peter |
{s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is |
822 |
18 Mar 07 |
peter |
the mean, \f$ n \f$ is the number of data points and \f$ s^2 = |
822 |
18 Mar 07 |
peter |
\frac{ \sum_i (x_i-m_x)^2 + \sum_i (y_i-m_y)^2 }{ n_x + n_y - 2 |
822 |
18 Mar 07 |
peter |
} \f$ |
822 |
18 Mar 07 |
peter |
87 |
|
822 |
18 Mar 07 |
peter |
\see Averager |
3023 |
06 Apr 13 |
peter |
89 |
|
822 |
18 Mar 07 |
peter |
\return t-score. |
669 |
07 Oct 06 |
peter |
91 |
*/ |
3024 |
06 Apr 13 |
peter |
92 |
double score(void) const; |
623 |
05 Sep 06 |
peter |
93 |
|
3023 |
06 Apr 13 |
peter |
94 |
/** |
3023 |
06 Apr 13 |
peter |
\return the probability of observing a t-score that is equal or |
3023 |
06 Apr 13 |
peter |
smaller than score(). |
3023 |
06 Apr 13 |
peter |
97 |
*/ |
3023 |
06 Apr 13 |
peter |
98 |
double p_left(void) const; |
3023 |
06 Apr 13 |
peter |
99 |
|
3023 |
06 Apr 13 |
peter |
100 |
/** |
3023 |
06 Apr 13 |
peter |
\return the one-sided p-value, i.e., the probability of |
3023 |
06 Apr 13 |
peter |
observing a t-score that is equal or greater than observed |
3023 |
06 Apr 13 |
peter |
here. |
3023 |
06 Apr 13 |
peter |
104 |
*/ |
3023 |
06 Apr 13 |
peter |
105 |
double p_right(void) const; |
3023 |
06 Apr 13 |
peter |
106 |
|
3023 |
06 Apr 13 |
peter |
107 |
/** |
3023 |
06 Apr 13 |
peter |
Calculates the two-sided p-value, i.e., the probability to |
3023 |
06 Apr 13 |
peter |
observe a t-score equal (or greater) than |t| or smaller than |
3023 |
06 Apr 13 |
peter |
-|t|, where t is the observed t-score (returned by score()). |
3023 |
06 Apr 13 |
peter |
111 |
|
3023 |
06 Apr 13 |
peter |
\return the two-sided p-value |
3023 |
06 Apr 13 |
peter |
113 |
*/ |
187 |
18 Oct 04 |
peter |
114 |
double p_value() const; |
179 |
04 Oct 04 |
peter |
115 |
|
3023 |
06 Apr 13 |
peter |
116 |
/** |
3023 |
06 Apr 13 |
peter |
\deprecated Provided for backward compatibility with 0.10 |
3023 |
06 Apr 13 |
peter |
API. Use p_right() instead. |
3023 |
06 Apr 13 |
peter |
119 |
*/ |
3023 |
06 Apr 13 |
peter |
120 |
double p_value_one_sided(void) const YAT_DEPRECATE; |
779 |
05 Mar 07 |
peter |
121 |
|
98 |
10 Jun 04 |
peter |
122 |
private: |
822 |
18 Mar 07 |
peter |
123 |
|
3024 |
06 Apr 13 |
peter |
124 |
mutable double dof_; |
3024 |
06 Apr 13 |
peter |
125 |
mutable bool updated_; |
3024 |
06 Apr 13 |
peter |
126 |
mutable double t_; |
822 |
18 Mar 07 |
peter |
127 |
AveragerWeighted pos_; |
822 |
18 Mar 07 |
peter |
128 |
AveragerWeighted neg_; |
98 |
10 Jun 04 |
peter |
129 |
}; |
98 |
10 Jun 04 |
peter |
130 |
|
683 |
11 Oct 06 |
jari |
131 |
}}} // of namespace statistics, yat, and theplu |
98 |
10 Jun 04 |
peter |
132 |
|
98 |
10 Jun 04 |
peter |
133 |
#endif |