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

Last change on this file since 1706 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1#ifndef _theplu_yat_statistics_ttest_
2#define _theplu_yat_statistics_ttest_
3
4// $Id: tTest.h 1487 2008-09-10 08:41:36Z jari $
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 Jari Häkkinen, Peter Johansson
10  Copyright (C) 2008 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
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    /// Calculates the p-value, i.e. the probability of observing a
94    /// t-score equally or larger if the null hypothesis is true. If P
95    /// is near zero, this casts doubt on this hypothesis. The null
96    /// hypothesis is that the means of the two distributions are
97    /// equal. Assumtions for this test is that the two distributions
98    /// are normal distributions with equal variance. The latter
99    /// assumtion is dropped in Welch's t-test.
100    ///
101    /// @return the two-sided p-value
102    ///
103    double p_value() const;
104
105    ///
106    /// @return One-sided P-value
107    ///
108    double p_value_one_sided(void) const;
109
110  private:
111
112    double dof_;
113    bool updated_;
114    double t_;
115    AveragerWeighted pos_;
116    AveragerWeighted neg_;
117
118  };
119
120}}} // of namespace statistics, yat, and theplu
121
122#endif
Note: See TracBrowser for help on using the repository browser.