X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=logsd.cpp;h=6a795415d832f265325138422f48d77afe3315be;hp=fddee4f5e94e977bd417e0d32a82f6f37894d232;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=51cf89e90eef8b300c2786eb1560dd89e6e83445 diff --git a/logsd.cpp b/logsd.cpp index fddee4f..6a79541 100644 --- a/logsd.cpp +++ b/logsd.cpp @@ -14,6 +14,7 @@ double LogSD::logS(double x){ return -(1-x)*log(1-x)/x; } +/***********************************************************************/ EstOutput LogSD::getValues(SAbundVector* rank){ try { @@ -28,15 +29,14 @@ EstOutput LogSD::getValues(SAbundVector* rank){ SAbundVector rankw = SAbundVector(dvec, mr,nb,ns); SAbundVector *rank = &rankw;*/ - data.resize(2,0); - int numInd = rank->getNumSeqs(); - int numSpec = rank->getNumBins(); + data.resize(3,0); + double numInd = rank->getNumSeqs(); + double numSpec = rank->getNumBins(); double snRatio = (double)numSpec/numInd; double x = .5; double step = .4999999999; - while(fabs(snRatio - logS(x)) > .00001) //This uses a binary search to find the value of x. - { + while(fabs(snRatio - logS(x)) > .00001) { //This uses a binary search to find the value of x. if(logS(x) > snRatio) x += step; else @@ -45,21 +45,18 @@ EstOutput LogSD::getValues(SAbundVector* rank){ } double alpha = numInd*(1-x)/x; - int oct = 1; + double oct = 1; double octSumObs = 0; double sumObs = 0; double octSumExp = 0; double sumExp = 0; double maxDiff = 0; - for(int y = 1; y < rank->size(); y++) - { - if(y - .5 < pow(2.0, oct)) - { + for(int y = 1; y < rank->size(); y++) { + if(y - .5 < pow(2.0, oct)) { octSumObs += rank->get(y); octSumExp += alpha*pow(x,y)/(y); } - else - { + else { sumObs += octSumObs; octSumObs = rank->get(y); @@ -68,8 +65,7 @@ EstOutput LogSD::getValues(SAbundVector* rank){ oct++; } - if(y == rank->size()-1) - { + if(y == rank->size()-1) { sumObs += octSumObs; sumExp += octSumExp; } @@ -78,27 +74,21 @@ EstOutput LogSD::getValues(SAbundVector* rank){ if(diff > maxDiff) maxDiff = diff; } + + data[0] = (maxDiff + .5)/numSpec; + data[1] = 0.886/sqrt(numSpec); + data[2] = 1.031/sqrt(numSpec); - double DStatistic = (maxDiff + .5)/numSpec; - /*cout << "LogSD:\n"; - cout << "D Test Statistic = " << DStatistic << "\n"; - cout << ".05 confidence value = " << .89196/sqrt(numSpec) << "\n"; - cout << "If D Test Statistic is greater than the critical value then the data fits the Log Series Distribution model w/ 95% confidence.\n\n";*/ - - data[0] = DStatistic; - data[1] = .89196/sqrt(numSpec); if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; } + if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; } + return data; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the NPShannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "LogSD", "getValues"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the NPShannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/