Changeset 779 for trunk/yat/statistics/tTest.cc
 Timestamp:
 Mar 5, 2007, 7:58:30 PM (15 years ago)
 File:

 1 copied
Legend:
 Unmodified
 Added
 Removed

trunk/yat/statistics/tTest.cc
r776 r779 22 22 */ 23 23 24 #include "tTest.h" 24 25 #include "tScore.h" 25 #include "Averager.h"26 #include "AveragerWeighted.h"27 #include "yat/classifier/DataLookupWeighted1D.h"28 #include "yat/classifier/Target.h"29 #include "yat/utility/vector.h"26 //#include "Averager.h" 27 //#include "AveragerWeighted.h" 28 //#include "yat/classifier/DataLookupWeighted1D.h" 29 //#include "yat/classifier/Target.h" 30 //#include "yat/utility/vector.h" 30 31 31 32 #include <cassert> … … 36 37 namespace statistics { 37 38 38 t Score::tScore(bool b)39 : Score(b),t_(0)39 tTest::tTest(bool b) 40 : t_(0) 40 41 { 41 42 } 42 43 43 double t Score::score(const classifier::Target& target,44 44 double tTest::score(const classifier::Target& target, 45 const utility::vector& value) 45 46 { 46 weighted_=false; 47 statistics::Averager positive; 48 statistics::Averager negative; 49 for(size_t i=0; i<target.size(); i++){ 50 if (target.binary(i)) 51 positive.add(value(i)); 52 else 53 negative.add(value(i)); 54 } 55 double diff = positive.mean()  negative.mean(); 56 dof_=positive.n()+negative.n()2; 57 double s2=(positive.sum_xx_centered()+negative.sum_xx_centered())/dof_; 58 59 t_=diff/sqrt(s2/positive.n()+s2/negative.n()); 60 if (t_<0 && absolute_) 61 t_=t_; 62 47 tScore score; 48 t_ = score.score(target, value, &dof_); 63 49 return t_; 64 50 } 65 51 66 52 67 double t Score::score(const classifier::Target& target,68 53 double tTest::score(const classifier::Target& target, 54 const classifier::DataLookupWeighted1D& value) 69 55 { 70 weighted_=true; 71 72 statistics::AveragerWeighted positive; 73 statistics::AveragerWeighted negative; 74 for(size_t i=0; i<target.size(); i++){ 75 if (target.binary(i)) 76 positive.add(value.data(i),value.weight(i)); 77 else 78 negative.add(value.data(i),value.weight(i)); 79 } 80 double diff = positive.mean()  negative.mean(); 81 dof_=positive.n()+negative.n()2; 82 double s2=(positive.sum_xx_centered()+negative.sum_xx_centered())/dof_; 83 t_=diff/sqrt(s2/positive.n()+s2/(negative.n())); 84 if (t_<0 && absolute_) 85 t_=t_; 86 87 if(positive.sum_w()==0  negative.sum_w()==0) 88 t_=0; 56 tScore score; 57 t_ = score.score(target, value, &dof_); 89 58 return t_; 90 59 } 91 60 92 61 93 double t Score::score(const classifier::Target& target,94 95 62 double tTest::score(const classifier::Target& target, 63 const utility::vector& value, 64 const utility::vector& weight) 96 65 { 97 weighted_=true; 98 99 statistics::AveragerWeighted positive; 100 statistics::AveragerWeighted negative; 101 for(size_t i=0; i<target.size(); i++){ 102 if (target.binary(i)) 103 positive.add(value(i),weight(i)); 104 else 105 negative.add(value(i),weight(i)); 106 } 107 double diff = positive.mean()  negative.mean(); 108 dof_=positive.n()+negative.n()2; 109 double s2=(positive.sum_xx_centered()+negative.sum_xx_centered())/dof_; 110 t_=diff/sqrt(s2/positive.n()+s2/(negative.n())); 111 if (t_<0 && absolute_) 112 t_=t_; 113 114 if(positive.sum_w()==0  negative.sum_w()==0) 115 t_=0; 66 tScore score; 67 t_ = score.score(target, value, weight, &dof_); 116 68 return t_; 117 69 } 118 70 119 double t Score::p_value(void) const71 double tTest::p_value(void) const 120 72 { 121 double p = gsl_cdf_tdist_Q(t_, dof_); 122 return (dof_ > 0 && !weighted_) ? p : 1; 73 if (!dof_) 74 return 1.0; 75 return gsl_cdf_tdist_Q(t_, dof_); 123 76 } 124 77
Note: See TracChangeset
for help on using the changeset viewer.