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

Last change on this file since 831 was 831, checked in by Peter, 16 years ago

Refs #185.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1#ifndef _theplu_yat_statistics_ttest_
2#define _theplu_yat_statistics_ttest_
3
4// $Id: tTest.h 831 2007-03-27 13:22:09Z peter $
5
6/*
7  Copyright (C) 2004, 2005 Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
9  Copyright (C) 2007 Peter Johansson
10
11  This file is part of the yat library, http://lev.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29#include "AveragerWeighted.h"
30
31#include <gsl/gsl_cdf.h>
32
33namespace theplu {
34namespace yat {
35namespace statistics { 
36
37  ///
38  /// @brief Class for Fisher'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       Calculates the t-score, i.e. the ratio between difference in
61       mean and standard deviation of this difference. The t-score is
62       calculated as
63       \f$ t = \frac{ m_x - m_y }{
64       s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is the
65       weighted mean, n is the weighted version of number of data
66       points \f$ \frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$, and
67       \f$ s^2 \f$ is an estimation of the variance \f$ s^2 = \frac{
68       \sum_i w_i(x_i-m_x)^2 + \sum_i w_i(y_i-m_y)^2 }{ n_x + n_y - 2
69       } \f$
70
71       \see AveragerWeighted
72
73       If all weights are equal to unity this boils down to
74       \f$ t = \frac{ m_x - m_y }
75       {s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is
76       the mean, \f$ n \f$ is the number of data points and \f$ s^2 =
77       \frac{ \sum_i (x_i-m_x)^2 + \sum_i (y_i-m_y)^2 }{ n_x + n_y - 2
78       } \f$
79
80       \see Averager
81       
82       \return t-score.
83    */
84    double score(void); 
85
86    ///
87    /// Calculates the p-value, i.e. the probability of observing a
88    /// t-score equally or larger if the null hypothesis is true. If P
89    /// is near zero, this casts doubt on this hypothesis. The null
90    /// hypothesis is that the means of the two distributions are
91    /// equal. Assumtions for this test is that the two distributions
92    /// are normal distributions with equal variance. The latter
93    /// assumtion is dropped in Welch's t-test.
94    ///
95    /// @return the two-sided p-value
96    ///
97    double p_value() const;
98
99    ///
100    /// @return One-sided P-value
101    ///
102    double p_value_one_sided(void) const;
103
104  private:
105
106    double dof_;
107    bool updated_;
108    double t_;
109    AveragerWeighted pos_;
110    AveragerWeighted neg_;
111
112  };
113
114}}} // of namespace statistics, yat, and theplu
115
116#endif
Note: See TracBrowser for help on using the repository browser.