source: trunk/yat/statistics/PearsonCorrelation.h @ 1024

Last change on this file since 1024 was 1024, checked in by Peter, 14 years ago

passing VectorBase? in regression::PearsonCorrelation? - refs #256

  • 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_pearson_correlation_
2#define _theplu_yat_statistics_pearson_correlation_
3
4// $Id: PearsonCorrelation.h 1024 2008-02-01 18:18:21Z 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://trac.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 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 "Score.h"
30
31namespace theplu {
32namespace yat {
33namespace utility {
34  class VectorBase;
35}
36namespace statistics {
37
38  ///
39  /// @brief Class for calculating Pearson correlation.
40  ///
41  class PearsonCorrelation
42  {
43  public:
44    ///
45    /// @brief The default constructor.
46    ///
47    PearsonCorrelation(void);
48   
49    ///
50    /// @brief The destructor.
51    ///
52    virtual ~PearsonCorrelation(void);
53   
54   
55    /**
56       \f$ \frac{\vert \sum_i(x_i-\bar{x})(y_i-\bar{y})\vert
57       }{\sqrt{\sum_i (x_i-\bar{x})^2\sum_i (x_i-\bar{x})^2}} \f$.
58       @return Pearson correlation, if absolute=true absolute value
59       of Pearson is used.
60    */
61    double score(const classifier::Target& target, 
62                 const utility::VectorBase& value);
63   
64    /**
65       \f$ \frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert }
66       {\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}}
67       \f$, where \f$ m_x = \frac{\sum w_ix_i}{\sum w_i} \f$ and \f$
68       m_x = \frac{\sum w_ix_i}{\sum w_i} \f$. This expression is
69       chosen to get a correlation equal to unity when \a x and \a y
70       are equal. @return absolute value of weighted version of
71       Pearson correlation.
72    */
73    double score(const classifier::Target& target, 
74                 const classifier::DataLookupWeighted1D& value); 
75   
76    /**
77       \f$ \frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert }
78       {\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}}
79       \f$, where \f$ m_x = \frac{\sum w_ix_i}{\sum w_i} \f$ and \f$
80       m_x = \frac{\sum w_ix_i}{\sum w_i} \f$. This expression is
81       chosen to get a correlation equal to unity when \a x and \a y
82       are equal. @return absolute value of weighted version of
83       Pearson correlation.
84    */
85    double score(const classifier::Target& target, 
86                 const utility::VectorBase& value,
87                 const utility::VectorBase& weight); 
88   
89    /**
90       The p-value is the probability of getting a correlation as
91       large (or larger) as the observed value by random chance, when the true
92       correlation is zero (and the data is Gaussian).
93       
94       @Note This function can only be used together with the
95       unweighted score.
96       
97       @return one-sided p-value
98    */
99    double p_value_one_sided() const;
100   
101  private:
102    double r_;
103    int nof_samples_;
104   
105  };
106 
107}}} // of namespace statistics, yat, and theplu
108
109#endif
Note: See TracBrowser for help on using the repository browser.