X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=spearman.cpp;fp=spearman.cpp;h=72d5667e97a0e6a0a499464fe529699212ae8a91;hb=75c5a235ac3eb22e0f97d36874f4b2dcf9591f2e;hp=0000000000000000000000000000000000000000;hpb=8f89a92f4ada82a2b3bf51b23b6a977770f2b9e2;p=mothur.git diff --git a/spearman.cpp b/spearman.cpp new file mode 100644 index 0000000..72d5667 --- /dev/null +++ b/spearman.cpp @@ -0,0 +1,47 @@ +/* + * spearman.cpp + * Mothur + * + * Created by westcott on 12/15/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "spearman.h" + +/***********************************************************************/ +EstOutput Spearman::getValues(vector shared) { + try { + data.resize(1,0); + + SAbundVector savA = shared[0]->getSAbundVector(); + SAbundVector savB = shared[1]->getSAbundVector(); + + double sumRanks = 0.0; + int numOTUS = shared[0]->getNumBins(); + + //calc the 2 denominators + for (int i = 0; i < shared[0]->getNumBins(); i++) { + + int Aij = shared[0]->getAbundance(i); + int Bij = shared[1]->getAbundance(i); + + int rankA = savA.get(Aij); + int rankB = savB.get(Bij); + + sumRanks += ((rankA - rankB) * (rankA - rankB)); + } + + data[0] = 1.0 - ((6 * sumRanks) / (float) (numOTUS * (numOTUS-1))); + + if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } + + return data; + } + catch(exception& e) { + m->errorOut(e, "Soergel", "getValues"); + exit(1); + } +} +/***********************************************************************/ +