5 * Created by Thomas Ryabin on 2/23/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12 /***********************************************************************/
14 double Geom::kEq(double k, double spec){
15 return k/(1-k)*pow(1-k, spec)/(1-pow(1-k, spec));
18 RAbundVector Geom::getRAbundVector(SAbundVector* rank){
24 for(int i = rank->size()-1; i > 0; i--)
26 int cur = rank->get(i);
27 if(mr == 1 && cur > 0)
31 for(int j = 0; j < cur; j++)
35 RAbundVector rav = RAbundVector(rData, mr, nb, ns);
36 rav.setLabel(rank->getLabel());
40 /***********************************************************************************/
42 /***********************************************************************************/
43 EstOutput Geom::getValues(SAbundVector* rank){
47 rdata = getRAbundVector(rank);
48 int numInd = rdata.getNumSeqs();
49 int numSpec = rdata.getNumBins();
50 int min = rdata.get(rdata.size()-1);
54 while(fabs(min - numInd*kEq(k, (double)numSpec)) > .0001) //This uses a binary search to find the value of k.
56 if(numInd*kEq(k, numSpec) > min)
63 double cK = 1/(1-pow(1-k, numSpec));
68 for(int i = 0; i < rdata.size(); i++)
70 sumObs += rdata.get(i);
71 sumExp += numInd*cK*k*pow(1-k, i);
72 double diff = fabs(sumObs-sumExp);
77 double DStatistic = maxDiff/numInd;
80 cout << "D-Statistic = " << DStatistic << "\n";
81 cout << "Critical value for 95% confidence interval = ";*/
84 critVal = .886/sqrt(rdata.size());
89 critVal = table.getConfLimit(numSpec);
91 /*cout << critVal << "\n";
92 cout << "If D-Statistic is less than the critical value then the data fits the Geometric Series model w/ 95% confidence.\n\n";*/
97 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
98 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
102 catch(exception& e) {
103 cout << "Standard Error: " << e.what() << " has occurred in the NPShannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
107 cout << "An unknown error has occurred in the NPShannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
112 /***********************************************************************/