Changeset 2315 for branches/0.6stable/yat/statistics/Fisher.cc
 Timestamp:
 Aug 20, 2010, 5:51:00 AM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/0.6stable/yat/statistics/Fisher.cc
r2119 r2315 30 30 31 31 #include <algorithm> 32 #include <cassert> 32 33 33 34 namespace theplu { … … 64 65 void Fisher::expected(double& a, double& b, double& c, double& d) const 65 66 { 66 double N = a_+b_+c_+d_; 67 // use floting point arithmetic to avoid overflow 68 double N = static_cast<double>(a_) + static_cast<double>(b_) 69 + static_cast<double>(c_) + static_cast<double>(d_); 67 70 a =((a_+b_)*(a_+c_)) / N; 68 71 b =((a_+b_)*(b_+d_)) / N; … … 98 101 d_ = d; 99 102 100 oddsratio_=static_cast<double>(a*d)/static_cast<double>(b*c); 103 oddsratio_= (static_cast<double>(a) / static_cast<double>(b) * 104 static_cast<double>(d) / static_cast<double>(c) ); 101 105 return oddsratio_; 102 106 } … … 118 122 return p_value_approximative()/2.0; 119 123 } 124 // check for overflow 125 assert(c_ <= c_+d_ && d_ <= c_+d_); 126 assert(a_ <= a_+b_ && b_ <= a_+b_); 127 assert(a_ <= a_+c_ && c_ <= a_+c_); 128 120 129 return statistics::cdf_hypergeometric_P(c_, c_+d_, a_+b_, a_+c_); 121 130 } … … 147 156 } 148 157 149 150 158 }}} // of namespace statistics, yat, and theplu
Note: See TracChangeset
for help on using the changeset viewer.