source: trunk/yat/statistics/tTest.h @ 3023

Last change on this file since 3023 was 3023, checked in by Peter, 9 years ago

closes #754. ROC::area() is now const

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