X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=geom.cpp;h=5bd150ef7f8201254a392a52a7583b07b83e0b00;hp=8b484de49bcd27c772ead83f10cbf77aa14adf91;hb=050a3ff02473a3d4c0980964e1a9ebe52e55d6b8;hpb=eb1c88346fb246e95a6b38935b103f95e38b82ca diff --git a/geom.cpp b/geom.cpp index 8b484de..5bd150e 100644 --- a/geom.cpp +++ b/geom.cpp @@ -3,12 +3,11 @@ * Mothur * * Created by Thomas Ryabin on 2/23/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "geom.h" -#include "calculator.h" /***********************************************************************/ @@ -22,8 +21,7 @@ RAbundVector Geom::getRAbundVector(SAbundVector* rank){ int nb = 0; int ns = 0; - for(int i = rank->size()-1; i > 0; i--) - { + for(int i = rank->size()-1; i > 0; i--) { int cur = rank->get(i); if(mr == 1 && cur > 0) mr = i; @@ -43,17 +41,16 @@ RAbundVector Geom::getRAbundVector(SAbundVector* rank){ /***********************************************************************************/ EstOutput Geom::getValues(SAbundVector* rank){ try { - data.resize(2,0); + data.resize(3,0); rdata = getRAbundVector(rank); - int numInd = rdata.getNumSeqs(); - int numSpec = rdata.getNumBins(); - int min = rdata.get(rdata.size()-1); + double numInd = rdata.getNumSeqs(); + double numSpec = rdata.getNumBins(); + double min = rdata.get(rdata.size()-1); double k = .5; double step = .49999; - while(fabs(min - numInd*kEq(k, (double)numSpec)) > .0001) //This uses a binary search to find the value of k. - { + while(fabs(min - numInd*kEq(k, (double)numSpec)) > .0001) { //This uses a binary search to find the value of k. if(numInd*kEq(k, numSpec) > min) k += step; else @@ -65,49 +62,33 @@ EstOutput Geom::getValues(SAbundVector* rank){ double sumExp = 0; double sumObs = 0; double maxDiff = 0; - - for(int i = 0; i < rdata.size(); i++) + + for(int i = 0; i < numSpec; i++) { sumObs += rdata.get(i); sumExp += numInd*cK*k*pow(1-k, i); + double diff = fabs(sumObs-sumExp); - if(diff > maxDiff) - maxDiff = diff; + if(diff > maxDiff) { maxDiff = diff; } + } - double DStatistic = maxDiff/numInd; - double critVal = 0; - /*cout << "Geom:\n"; - cout << "D-Statistic = " << DStatistic << "\n"; - cout << "Critical value for 95% confidence interval = ";*/ - if(rdata.size() > 20) - { - critVal = .886/sqrt(rdata.size()); - } - else - { - KOSTable table; - critVal = table.getConfLimit(numSpec); - } - /*cout << critVal << "\n"; - cout << "If D-Statistic is less than the critical value then the data fits the Geometric Series model w/ 95% confidence.\n\n";*/ - - data[0] = DStatistic; - data[1] = critVal; + + data[0] = maxDiff/numInd; + data[1] = 0.886/sqrt(numSpec); + data[2] = 1.031/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, "Geom", "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); - } } /***********************************************************************/