]> git.donarmstrong.com Git - mothur.git/blob - efron.cpp
added shen calculator
[mothur.git] / efron.cpp
1 /*
2  *  efron.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 5/13/09.
6  *  Copyright 2009 __MyCompanyName__. All rights reserved.
7  *
8  */
9
10 #include "efron.h"
11 #include <math.h>
12
13 /***********************************************************************/
14 EstOutput Efron::getValues(SAbundVector* rank){
15
16         try {
17                 data.resize(1,0);
18                 
19                 double n = (double)rank->getNumSeqs();
20                 if(m > n) {
21                         cout << "Error in the 'efron' calculator. 'size' must be less than the length of the smallest sabund vector.\n";
22                         data[0] = 0;
23                         return data;
24                 }
25                 
26                 double sum = 0;
27                 for(int i = 1; i < rank->size(); i++)
28                         sum += pow(-1, (double)(i+1)) * pow(((double)m / n), i) * (double)(rank->get(i));
29
30                 data[0] = sum;
31                 
32                 return data;
33         }
34         catch(exception& e) {
35                 cout << "Standard Error: " << e.what() << " has occurred in the Coverage class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
36                 exit(1);
37         }
38         catch(...) {
39                 cout << "An unknown error has occurred in the Coverage class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
40                 exit(1);
41         }       
42 };
43
44
45 /***********************************************************************/