5 * Created by Thomas Ryabin on 3/6/09.
6 * Copyright 2009 __MyCompanyName__. All rights reserved.
11 #include "calculator.h"
13 /***********************************************************************/
14 double BStick::invSum(int index, double numSpec)
17 for(int i = index; i <= numSpec; i++)
22 RAbundVector BStick::getRAbundVector(SAbundVector* rank){
28 for(int i = rank->size()-1; i > 0; i--)
30 int cur = rank->get(i);
31 if(mr == 1 && cur > 0)
35 for(int j = 0; j < cur; j++)
39 RAbundVector rav = RAbundVector(rData, mr, nb, ns);
40 rav.setLabel(rank->getLabel());
44 /***************************************************************************/
46 /***************************************************************************/
47 EstOutput BStick::getValues(SAbundVector* rank){
50 rdata = getRAbundVector(rank);
51 double numInd = (double)rdata.getNumSeqs();
52 double numSpec = (double)rdata.getNumBins();
58 for(int i = 0; i < rdata.size(); i++)
60 sumObs += rdata.get(i);
61 sumExp += numInd/numSpec*invSum(i+1,numSpec);
62 double diff = fabs(sumObs-sumExp);
67 double DStatistic = maxDiff/numInd;
69 /*cout << "BStick:\n";
70 cout << "D-Statistic = " << DStatistic << "\n";
71 cout << "Critical value for 95% confidence interval = ";*/
74 critVal = .886/sqrt(rdata.size());
79 critVal = table.getConfLimit(numSpec);
81 /*cout << critVal << "\n";
82 cout << "If D-Statistic is less than the critical value then the data fits the Broken Stick model w/ 95% confidence.\n\n";*/
86 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
87 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
92 cout << "Standard Error: " << e.what() << " has occurred in the NPShannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
96 cout << "An unknown error has occurred in the NPShannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
101 /***********************************************************************/