X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=memchi2.cpp;h=f08b4b8561d9177fbd6f0a5a8f3337b95312e362;hp=07edd66475c9680cdacd5b9ff7920863323dd525;hb=615301e57c25e241356a9c2380648d117709458d;hpb=7d38edc137a66a33f67f8cf55cce88331290aaf7 diff --git a/memchi2.cpp b/memchi2.cpp index 07edd66..f08b4b8 100644 --- a/memchi2.cpp +++ b/memchi2.cpp @@ -17,7 +17,7 @@ EstOutput MemChi2::getValues(vector shared) { int nonZeroA = 0; int nonZeroB = 0; int totalOtus = shared[0]->getNumBins(); - int totalGroups = shared.size(); + //int totalGroups = shared.size(); //for each otu for (int i = 0; i < shared[0]->getNumBins(); i++) { @@ -25,7 +25,6 @@ EstOutput MemChi2::getValues(vector 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 shared) { double Aterm = A / (float) nonZeroA; double Bterm = B / (float) nonZeroB; + + int incidence = 0; + for(int j=0;jgetAbundance(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; }