# Changeset 822 for trunk/yat/statistics

Ignore:
Timestamp:
Mar 19, 2007, 12:44:09 AM (15 years ago)
Message:

redesigned tTest fixes #212 and #156

Location:
trunk/yat/statistics
Files:
4 edited

Unmodified
Removed
• ## trunk/yat/statistics/tScore.h

 r779 double* dof=0) const; /** Calcultate t-score from Averager like objects. Requirements for T1 and T2 are: double mean(), double n(), double sum_xx_centered() If \a dof is not a null pointer it is assigned to number of degrees of freedom. */ template double score(const T1& pos, const T2& neg, double* dof=0) const; private: }; template double score(const T& pos, const T& neg, double* dof) const { double diff = pos.mean() - neg.mean(); if (dof) *dof=pos.n()+neg.n()-2; double s2=( (pos.sum_xx_centered()+neg.sum_xx_centered())/ (pos.n()+neg.n()-2)); double t=diff/sqrt(s2/pos.n()+s2/(neg.n())); if (t<0 && absolute_) return -t; return t; } }; template double tScore::score(const T1& pos, const T2& neg, double* dof) const { double diff = pos.mean() - neg.mean(); if (dof) *dof=pos.n()+neg.n()-2; double s2=( (pos.sum_xx_centered()+neg.sum_xx_centered())/ (pos.n()+neg.n()-2)); double t=diff/sqrt(s2/pos.n()+s2/neg.n()); if (t<0 && absolute_) return -t; return t; } }}} // of namespace statistics, yat, and theplu
• ## trunk/yat/statistics/tTest.cc

 r779 #include "tTest.h" #include "AveragerWeighted.h" #include "tScore.h" //#include "Averager.h" //#include "AveragerWeighted.h" //#include "yat/classifier/DataLookupWeighted1D.h" //#include "yat/classifier/Target.h" //#include "yat/utility/vector.h" #include #include #include namespace statistics { tTest::tTest(bool b) : t_(0) tTest::tTest(void) : updated_(false) { } double tTest::score(const classifier::Target& target, const utility::vector& value) void tTest::add(double x, bool target, double w) { tScore score; t_ = score.score(target, value, &dof_); if (!w) return; if (target) pos_.add(x,w); else neg_.add(x,w); updated_=false; } double tTest::score(void) { if (!updated_){ tScore score(false); t_ = score.score(pos_, neg_, &dof_); updated_=true; } return t_; } double tTest::score(const classifier::Target& target, const classifier::DataLookupWeighted1D& value) double tTest::p_value(void) const { tScore score; t_ = score.score(target, value, &dof_); return t_; double p=2*p_value_one_sided(); return std::min(p,2-p); } double tTest::score(const classifier::Target& target, const utility::vector& value, const utility::vector& weight) double tTest::p_value_one_sided(void) const { tScore score; t_ = score.score(target, value, weight, &dof_); return t_; } double tTest::p_value(void) const { if (!dof_) double t=t_; double dof=dof_; if (!updated_){ tScore score(false); t = score.score(pos_, neg_, &dof); } if (!dof) return 1.0; return gsl_cdf_tdist_Q(t_, dof_); return gsl_cdf_tdist_Q(t, dof); }
• ## trunk/yat/statistics/tTest.h

 r779 */ #include "AveragerWeighted.h" #include namespace theplu { namespace yat { namespace classifier { class DataLookup1D; class DataLookupWeighted1D; class Target; } namespace utility { class vector; } namespace statistics { /// @brief Default Constructor. /// tTest(bool absolute=true); tTest(void); /** Calculates the value of t-score, i.e. the ratio between difference in mean and standard deviation of this difference. \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$ @return t-score. If absolute=true absolute value of t-score is returned Adding a data value to tTest. */ double score(const classifier::Target& target, const utility::vector& value); void add(double value, bool target, double weight=1.0); /** Calculates the weighted t-score, i.e. the ratio between difference in mean and standard deviation of this difference. \f$t = \frac{ m_x - m_y }{ /** 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 \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 for details. } \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. If absolute=true absolute value of t-score is returned \return t-score. */ double score(const classifier::Target& target, const classifier::DataLookupWeighted1D& value); /// /// Calculates the weighted t-score, i.e. the ratio between /// difference in mean and standard deviation of this /// difference. \f$t = \frac{ m_x - m_y }{ /// \frac{s2}{n_x}+\frac{s2}{n_y}} \f$ where \f$m \f$ is the /// weighted mean, n is the weighted version of number of data /// points and \f$s2 \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 for details. /// /// @return t-score if absolute=true absolute value of t-score /// is returned /// double score(const classifier::Target& target, const utility::vector& value, const utility::vector& weight); double score(void); /// private: double dof_; bool updated_; double t_; double dof_; AveragerWeighted pos_; AveragerWeighted neg_; };
• ## trunk/yat/statistics/utility.h

 r757 */ #include "yat/classifier/DataLookupWeighted1D.h" #include "yat/classifier/target.h" #include "yat/utility/vector.h" const bool sorted=false); /** Adding each value in an array \a v \a to an object \a o.  The requirements for the type T1 is to have an add(double, bool) function, and for T2 of the array \a v are: operator[] returning an element and function size() returning the number of elements. */ template void add(T1& o, const T2& v, const classifier::Target& target) { for (size_t i=0; i void add(T1& o, const classifier::DataLookupWeighted1D& v, const classifier::Target& target) { for (size_t i=0; i
Note: See TracChangeset for help on using the changeset viewer.