yat/statistics/PearsonCorrelation.cc

Code
Comments
Other
Rev Date Author Line
139 20 Aug 04 peter 1 // $Id$
139 20 Aug 04 peter 2
675 10 Oct 06 jari 3 /*
831 27 Mar 07 peter 4   Copyright (C) 2004, 2005 Peter Johansson
4359 23 Aug 23 peter 5   Copyright (C) 2006 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 6   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 7   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
3114 10 Nov 13 peter 8   Copyright (C) 2009, 2012, 2013 Peter Johansson
295 29 Apr 05 peter 9
1437 25 Aug 08 peter 10   This file is part of the yat library, http://dev.thep.lu.se/yat
675 10 Oct 06 jari 11
675 10 Oct 06 jari 12   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 13   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 14   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 15   License, or (at your option) any later version.
675 10 Oct 06 jari 16
675 10 Oct 06 jari 17   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 18   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 20   General Public License for more details.
675 10 Oct 06 jari 21
675 10 Oct 06 jari 22   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 23   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 24 */
675 10 Oct 06 jari 25
2881 18 Nov 12 peter 26 #include <config.h>
2881 18 Nov 12 peter 27
779 05 Mar 07 peter 28 #include "PearsonCorrelation.h"
1145 25 Feb 08 peter 29 #include "utility.h"
675 10 Oct 06 jari 30
139 20 Aug 04 peter 31 namespace theplu {
680 11 Oct 06 jari 32 namespace yat {
3005 24 Mar 13 peter 33 namespace statistics {
139 20 Aug 04 peter 34
3005 24 Mar 13 peter 35   PearsonCorrelation::PearsonCorrelation(void)
139 20 Aug 04 peter 36   {
139 20 Aug 04 peter 37   }
139 20 Aug 04 peter 38
1794 11 Feb 09 peter 39
779 05 Mar 07 peter 40   PearsonCorrelation::~PearsonCorrelation(void)
703 18 Dec 06 jari 41   {
703 18 Dec 06 jari 42   }
703 18 Dec 06 jari 43
1794 11 Feb 09 peter 44
1794 11 Feb 09 peter 45   void PearsonCorrelation::add(double value, bool target, double weight)
1794 11 Feb 09 peter 46   {
1794 11 Feb 09 peter 47     ap_.add(value, target ? 1.0 : -1.0, weight, 1.0);
1794 11 Feb 09 peter 48   }
1794 11 Feb 09 peter 49
1794 11 Feb 09 peter 50
1794 11 Feb 09 peter 51   double PearsonCorrelation::score(void) const
1794 11 Feb 09 peter 52   {
1794 11 Feb 09 peter 53     return ap_.correlation();
1794 11 Feb 09 peter 54   }
1794 11 Feb 09 peter 55
1794 11 Feb 09 peter 56
3005 24 Mar 13 peter 57   double PearsonCorrelation::p_right(void) const
139 20 Aug 04 peter 58   {
3005 24 Mar 13 peter 59     return pearson_p_value(ap_.correlation(),
3005 24 Mar 13 peter 60                            static_cast<unsigned int>(ap_.n()));
139 20 Aug 04 peter 61   }
139 20 Aug 04 peter 62
3005 24 Mar 13 peter 63
3005 24 Mar 13 peter 64   double PearsonCorrelation::p_left(void) const
3005 24 Mar 13 peter 65   {
3005 24 Mar 13 peter 66     return pearson_p_value(-ap_.correlation(),
3005 24 Mar 13 peter 67                            static_cast<unsigned int>(ap_.n()));
3005 24 Mar 13 peter 68   }
3005 24 Mar 13 peter 69
3005 24 Mar 13 peter 70
3005 24 Mar 13 peter 71   double PearsonCorrelation::p_value_one_sided(void) const
3005 24 Mar 13 peter 72   {
3005 24 Mar 13 peter 73     return p_right();
3005 24 Mar 13 peter 74   }
3005 24 Mar 13 peter 75
3005 24 Mar 13 peter 76
3005 24 Mar 13 peter 77   double PearsonCorrelation::p_value(void) const
3005 24 Mar 13 peter 78   {
3005 24 Mar 13 peter 79     double r = ap_.correlation();
3005 24 Mar 13 peter 80     if (r>0)
3005 24 Mar 13 peter 81       return 2*p_right();
3005 24 Mar 13 peter 82     return 2*p_left();
3005 24 Mar 13 peter 83   }
3005 24 Mar 13 peter 84
683 11 Oct 06 jari 85 }}} // of namespace statistics, yat, and theplu