yat/statistics/tTest.h

Code
Comments
Other
Rev Date Author Line
779 05 Mar 07 peter 1 #ifndef _theplu_yat_statistics_ttest_
3023 06 Apr 13 peter 2 #define _theplu_yat_statistics_ttest_
616 31 Aug 06 jari 3
98 10 Jun 04 peter 4 // $Id$
98 10 Jun 04 peter 5
675 10 Oct 06 jari 6 /*
831 27 Mar 07 peter 7   Copyright (C) 2004, 2005 Peter Johansson
2119 12 Dec 09 peter 8   Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
4359 23 Aug 23 peter 9   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 10   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
3114 10 Nov 13 peter 11   Copyright (C) 2013 Peter Johansson
295 29 Apr 05 peter 12
1437 25 Aug 08 peter 13   This file is part of the yat library, http://dev.thep.lu.se/yat
675 10 Oct 06 jari 14
675 10 Oct 06 jari 15   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 16   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 17   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 18   License, or (at your option) any later version.
675 10 Oct 06 jari 19
675 10 Oct 06 jari 20   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 21   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 22   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 23   General Public License for more details.
675 10 Oct 06 jari 24
675 10 Oct 06 jari 25   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 26   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 27 */
675 10 Oct 06 jari 28
822 18 Mar 07 peter 29 #include "AveragerWeighted.h"
3023 06 Apr 13 peter 30 #include "yat/utility/deprecate.h"
822 18 Mar 07 peter 31
98 10 Jun 04 peter 32 #include <gsl/gsl_cdf.h>
98 10 Jun 04 peter 33
98 10 Jun 04 peter 34 namespace theplu {
680 11 Oct 06 jari 35 namespace yat {
3023 06 Apr 13 peter 36 namespace statistics {
414 01 Dec 05 peter 37
98 10 Jun 04 peter 38   ///
1145 25 Feb 08 peter 39   /// @brief Class for Student's t-test.
3023 06 Apr 13 peter 40   ///
589 24 Aug 06 peter 41   /// See <a href="http://en.wikipedia.org/wiki/Student's_t-test">
589 24 Aug 06 peter 42   /// http://en.wikipedia.org/wiki/Student's_t-test</a> for more
589 24 Aug 06 peter 43   /// details on the t-test.
3023 06 Apr 13 peter 44   ///
779 05 Mar 07 peter 45   class tTest
98 10 Jun 04 peter 46   {
3023 06 Apr 13 peter 47
98 10 Jun 04 peter 48   public:
98 10 Jun 04 peter 49     ///
779 05 Mar 07 peter 50     /// @brief Default Constructor.
102 15 Jun 04 peter 51     ///
822 18 Mar 07 peter 52     tTest(void);
102 15 Jun 04 peter 53
3023 06 Apr 13 peter 54
669 07 Oct 06 peter 55     /**
822 18 Mar 07 peter 56        Adding a data value to tTest.
669 07 Oct 06 peter 57     */
822 18 Mar 07 peter 58     void add(double value, bool target, double weight=1.0);
119 20 Jul 04 peter 59
822 18 Mar 07 peter 60     /**
1451 28 Aug 08 peter 61        \brief Set everything to zero
1451 28 Aug 08 peter 62
1451 28 Aug 08 peter 63        \since New in yat 0.5
1451 28 Aug 08 peter 64      */
1451 28 Aug 08 peter 65     void reset(void);
1451 28 Aug 08 peter 66
1451 28 Aug 08 peter 67     /**
822 18 Mar 07 peter 68        Calculates the t-score, i.e. the ratio between difference in
822 18 Mar 07 peter 69        mean and standard deviation of this difference. The t-score is
3023 06 Apr 13 peter 70        calculated as
822 18 Mar 07 peter 71        \f$ t = \frac{ m_x - m_y }{
669 07 Oct 06 peter 72        s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is the
669 07 Oct 06 peter 73        weighted mean, n is the weighted version of number of data
669 07 Oct 06 peter 74        points \f$ \frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$, and
669 07 Oct 06 peter 75        \f$ s^2 \f$ is an estimation of the variance \f$ s^2 = \frac{
669 07 Oct 06 peter 76        \sum_i w_i(x_i-m_x)^2 + \sum_i w_i(y_i-m_y)^2 }{ n_x + n_y - 2
822 18 Mar 07 peter 77        } \f$
822 18 Mar 07 peter 78
822 18 Mar 07 peter 79        \see AveragerWeighted
822 18 Mar 07 peter 80
3023 06 Apr 13 peter 81        If all weights are equal to unity this boils down to
822 18 Mar 07 peter 82        \f$ t = \frac{ m_x - m_y }
822 18 Mar 07 peter 83        {s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$ m \f$ is
822 18 Mar 07 peter 84        the mean, \f$ n \f$ is the number of data points and \f$ s^2 =
822 18 Mar 07 peter 85        \frac{ \sum_i (x_i-m_x)^2 + \sum_i (y_i-m_y)^2 }{ n_x + n_y - 2
822 18 Mar 07 peter 86        } \f$
822 18 Mar 07 peter 87
822 18 Mar 07 peter 88        \see Averager
3023 06 Apr 13 peter 89
822 18 Mar 07 peter 90        \return t-score.
669 07 Oct 06 peter 91     */
3024 06 Apr 13 peter 92     double score(void) const;
623 05 Sep 06 peter 93
3023 06 Apr 13 peter 94     /**
3023 06 Apr 13 peter 95        \return the probability of observing a t-score that is equal or
3023 06 Apr 13 peter 96        smaller than score().
3023 06 Apr 13 peter 97      */
3023 06 Apr 13 peter 98     double p_left(void) const;
3023 06 Apr 13 peter 99
3023 06 Apr 13 peter 100     /**
3023 06 Apr 13 peter 101        \return the one-sided p-value, i.e., the probability of
3023 06 Apr 13 peter 102        observing a t-score that is equal or greater than observed
3023 06 Apr 13 peter 103        here.
3023 06 Apr 13 peter 104      */
3023 06 Apr 13 peter 105     double p_right(void) const;
3023 06 Apr 13 peter 106
3023 06 Apr 13 peter 107     /**
3023 06 Apr 13 peter 108        Calculates the two-sided p-value, i.e., the probability to
3023 06 Apr 13 peter 109        observe a t-score equal (or greater) than |t| or smaller than
3023 06 Apr 13 peter 110        -|t|, where t is the observed t-score (returned by score()).
3023 06 Apr 13 peter 111
3023 06 Apr 13 peter 112      \return the two-sided p-value
3023 06 Apr 13 peter 113     */
187 18 Oct 04 peter 114     double p_value() const;
179 04 Oct 04 peter 115
3023 06 Apr 13 peter 116     /**
3023 06 Apr 13 peter 117        \deprecated Provided for backward compatibility with 0.10
3023 06 Apr 13 peter 118        API. Use p_right() instead.
3023 06 Apr 13 peter 119      */
3023 06 Apr 13 peter 120     double p_value_one_sided(void) const YAT_DEPRECATE;
779 05 Mar 07 peter 121
98 10 Jun 04 peter 122   private:
822 18 Mar 07 peter 123
3024 06 Apr 13 peter 124     mutable double dof_;
3024 06 Apr 13 peter 125     mutable bool updated_;
3024 06 Apr 13 peter 126     mutable double t_;
822 18 Mar 07 peter 127     AveragerWeighted pos_;
822 18 Mar 07 peter 128     AveragerWeighted neg_;
98 10 Jun 04 peter 129    };
98 10 Jun 04 peter 130
683 11 Oct 06 jari 131 }}} // of namespace statistics, yat, and theplu
98 10 Jun 04 peter 132
98 10 Jun 04 peter 133 #endif