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--) {
25 int cur = rank->get(i);
26 if(mr == 1 && cur > 0)
30 for(int j = 0; j < cur; j++)
34 RAbundVector rav = RAbundVector(rData, mr, nb, ns);
35 rav.setLabel(rank->getLabel());
39 /***********************************************************************************/
41 /***********************************************************************************/
42 EstOutput Geom::getValues(SAbundVector* rank){
46 rdata = getRAbundVector(rank);
47 double numInd = rdata.getNumSeqs();
48 double numSpec = rdata.getNumBins();
49 double min = rdata.get(rdata.size()-1);
53 while(fabs(min - numInd*kEq(k, (double)numSpec)) > .0001) { //This uses a binary search to find the value of k.
54 if(numInd*kEq(k, numSpec) > min)
61 double cK = 1/(1-pow(1-k, numSpec));
66 for(int i = 0; i < numSpec; i++)
68 sumObs += rdata.get(i);
69 sumExp += numInd*cK*k*pow(1-k, i);
71 double diff = fabs(sumObs-sumExp);
72 if(diff > maxDiff) { maxDiff = diff; }
77 data[0] = maxDiff/numInd;
78 data[1] = 0.886/sqrt(numSpec);
79 data[2] = 1.031/sqrt(numSpec);
82 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
83 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
84 if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
89 m->errorOut(e, "Geom", "getValues");
94 /***********************************************************************/