X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mothurout.cpp;h=7d40e80ead727205f4bcc00269f78bd7f81057ca;hb=e8e13c129ba8184ec5932a090773f353f3ae3406;hp=c5eb0dca828a47023973f1684986ba05d45bb0fb;hpb=96dbe925073caefaed6e6db85659c144a806aeb1;p=mothur.git diff --git a/mothurout.cpp b/mothurout.cpp index c5eb0dc..7d40e80 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -2912,8 +2912,31 @@ string MothurOut::removeQuotes(string tax) { } } /**************************************************************************************************/ - - +// function for calculating standard deviation +double MothurOut::getStandardDeviation(vector& featureVector){ + try { + //finds sum + double average = 0; + for (int i = 0; i < featureVector.size(); i++) { average += featureVector[i]; } + average /= (double) featureVector.size(); + + //find standard deviation + double stdDev = 0; + for (int i = 0; i < featureVector.size(); i++) { //compute the difference of each dist from the mean, and square the result of each + stdDev += ((featureVector[i] - average) * (featureVector[i] - average)); + } + + stdDev /= (double) featureVector.size(); + stdDev = sqrt(stdDev); + + return stdDev; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getStandardDeviation"); + exit(1); + } +} +/**************************************************************************************************/