Ignore:
Timestamp:
Dec 21, 2010, 2:16:58 PM (11 years ago)
Author:
Peter
Message:

merged patch release 0.6.3 into trunk.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/yat/statistics/Fisher.cc

    r2316 r2382  
    55  Copyright (C) 2005 Peter Johansson
    66  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    7   Copyright (C) 2009 Peter Johansson
     7  Copyright (C) 2009, 2010 Peter Johansson
    88
    99  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    3232
    3333#include <algorithm>
     34#include <cassert>
    3435
    3536namespace theplu {
     
    6667  void Fisher::expected(double& a, double& b, double& c, double& d) const
    6768  {
    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;
    7379  }
    7480
     
    100106    d_ = d;
    101107
    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) );
    103110    return oddsratio_;
    104111  }
     
    120127      return p_value_approximative()/2.0;
    121128    }
     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
    122134    return statistics::cdf_hypergeometric_P(c_, c_+d_, a_+b_, a_+c_);
    123135  }
     
    149161  }
    150162
    151 
    152163}}} // of namespace statistics, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.