Changeset 2595


Ignore:
Timestamp:
Oct 30, 2011, 4:27:20 AM (12 years ago)
Author:
Peter
Message:

fixes #678. ROC p_value

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/roc.cc

    r2593 r2595  
    124124    -+++- 3 3
    125125    -++-+ 2 2
    126     -+-++ 1 0.5
     126    -+-++ 1 0.5 *** our second case ***
    127127    --+++ 0 0.5
    128128   */
     
    145145  else
    146146    suite.add(true);
     147
     148  suite.out() << "test p exact with ties II\n";
     149  roc.reset();
     150  roc.add(2, false);
     151  roc.add(1, true);
     152  roc.add(1, false);
     153  roc.add(0, true);
     154  roc.add(-1, true);
     155  suite.add(suite.equal(roc.area(), 0.5/6));
     156  if (!suite.add(suite.equal(roc.p_value_one_sided(), 10.0/10.0)))
     157    suite.out() << "  p_value_one_sided: expected 0.3\n";
     158  if (!suite.add(suite.equal(roc.p_value(), 3.0/10.0)))
     159    suite.out() << "  (two-sided) p_value: expected 0.5\n";
    147160}
    148161
     
    183196    roc.add(i, i<5);
    184197  if (roc.p_value_one_sided()<0.5) {
    185     suite.xadd(false);
     198    suite.add(false);
    186199    suite.err() << "error: expected p-value>0.5\n  found: "
    187200                << roc.p_value_one_sided() << "\n";
    188201  }
    189 
    190202}
    191203
  • trunk/yat/statistics/ROC.cc

    r2592 r2595  
    2727#include <gsl/gsl_cdf.h>
    2828
     29#include <algorithm>
    2930#include <cassert>
    3031#include <cmath>
     
    137138  double ROC::p_exact(double area) const
    138139  {
    139     if (area>=0.5)
    140       return p_exact_with_ties(multimap_.begin(), multimap_.end(),
    141                                area*w_pos_*w_neg_, w_pos_, w_neg_);
    142     return p_exact_with_ties(multimap_.rbegin(), multimap_.rend(),
    143                              (1.0-area)*w_pos_*w_neg_, w_pos_, w_neg_);
    144    
    145    
     140    return p_exact_with_ties(multimap_.begin(), multimap_.end(),
     141                             area*w_pos_*w_neg_, w_pos_, w_neg_);
    146142  }
    147143
     
    156152    if (use_exact_method()) {
    157153      double p = 0;
    158       p = p_exact(area);
     154      double abs_area = std::max(area, 1-area);
     155      p = p_exact(abs_area);
    159156      if (has_ties_) {
    160         p += p_exact(1-area);
     157        p += p_exact_with_ties(multimap_.rbegin(), multimap_.rend(),
     158                               abs_area*w_pos_*w_neg_, w_pos_, w_neg_);
    161159      }
    162160      else
Note: See TracChangeset for help on using the changeset viewer.