ANIMA  4.0
animaFDRCorrection.cxx
Go to the documentation of this file.
1 #include "animaFDRCorrection.h"
2 #include <algorithm>
3 #include <iostream>
4 
5 namespace anima
6 {
7 
8  void BHCorrection(std::vector <double> &pvalues, double qValue)
9  {
10  std::vector < std::pair <unsigned int, double> > indexedPvalues;
11  unsigned int numData = pvalues.size();
12  for (unsigned int i = 0;i < numData;++i)
13  indexedPvalues.push_back(std::pair <unsigned int, double> (i,pvalues[i]));
14 
15  std::sort(indexedPvalues.begin(),indexedPvalues.end(),pair_increasing_comparator());
16 
17  // Update p-values
18  unsigned int breakingIndex = 0;
19  for (unsigned int i = 0;i < numData;++i)
20  {
21  if (indexedPvalues[i].second > qValue * (i + 1) / numData)
22  {
23  breakingIndex = i;
24  break;
25  }
26  }
27 
28  // Now put back values to their places
29  for (unsigned int i = 0;i < numData;++i)
30  pvalues[indexedPvalues[i].first] = (i < breakingIndex);
31  }
32 
33  void BYCorrection(std::vector <double> &pvalues, double qValue)
34  {
35  std::vector < std::pair <unsigned int, double> > indexedPvalues;
36  unsigned int numData = pvalues.size();
37 
38  double byFactor = 0;
39 
40  for (unsigned int i = 0;i < numData;++i)
41  {
42  indexedPvalues.push_back(std::pair <unsigned int, double> (i,pvalues[i]));
43  byFactor += 1.0 / (i + 1.0);
44  }
45 
46  std::sort(indexedPvalues.begin(),indexedPvalues.end(),pair_increasing_comparator());
47 
48  // Update p-values
49  unsigned int breakingIndex = 0;
50  for (unsigned int i = 0;i < numData;++i)
51  {
52  if (indexedPvalues[i].second > qValue * (i + 1) / numData / byFactor)
53  {
54  breakingIndex = i;
55  break;
56  }
57  }
58 
59  // Now put back values to their places
60  for (unsigned int i = 0;i < numData;++i)
61  pvalues[indexedPvalues[i].first] = (i < breakingIndex);
62  }
63 
64 } // end of namespace anima
void BHCorrection(std::vector< double > &pvalues, double qValue)
void BYCorrection(std::vector< double > &pvalues, double qValue)