5 * Created by westcott on 12/17/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "structchi2.h"
12 /***********************************************************************/
13 EstOutput StructChi2::getValues(vector<SharedRAbundVector*> shared) {
17 double sumA = shared[0]->getNumSeqs();
18 double sumB = shared[1]->getNumSeqs();
19 double totalSum = 0.0;
21 for (int i = 0; i < shared.size(); i++) { totalSum += shared[i]->getNumSeqs(); }
23 vector<int> sumOtus; sumOtus.resize(shared[0]->getNumBins(), 0);
25 for (int i = 0; i < shared[0]->getNumBins(); i++) {
27 for (int j = 0; j < shared.size(); j++) {
28 sumOtus[i] += shared[j]->getAbundance(i);
33 for (int i = 0; i < shared[0]->getNumBins(); i++) {
34 int A = shared[0]->getAbundance(i);
35 int B = shared[1]->getAbundance(i);
37 double totalTerm = 1 / (float) sumOtus[i];
38 double Aterm = A / sumA;
39 double Bterm = B / sumB;
41 sum += (totalTerm * ((Aterm-Bterm)*(Aterm-Bterm)));
44 data[0] = sqrt((totalSum * sum));
46 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
51 m->errorOut(e, "StructChi2", "getValues");
55 /***********************************************************************/