#ifndef _theplu_yat_statistics_ttest_ #define _theplu_yat_statistics_ttest_ // $Id: tTest.h 1487 2008-09-10 08:41:36Z jari$ /* Copyright (C) 2004, 2005 Peter Johansson Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér Copyright (C) 2007 Jari Häkkinen, Peter Johansson Copyright (C) 2008 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The yat library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with yat. If not, see . */ #include "AveragerWeighted.h" #include namespace theplu { namespace yat { namespace statistics { /// /// @brief Class for Student's t-test. /// /// See /// http://en.wikipedia.org/wiki/Student's_t-test for more /// details on the t-test. /// class tTest { public: /// /// @brief Default Constructor. /// tTest(void); /** Adding a data value to tTest. */ void add(double value, bool target, double weight=1.0); /** \brief Set everything to zero \since New in yat 0.5 */ void reset(void); /** Calculates the t-score, i.e. the ratio between difference in mean and standard deviation of this difference. The t-score is calculated as \f$t = \frac{ m_x - m_y }{ s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$m \f$ is the weighted mean, n is the weighted version of number of data points \f$\frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$, and \f$s^2 \f$ is an estimation of the variance \f$s^2 = \frac{ \sum_i w_i(x_i-m_x)^2 + \sum_i w_i(y_i-m_y)^2 }{ n_x + n_y - 2 } \f$ \see AveragerWeighted If all weights are equal to unity this boils down to \f$t = \frac{ m_x - m_y } {s\sqrt{\frac{1}{n_x}+\frac{1}{n_y}}} \f$ where \f$m \f$ is the mean, \f$n \f$ is the number of data points and \f$s^2 = \frac{ \sum_i (x_i-m_x)^2 + \sum_i (y_i-m_y)^2 }{ n_x + n_y - 2 } \f$ \see Averager \return t-score. */ double score(void); /// /// Calculates the p-value, i.e. the probability of observing a /// t-score equally or larger if the null hypothesis is true. If P /// is near zero, this casts doubt on this hypothesis. The null /// hypothesis is that the means of the two distributions are /// equal. Assumtions for this test is that the two distributions /// are normal distributions with equal variance. The latter /// assumtion is dropped in Welch's t-test. /// /// @return the two-sided p-value /// double p_value() const; /// /// @return One-sided P-value /// double p_value_one_sided(void) const; private: double dof_; bool updated_; double t_; AveragerWeighted pos_; AveragerWeighted neg_; }; }}} // of namespace statistics, yat, and theplu #endif