Changeset 3298
- Timestamp:
- Aug 8, 2014, 9:15:28 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/fisher.cc
r3114 r3298 2 2 3 3 /* 4 Copyright (C) 2008, 2009, 2010, 2012, 2013 Peter Johansson4 Copyright (C) 2008, 2009, 2010, 2012, 2013, 2014 Peter Johansson 5 5 6 6 This file is part of the yat library, http://dev.thep.lu.se/yat … … 33 33 void test_p_value_exact(test::Suite&); 34 34 void test_large_numbers(test::Suite&); 35 void test_yates(test::Suite&); 35 36 36 37 int main(int argc, char* argv[]) … … 71 72 test_p_value(suite); 72 73 test_large_numbers(suite); 74 test_yates(suite); 73 75 return suite.return_value(); 74 76 } … … 147 149 suite.add(suite.equal(f.p_left(), 0.7)); 148 150 } 151 152 153 void test_yates(test::Suite& suite) 154 { 155 statistics::Fisher f; 156 statistics::Fisher f2(true); 157 158 f.oddsratio(5,10,10,10); 159 f2.oddsratio(5,10,10,10); 160 f.minimum_size() = 0; 161 f2.minimum_size() = 0; 162 double p = f.p_value(); 163 double p_yates = f2.p_value(); 164 if (p==p_yates) { 165 suite.add(false); 166 suite.err() << "p-value: " << p << "\n"; 167 suite.err() << "p-value yates's corrected: " << p_yates << "\n"; 168 } 169 } -
trunk/yat/statistics/Fisher.cc
r3004 r3298 5 5 Copyright (C) 2005 Peter Johansson 6 6 Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson 7 Copyright (C) 2009, 2010, 2011, 2012, 2013 Peter Johansson7 Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Peter Johansson 8 8 9 9 This file is part of the yat library, http://dev.thep.lu.se/yat … … 41 41 42 42 43 Fisher::Fisher() 44 : a_(0), b_(0), c_(0), d_(0), minimum_size_(10), oddsratio_(1.0) 43 Fisher::Fisher(bool yates) 44 : a_(0), b_(0), c_(0), d_(0), minimum_size_(10), oddsratio_(1.0), 45 yates_(yates) 45 46 { 46 47 } … … 62 63 double a,b,c,d; 63 64 expected(a,b,c,d); 65 if (yates_) 66 return yates(a_, a) + yates(b_, b) + yates(c_, c) + yates(d_, d); 67 64 68 return (a-a_)*(a-a_)/a + (b-b_)*(b-b_)/b + 65 69 (c-c_)*(c-c_)/c + (d-d_)*(d-d_)/d; … … 204 208 } 205 209 210 211 double Fisher::yates(unsigned int o, double e) const 212 { 213 double x = std::abs(o - e) - 0.5; 214 return x*x/e; 215 } 216 206 217 }}} // of namespace statistics, yat, and theplu -
trunk/yat/statistics/Fisher.h
r3004 r3298 7 7 Copyright (C) 2004, 2005 Peter Johansson 8 8 Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson 9 Copyright (C) 2009, 2011, 2013 Peter Johansson9 Copyright (C) 2009, 2011, 2013, 2014 Peter Johansson 10 10 11 11 This file is part of the yat library, http://dev.thep.lu.se/yat … … 69 69 /// 70 70 /// Default Constructor. 71 /// 72 Fisher(void); 71 /// 72 /// \param yates if true Yates's correction is used for 73 /// chi-squared calculation 74 /// 75 Fisher(bool yates=false); 73 76 74 77 /// … … 82 85 \frac{(O_i-E_i)^2}{E_i}\f$ where \a E is expected value and \a 83 86 O is observed value. 87 88 If indicated in constructor, Yates's correction is used, i.e., 89 Chi2 is calculated as \f$ \frac{(|O_i-E_i|-0.5)^2}{E_i} \f$ 90 84 91 85 92 \see expected(double&, double&, double&, double&) … … 193 200 double p_value_exact(void) const; 194 201 202 double yates(unsigned int o, double e) const; 203 195 204 unsigned int a_; 196 205 unsigned int b_; … … 199 208 unsigned int minimum_size_; 200 209 double oddsratio_; 210 bool yates_; 201 211 }; 202 212
Note: See TracChangeset
for help on using the changeset viewer.