5 * Created by westcott on 12/15/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
12 /***********************************************************************/
14 EstOutput Spearman::getValues(vector<SharedRAbundVector*> shared) {
18 SAbundVector savA = shared[0]->getSAbundVector();
19 SAbundVector savB = shared[1]->getSAbundVector();
21 double sumRanks = 0.0;
22 int numOTUS = shared[0]->getNumBins();
24 vector<double> rankVectorA(savA.getMaxRank()+1, 0);
26 for(int i=savA.getMaxRank();i>0;i--){
27 int numWithAbundanceI = savA.get(i);
29 if(numWithAbundanceI > 1){ rankVectorA[i] = (currentRankA + 1 + currentRankA + numWithAbundanceI) / 2.0; }
30 else { rankVectorA[i] = currentRankA+numWithAbundanceI; }
31 currentRankA += numWithAbundanceI;
33 rankVectorA[0] = (numOTUS + currentRankA + 1) / 2.0;
36 vector<double> rankVectorB(savB.getMaxRank()+1, 0);
38 for(int i=savB.getMaxRank();i>0;i--){
39 int numWithAbundanceI = savB.get(i);
41 if(numWithAbundanceI > 1){ rankVectorB[i] = (currentRankB + 1 + currentRankB + numWithAbundanceI) / 2.0; }
42 else { rankVectorB[i] = currentRankB+numWithAbundanceI; }
43 currentRankB += numWithAbundanceI;
45 rankVectorB[0] = (numOTUS + currentRankB + 1) / 2.0;
49 for (int i = 0; i < shared[0]->getNumBins(); i++) {
50 int Aij = shared[0]->getAbundance(i);
51 int Bij = shared[1]->getAbundance(i);
53 float rankA = rankVectorA[Aij];
54 float rankB = rankVectorB[Bij];
56 sumRanks += ((rankA - rankB) * (rankA - rankB));
58 data[0] = 1.0 - ((6 * sumRanks) / (float) (numOTUS * ((numOTUS*numOTUS)-1)));
60 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
65 m->errorOut(e, "Spearman", "getValues");
70 /***********************************************************************/