5 * Created by Sarah Westcott on 1/7/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12 /***********************************************************************/
14 EstOutput Simpson::getValues(SAbundVector* rank){
16 //vector<double> simpsonData(3,0);
18 double simpson = 0.0000;
21 double maxRank = (double)rank->getMaxRank();
22 double sampled = (double)rank->getNumSeqs();
23 double sobs = (double)rank->getNumBins();
26 double secondTerm = 0;
31 for(unsigned long long i=1;i<=maxRank;i++){
32 simnum += (double)(rank->get(i)*i*(i-1));
35 simpson = simnum / (sampled*(sampled-1));
37 for(unsigned long long i=1;i<=maxRank;i++){
38 double piI = (double) i / (double)sampled;
39 firstTerm += rank->get(i) * pow(piI, 3);
40 secondTerm += rank->get(i) * pow(piI, 2);
43 double var = (4.0 / sampled) * (firstTerm - secondTerm*secondTerm);
44 ci = 1.95 * pow(var, 0.5);
47 double simpsonlci = simpson - ci;
48 double simpsonhci = simpson + ci;
54 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
55 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
56 if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
61 m->errorOut(e, "Simpson", "getValues");
66 /***********************************************************************/