X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=sharedthetayc.cpp;fp=sharedthetayc.cpp;h=6f3f25001a73208caa74dc438a0b9c7652f70531;hb=0fb6d165c8dc8dc7153a101513a05f457431d0bc;hp=45dce49ce0a1185c1558068bc27e15be87f03fcb;hpb=956cdff34f2d609a7736838b1631cd7957580b8b;p=mothur.git diff --git a/sharedthetayc.cpp b/sharedthetayc.cpp index 45dce49..6f3f250 100644 --- a/sharedthetayc.cpp +++ b/sharedthetayc.cpp @@ -12,38 +12,63 @@ /***********************************************************************/ EstOutput ThetaYC::getValues(vector shared) { try { - data.resize(1,0); + data.resize(3,0.0000); - int Atotal = 0; - int Btotal = 0; + float Atotal = 0; + float Btotal = 0; float thetaYC = 0; - float relA = 0; - float relB = 0; + float pi = 0; + float qi = 0; float a = 0; float b = 0; + float d = 0; + + float sumPcubed = 0; + float sumQcubed = 0; + float sumPQsq = 0; + float sumPsqQ = 0; //get the total values we need to calculate the theta denominator sums for (int i = 0; i < shared[0]->size(); i++) { //store in temps to avoid multiple repetitive function calls - Atotal += shared[0]->getAbundance(i); - Btotal += shared[1]->getAbundance(i); + Atotal += (float)shared[0]->getAbundance(i); + Btotal += (float)shared[1]->getAbundance(i); } //calculate the theta denominator sums for (int j = 0; j < shared[0]->size(); j++) { //store in temps to avoid multiple repetitive function calls - relA = shared[0]->getAbundance(j) / (float)Atotal; - relB = shared[1]->getAbundance(j) / (float)Btotal; + pi = shared[0]->getAbundance(j) / Atotal; + qi = shared[1]->getAbundance(j) / Btotal; - a += relA * relB; - b += pow((relA-relB),2); + a += pi * pi; + b += qi * qi; + d += pi * qi; + + sumPcubed += pi * pi * pi; + sumQcubed += qi * qi * qi; + sumPQsq += pi * qi * qi; + sumPsqQ += pi * pi * qi; } - thetaYC = a / (float) (b+a); + thetaYC = d / (a + b - d); if (isnan(thetaYC) || isinf(thetaYC)) { thetaYC = 0; } + float varA = 4 / Atotal * (sumPcubed - a * a); + float varB = 4 / Btotal * (sumQcubed - b * b); + float varD = sumPQsq / Atotal + sumPsqQ / Btotal - d * d * (1/Atotal + 1/Btotal); + float covAD = 2 / Atotal * (sumPsqQ - a * d); + float covBD = 2 / Btotal * (sumPQsq - b* d); + + float varT = d * d * (varA + varB) / pow(a + b - d, (float)4.0) + pow(a+b, (float)2.0) * varD / pow(a+b-d, (float)4.0) + - 2.0 * (a + b) * d / pow(a + b - d, (float)4.0) * (covAD + covBD); + + float ci = 1.95 * sqrt(varT); + data[0] = thetaYC; + data[1] = thetaYC - ci; + data[2] = thetaYC + ci; return data; }