Changeset 2382 for trunk/yat/statistics/Fisher.cc
- Timestamp:
- Dec 21, 2010, 2:16:58 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/0.6-stable merged: 2258,2271-2272,2304,2310,2314-2315,2317-2320,2322,2378-2380
- Property svn:mergeinfo changed
-
trunk/yat/statistics/Fisher.cc
r2316 r2382 5 5 Copyright (C) 2005 Peter Johansson 6 6 Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson 7 Copyright (C) 2009 Peter Johansson7 Copyright (C) 2009, 2010 Peter Johansson 8 8 9 9 This file is part of the yat library, http://dev.thep.lu.se/yat … … 32 32 33 33 #include <algorithm> 34 #include <cassert> 34 35 35 36 namespace theplu { … … 66 67 void Fisher::expected(double& a, double& b, double& c, double& d) const 67 68 { 68 double N = a_+b_+c_+d_; 69 a =((a_+b_)*(a_+c_)) / N; 70 b =((a_+b_)*(b_+d_)) / N; 71 c =((c_+d_)*(a_+c_)) / N; 72 d =((c_+d_)*(b_+d_)) / N; 69 // use floting point arithmetic to avoid overflow 70 double a1 = a_; 71 double b1 = b_; 72 double c1 = c_; 73 double d1 = d_; 74 double N = a1 + b1 + c1 + d1; 75 a =((a1+b1)*(a1+c1)) / N; 76 b =((a1+b1)*(b1+d1)) / N; 77 c =((c1+d1)*(a1+c1)) / N; 78 d =((c1+d1)*(b1+d1)) / N; 73 79 } 74 80 … … 100 106 d_ = d; 101 107 102 oddsratio_=static_cast<double>(a*d)/static_cast<double>(b*c); 108 oddsratio_= (static_cast<double>(a) / static_cast<double>(b) * 109 static_cast<double>(d) / static_cast<double>(c) ); 103 110 return oddsratio_; 104 111 } … … 120 127 return p_value_approximative()/2.0; 121 128 } 129 // check for overflow 130 assert(c_ <= c_+d_ && d_ <= c_+d_); 131 assert(a_ <= a_+b_ && b_ <= a_+b_); 132 assert(a_ <= a_+c_ && c_ <= a_+c_); 133 122 134 return statistics::cdf_hypergeometric_P(c_, c_+d_, a_+b_, a_+c_); 123 135 } … … 149 161 } 150 162 151 152 163 }}} // of namespace statistics, yat, and theplu
Note: See TracChangeset
for help on using the changeset viewer.