]> git.donarmstrong.com Git - mothur.git/blob - smithwilson.cpp
working on get.coremicrobiom
[mothur.git] / smithwilson.cpp
1 /*
2  *  smithwilson.cpp
3  *  Mothur
4  *
5  *  Created by Pat Schloss on 8/21/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "smithwilson.h"
11
12 /***********************************************************************/
13
14 EstOutput SmithWilson::getValues(SAbundVector* rank){
15         try {
16
17                 data.resize(1,0);
18
19                 double maxRank = rank->getMaxRank();
20                 double sobs = rank->getNumBins();
21                 
22                 double innerSum = 0;
23                 for(int i=1;i<=maxRank;i++){
24                         innerSum += rank->get(i) * log(i);
25                 }
26                 innerSum /= sobs;
27
28                 double outerSum = 0;
29                 for(int i=1;i<=maxRank;i++){
30                         outerSum += rank->get(i) * (log(i) - innerSum) * (log(i) - innerSum);
31                 }
32                 outerSum /= sobs;
33
34                 if(outerSum > 0){
35                         data[0] = 1.0000 - 2.0000 / (3.14159 * atan(outerSum));
36                 }
37                 else{
38                         data[0] = 1.0000;
39                 }
40                 
41                 
42                 return data;
43         }
44         catch(exception& e) {
45                 m->errorOut(e, "InvSimpson", "getValues");
46                 exit(1);
47         }
48 }
49
50 /***********************************************************************/