X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=memchi2.cpp;fp=memchi2.cpp;h=595b54f664d61e1fcd75e537d48b2e055fde2237;hb=5a7b1d45e9604becce2410333fcc71de818e3782;hp=07edd66475c9680cdacd5b9ff7920863323dd525;hpb=7ecb96ba54980d303fa066b4c29dae1e5a5be5b9;p=mothur.git diff --git a/memchi2.cpp b/memchi2.cpp index 07edd66..595b54f 100644 --- a/memchi2.cpp +++ b/memchi2.cpp @@ -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; }