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