source: trunk/yat/statistics/tScore.h @ 680

Last change on this file since 680 was 680, checked in by Jari Häkkinen, 15 years ago

Addresses #153. Introduced yat namespace. Removed alignment namespace. Clean up of code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1#ifndef _theplu_yat_statistics_tscore_
2#define _theplu_yat_statistics_tscore_
3
4// $Id: tScore.h 680 2006-10-11 17:49:03Z jari $
5
6/*
7  Copyright (C) The authors contributing to this file.
8
9  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "Score.h"
28
29#include <gsl/gsl_cdf.h>
30
31
32namespace theplu {
33namespace yat {
34  namespace utility {
35    class vector;
36  }
37namespace statistics { 
38
39  ///
40  /// Class for Fisher's t-test.
41  ///   
42  /// See <a href="http://en.wikipedia.org/wiki/Student's_t-test">
43  /// http://en.wikipedia.org/wiki/Student's_t-test</a> for more
44  /// details on the t-test.
45  ///
46  class tScore : public Score
47  {
48 
49  public:
50    ///
51    /// Default Constructor.
52    ///
53    tScore(bool absolute=true);
54
55   
56    /**
57       Calculates the value of t-score, i.e. the ratio between
58       difference in mean and standard deviation of this
59       difference. \f$ t = \frac{ m_x - m_y }
60       {s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is the
61       mean, \f$ n \f$ is the number of data points and \f$ s^2 =
62       \frac{ \sum_i (x_i-m_x)^2 + \sum_i (y_i-m_y)^2 }{ n_x + n_y -
63       2 } \f$
64       
65       @return t-score. If absolute=true absolute value of t-score
66       is returned
67    */
68    double score(const classifier::Target& target, 
69                 const utility::vector& value); 
70
71    /**
72       Calculates the weighted t-score, i.e. the ratio between
73       difference in mean and standard deviation of this
74       difference. \f$ t = \frac{ m_x - m_y }{
75       s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is the
76       weighted mean, n is the weighted version of number of data
77       points \f$ \frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$, and
78       \f$ s^2 \f$ is an estimation of the variance \f$ s^2 = \frac{
79       \sum_i w_i(x_i-m_x)^2 + \sum_i w_i(y_i-m_y)^2 }{ n_x + n_y - 2
80       } \f$. See AveragerWeighted for details.
81       
82       @return t-score. If absolute=true absolute value of t-score
83       is returned
84    */
85    double score(const classifier::Target& target, 
86                 const classifier::DataLookupWeighted1D& value); 
87
88    ///
89    /// Calculates the weighted t-score, i.e. the ratio between
90    /// difference in mean and standard deviation of this
91    /// difference. \f$ t = \frac{ m_x - m_y }{
92    /// \frac{s2}{n_x}+\frac{s2}{n_y}} \f$ where \f$ m \f$ is the
93    /// weighted mean, n is the weighted version of number of data
94    /// points and \f$ s2 \f$ is an estimation of the variance \f$ s^2
95    /// = \frac{ \sum_i w_i(x_i-m_x)^2 + \sum_i w_i(y_i-m_y)^2 }{ n_x
96    /// + n_y - 2 } \f$. See AveragerWeighted for details.
97    ///
98    /// @return t-score if absolute=true absolute value of t-score
99    /// is returned
100    ///
101    double score(const classifier::Target& target, 
102                 const utility::vector& value, 
103                 const utility::vector& weight); 
104
105    ///
106    /// Calculates the p-value, i.e. the probability of observing a
107    /// t-score equally or larger if the null hypothesis is true. If P
108    /// is near zero, this casts doubt on this hypothesis. The null
109    /// hypothesis is that the means of the two distributions are
110    /// equal. Assumtions for this test is that the two distributions
111    /// are normal distributions with equal variance. The latter
112    /// assumtion is dropped in Welch's t-test.
113    ///
114    /// @return the one-sided p-value( if absolute=true is used
115    /// the two-sided p-value)
116    ///
117    double p_value() const;
118
119         
120         
121  private:
122    double t_;
123    double dof_;
124       
125  };
126
127}}} // of namespace statistics, yat and theplu
128
129#endif
130
Note: See TracBrowser for help on using the repository browser.