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