X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=smithwilson.cpp;fp=smithwilson.cpp;h=ec04196134bf7c19e3e09f36a9b804d5a5cc0c89;hb=10e9f1ff74515ff887519b08e50c30c47d2472d2;hp=0000000000000000000000000000000000000000;hpb=94ba64671398f3c9e591df90536833123de0fd34;p=mothur.git diff --git a/smithwilson.cpp b/smithwilson.cpp new file mode 100644 index 0000000..ec04196 --- /dev/null +++ b/smithwilson.cpp @@ -0,0 +1,50 @@ +/* + * smithwilson.cpp + * Mothur + * + * Created by Pat Schloss on 8/21/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "smithwilson.h" + +/***********************************************************************/ + +EstOutput SmithWilson::getValues(SAbundVector* rank){ + try { + + data.resize(1,0); + + double maxRank = rank->getMaxRank(); + double sobs = rank->getNumBins(); + + double innerSum = 0; + for(int i=1;i<=maxRank;i++){ + innerSum += rank->get(i) * log(i); + } + innerSum /= sobs; + + double outerSum = 0; + for(int i=1;i<=maxRank;i++){ + outerSum += rank->get(i) * (log(i) - innerSum) * (log(i) - innerSum); + } + outerSum /= sobs; + + if(outerSum > 0){ + data[0] = 1.0000 - 2.0000 / (3.14159 * atan(outerSum)); + } + else{ + data[0] = 1.0000; + } + + + return data; + } + catch(exception& e) { + m->errorOut(e, "InvSimpson", "getValues"); + exit(1); + } +} + +/***********************************************************************/