]> git.donarmstrong.com Git - mothur.git/commitdiff
changes to beta diversity calculators
authorpschloss <pschloss>
Tue, 31 May 2011 12:23:23 +0000 (12:23 +0000)
committerpschloss <pschloss>
Tue, 31 May 2011 12:23:23 +0000 (12:23 +0000)
19 files changed:
memchi2.cpp
mempearson.cpp
sharedanderbergs.cpp
sharedbraycurtis.cpp
sharedjabund.cpp
sharedjclass.cpp
sharedjest.cpp
sharedkulczynski.cpp
sharedkulczynskicody.cpp
sharedlennon.cpp
sharedmorisitahorn.cpp
sharedsorabund.cpp
sharedsorclass.cpp
sharedsorest.cpp
sharedthetan.cpp
sharedthetayc.cpp
spearman.cpp
structpearson.cpp
whittaker.cpp

index 07edd66475c9680cdacd5b9ff7920863323dd525..595b54f664d61e1fcd75e537d48b2e055fde2237 100644 (file)
@@ -25,7 +25,6 @@ EstOutput MemChi2::getValues(vector<SharedRAbundVector*> shared) {
                        if (shared[1]->getAbundance(i) != 0) { nonZeroB++; }
                }
                
-               double totalTerm = 1 / (float) totalGroups;
                double sum = 0.0;
                for (int i = 0; i < shared[0]->getNumBins(); i++) {
                        int A = shared[0]->getAbundance(i);
@@ -36,11 +35,18 @@ EstOutput MemChi2::getValues(vector<SharedRAbundVector*> shared) {
                        
                        double Aterm = A / (float) nonZeroA;
                        double Bterm = B / (float) nonZeroB;
+
+                       int incidence = 0;
+                       for(int j=0;j<shared.size();j++){
+                               if(shared[j]->getAbundance(i) != 0){    incidence++;    }
+                       }
                        
-                       sum += (totalTerm * ((Aterm-Bterm)*(Aterm-Bterm)));
+                       if(incidence != 0){
+                               sum += (((Aterm-Bterm)*(Aterm-Bterm))/incidence);
+                       }
                }
                
-               data[0] = sqrt((totalOtus * sum));
+               data[0] = sqrt(totalOtus * sum);
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index 934bd01cb6039a9dd91d27eef9f0b30a87d3c827..2503b5dc1cfc18e253e6042b25931068f3c13054 100644 (file)
@@ -46,9 +46,9 @@ EstOutput MemPearson::getValues(vector<SharedRAbundVector*> shared) {
                denomTerm2 = sqrt(denomTerm2);
                
                double denom = denomTerm1 * denomTerm2;
-               
+
                if (denom != 0) { 
-                       data[0] = 1.0 - (numTerm / denom);
+                       data[0] = (numTerm / denom);
                }else {
                        data[0] = 1.0;
                }
index 09ec692259f8845e7543bdf71eeab298c657d207..10dfbd544bedeafaa3a82c282174480e9b55d005 100644 (file)
@@ -33,7 +33,7 @@ EstOutput Anderberg::getValues(vector<SharedRAbundVector*> shared) {
                        if ((tempA != 0) && (tempB != 0)) {     S12++; }
                }
                
-               data[0] = S12 / ((float)((2 * S1) + (2 * S2) - (3 * S12)));
+               data[0] = 1.0 - S12 / ((float)((2 * S1) + (2 * S2) - (3 * S12)));
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index 566df3b8d87a93c8bbc069e078c2a68f4e71f2bd..0182e13bd34ea9164383b5f83c221ae705898677 100644 (file)
@@ -37,7 +37,7 @@ EstOutput BrayCurtis::getValues(vector<SharedRAbundVector*> shared) {
                        else  { sumSharedAB += tempB; }                         
                }
                
-               data[0] = (2 * sumSharedAB) / (float)( sumSharedA + sumSharedB);
+               data[0] = 1.0 - (2 * sumSharedAB) / (float)( sumSharedA + sumSharedB);
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                                
index 79c9f5223c3be4d4cdce4a1516db914169793fbc..d86fcb8ef65da974cc69b14be6417939bcded5a7 100644 (file)
@@ -20,8 +20,8 @@ EstOutput JAbund::getValues(vector<SharedRAbundVector*> shared) {
                UVest = uv->getUVest(shared);
                
                //UVest[0] is Uest UVest[1] is Vest
-               data[0] = (UVest[0] * UVest[1]) / ((float)(UVest[0] + UVest[1] - (UVest[0] * UVest[1])));
-               if(data[0] > 1){data[0] = 1;    }
+               data[0] = 1.0-(UVest[0] * UVest[1]) / ((float)(UVest[0] + UVest[1] - (UVest[0] * UVest[1])));
+               if(data[0] > 1){data[0] = 0;    }
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
                return data;
index ede4e31264d49b1cc26ccb4e684262ec6f1c1d3e..ac3e94eaffaa8ac339935a97267c56b0d4e832db 100644 (file)
@@ -34,7 +34,7 @@ EstOutput Jclass::getValues(vector<SharedRAbundVector*> shared) {
                        if ((tempA != 0) && (tempB != 0)) {     S12++; }
                }
                
-               data[0] = S12 / (float)(S1 + S2 - S12);
+               data[0] = 1.0 - S12 / (float)(S1 + S2 - S12);
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index 504dd7d605d7d06193c4596841975b0a8f801086..9a1cfbb5a1567153628a1213a494c36242e1d763 100644 (file)
@@ -39,7 +39,7 @@ EstOutput Jest::getValues(vector<SharedRAbundVector*> shared) {
                S1 = chaoS1->getValues(chaoS1Sabund);
                S2 = chaoS2->getValues(chaoS2Sabund);
                
-               data[0] = S12[0] / (float)(S1[0] + S2[0] - S12[0]);
+               data[0] = 1.0 - S12[0] / (float)(S1[0] + S2[0] - S12[0]);
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index c19df537a4f382f5404d8d2c643725599fba2478..6aad5df26f2a6912b950df9e8d8211e730ef0fe1 100644 (file)
@@ -33,7 +33,7 @@ EstOutput Kulczynski::getValues(vector<SharedRAbundVector*> shared) {
                        if ((tempA != 0) && (tempB != 0)) {     S12++; }
                }
                
-               data[0] = S12 / (float)(S1 + S2 - (2 * S12));
+               data[0] = 1.0 - S12 / (float)(S1 + S2 - (2 * S12));
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index 57fcb248d8747332098dfc57657cf021897a46e6..de90252769a3925c96a463a62c63a1349c3ef710 100644 (file)
@@ -33,7 +33,7 @@ EstOutput KulczynskiCody::getValues(vector<SharedRAbundVector*> shared) {
                        if ((tempA != 0) && (tempB != 0)) {     S12++; }
                }
                
-               data[0] = 0.5 * ((S12 / (float)S1) + (S12 / (float)S2));
+               data[0] = 1.0 - 0.5 * ((S12 / (float)S1) + (S12 / (float)S2));
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index 0c0f833f33ff83299237b8b03cc9e28174f2c224..f3ed5ece3850f6528ecb56cc99a17765b7766ff7 100644 (file)
@@ -39,7 +39,7 @@ EstOutput Lennon::getValues(vector<SharedRAbundVector*> shared) {
                if (tempA < tempB) { min = tempA; }
                else { min = tempB; }
                
-               data[0] = S12 / (float)(S12 + min);
+               data[0] = 1.0 - S12 / (float)(S12 + min);
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index d52ead5e6fccbb784487fd188b12424035a30658..bd4923f32ddf4337ce6f8570fd57fcd199ccaf6f 100644 (file)
@@ -39,9 +39,9 @@ EstOutput MorHorn::getValues(vector<SharedRAbundVector*> shared) {
                        d += relA * relB;
                }
 
-               morhorn = (2 * d) / (a + b);
+               morhorn = 1- (2 * d) / (a + b);
 
-               if (isnan(morhorn) || isinf(morhorn)) { morhorn = 0; }
+               if (isnan(morhorn) || isinf(morhorn)) { morhorn = 1; }
                
                data[0] = morhorn;
                
index 90b825adbd8a7c0522f5be47db3a9009693bc735..9a1bd63d7bd2a5b459c6b9955afa77cebc23ed7c 100644 (file)
@@ -23,6 +23,7 @@ EstOutput SorAbund::getValues(vector<SharedRAbundVector*> shared) {
                data[0] = (2 * UVest[0] * UVest[1]) / ((float)(UVest[0] + UVest[1]));
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               data[0] = 1-data[0];
                
                return data;
        }
index 2cebc7df47a7c13926bc0758653cabe4fc32b8ae..32728f575a52f94c9d7b8b287fd14a7147ad53e9 100644 (file)
@@ -34,7 +34,7 @@ EstOutput SorClass::getValues(vector<SharedRAbundVector*> shared) {
                        if ((tempA != 0) && (tempB != 0)) {     S12++; }
                }
                
-               data[0] = (2 * S12) / (float)(S1 + S2);
+               data[0] = 1.0-(2 * S12) / (float)(S1 + S2);
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index d3ae59e6c119c90989eb72fbb61b35c7085bcbe8..b9ab0501bc5f8f7fa000b16b14f79bfad237b8cf 100644 (file)
@@ -38,7 +38,7 @@ EstOutput SorEst::getValues(vector<SharedRAbundVector*> shared) {
                S1 = chaoS1->getValues(chaoS1Sabund);
                S2 = chaoS2->getValues(chaoS2Sabund);
                
-               data[0] = (2 * S12[0]) / (float)(S1[0] + S2[0]);
+               data[0] = 1.0-(2 * S12[0]) / (float)(S1[0] + S2[0]);
                 
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index 361c7b26ebc52937a6fcd2f890da162a4a3cd9b3..7c42a18d662f9b8d976a39515a47c4e79d509e22 100644 (file)
@@ -46,7 +46,7 @@ EstOutput ThetaN::getValues(vector<SharedRAbundVector*> shared) {
                
                if (isnan(thetaN) || isinf(thetaN)) { thetaN = 0; }
                
-               data[0] = thetaN;
+               data[0] = 1.0 - thetaN;
                
                return data;
        }
index ed18d9252ed52ef126355336f04bd04b67b0d7c3..315a61f1310f8381e7fab74546f059d1823f11f7 100644 (file)
@@ -74,6 +74,7 @@ EstOutput ThetaYC::getValues(vector<SharedRAbundVector*> shared) {
                if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
                if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
                
+               data[0] = 1.0 - data[0];
                return data;
        }
        catch(exception& e) {
index 72d5667e97a0e6a0a499464fe529699212ae8a91..49d5265259bc2ceb566d6f88f71fda30130b7945 100644 (file)
@@ -10,6 +10,7 @@
 #include "spearman.h"
 
 /***********************************************************************/
+
 EstOutput Spearman::getValues(vector<SharedRAbundVector*> shared) {
        try {
                data.resize(1,0);
@@ -20,28 +21,51 @@ EstOutput Spearman::getValues(vector<SharedRAbundVector*> shared) {
                double sumRanks = 0.0;
                int numOTUS = shared[0]->getNumBins();
                
-               //calc the 2 denominators
-               for (int i = 0; i < shared[0]->getNumBins(); i++) { 
+               vector<double> rankVectorA(savA.getMaxRank()+1, 0);
+               int currentRankA = 0;
+               for(int i=savA.getMaxRank();i>0;i--){   
+                       int numWithAbundanceI = savA.get(i);
+
+                       if(numWithAbundanceI > 1){      rankVectorA[i] = (currentRankA + 1 + currentRankA + numWithAbundanceI) / 2.0;   }
+                       else                                    {       rankVectorA[i] = currentRankA+numWithAbundanceI;        }
+                       currentRankA += numWithAbundanceI;
+               }
+               rankVectorA[0] = (numOTUS + currentRankA + 1) / 2.0;
+               
+               
+               vector<double> rankVectorB(savB.getMaxRank()+1, 0);
+               int currentRankB = 0;
+               for(int i=savB.getMaxRank();i>0;i--){   
+                       int numWithAbundanceI = savB.get(i);
                        
+                       if(numWithAbundanceI > 1){      rankVectorB[i] = (currentRankB + 1 + currentRankB + numWithAbundanceI) / 2.0;   }
+                       else                                    {       rankVectorB[i] = currentRankB+numWithAbundanceI;        }
+                       currentRankB += numWithAbundanceI;
+               }
+               rankVectorB[0] = (numOTUS + currentRankB + 1) / 2.0;
+               
+               
+
+               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);
+                       float rankA = rankVectorA[Aij];
+                       float rankB = rankVectorB[Bij];
                        
                        sumRanks += ((rankA - rankB) * (rankA - rankB));
                }
-               
-               data[0] = 1.0 - ((6 * sumRanks) / (float) (numOTUS * (numOTUS-1)));
+               data[0] = 1.0 - ((6 * sumRanks) / (float) (numOTUS * ((numOTUS*numOTUS)-1)));
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
                return data;
        }
        catch(exception& e) {
-               m->errorOut(e, "Soergel", "getValues");
+               m->errorOut(e, "Spearman", "getValues");
                exit(1);
        }
 }
+
 /***********************************************************************/
 
index bc2ac76b5c7222999f068709275d0d0aea9a5047..a21eb9936aa7799e9d56436a4c513c668148d7d9 100644 (file)
@@ -37,7 +37,7 @@ EstOutput StructPearson::getValues(vector<SharedRAbundVector*> shared) {
                
                double denom = denomTerm1 * denomTerm2;
                
-               data[0] = 1.0 - (numTerm / denom);
+               data[0] = (numTerm / denom);
                
                if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
                
index 8688edd3871ca05542a06dd2432dd094ab948889..5ab1e5dd88eedb8e0fb0dbe52d0b42e0c61d3c44 100644 (file)
@@ -23,7 +23,7 @@ EstOutput Whittaker::getValues(vector<SharedRAbundVector*> shared){
                        if(shared[1]->getAbundance(i) != 0){    countB++;       }               
                }
                
-               data[0] = 2*sTotal/(float)(countA+countB)-1;
+               data[0] = 2-2*sTotal/(float)(countA+countB);
                return data;
        }
        catch(exception& e) {