bpp-core3  3.0.0
StatTools.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "StatTools.h"
6 
7 // From the STL:
8 #include <algorithm>
9 
10 using namespace bpp;
11 using namespace std;
12 
13 vector<double> StatTools::computeFdr(const vector<double>& pvalues)
14 {
15  size_t n = pvalues.size();
16  vector<PValue_> sortedPValues;
17  for (size_t i = 0; i < n; ++i)
18  {
19  sortedPValues.push_back(PValue_(pvalues[i], i));
20  }
21  sort(sortedPValues.begin(), sortedPValues.end());
22  vector<double> fdr(pvalues.size());
23  for (size_t i = 0; i < sortedPValues.size(); ++i)
24  {
25  fdr[sortedPValues[i].index_] = sortedPValues[i].pvalue_ * static_cast<double>(n) / ( static_cast<double>(sortedPValues[i].index_ + 1));
26  }
27  return fdr;
28 }
STL namespace.
static std::vector< double > computeFdr(const std::vector< double > &pvalues)
Compute the false discovery rate for a set of input p-values, using Benjamini and Hochberg&#39;s &#39;FDR&#39; me...
Definition: StatTools.cpp:13