5 * Created by Thomas Ryabin on 3/30/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sharedjackknife.h"
12 /***************************************************************************************
14 ***************************************************************************************/
15 double SharedJackknife::simpson(vector<int> abunds, double numInd, int numBins){
16 double denom = numInd*(numInd-1);
18 for(int i = 0; i < numBins; i++)
19 sum += (double)abunds[i]*((double)abunds[i]-1)/denom;
24 /*****************************************************************************************/
26 double* SharedJackknife::jackknife(){
27 int numBins = groups.at(0)->getNumBins()-1;
28 vector<int> cArray(numBins);
29 for(int i = 0; i < numBins; i++)
33 for(int i = 0; i < numGroups; i++)
34 for(int j = 0; j < numBins; j++) {
35 int curAbund = groups.at(i)->get(j+1).abundance;
36 cArray[j] += curAbund;
37 numInd += (double)curAbund;
40 double baseD = 1/simpson(cArray, numInd, numBins);
42 vector<double> pseudoVals(numBins);
43 double jackknifeEstimate = 0;
44 for(int i = 0; i < numGroups; i++) {
45 for(int j = 0; j < numBins-1; j++) {
46 int abundDiff = -groups.at(i)->get(j+1).abundance;
48 abundDiff += groups.at(i-1)->get(j+1).abundance;
50 cArray[j] += abundDiff;
54 double curD = 1/simpson(cArray, numInd, numBins);
55 pseudoVals[i] = (double)numGroups*(baseD - curD) + curD;
56 jackknifeEstimate += pseudoVals[i];
58 jackknifeEstimate /= (double)numGroups;
61 for(int i = 0; i < numGroups; i++)
62 variance += pow(pseudoVals[i]-jackknifeEstimate, 2);
64 variance /= (double)numGroups*((double)numGroups-1);
65 double stErr = sqrt(variance);
69 confLimit = table.getConfLimit(numGroups-1, 1);
75 double* rdata = new double[3];
77 rdata[1] = jackknifeEstimate - confLimit;
78 rdata[2] = jackknifeEstimate + confLimit;
83 /************************************************************************************************
84 ************************************************************************************************/
86 EstOutput SharedJackknife::getValues(vector<SharedRAbundVector*> vectorShared){ //Fix this for collect, mistake was that it was made with summary in mind.
88 SharedRAbundVector* shared1 = vectorShared[0];
89 SharedRAbundVector* shared2 = vectorShared[1];
91 numGroups = m->getNumGroups();
94 if(callCount == numGroups*(numGroups-1)/2) {
95 currentCallDone = true;
100 if(currentCallDone) {
102 currentCallDone = false;
105 if(groups.size() != numGroups) {
106 if(groups.size() == 0)
107 groups.push_back(shared1);
108 groups.push_back(shared2);
111 if(groups.size() == numGroups && callCount < numGroups) {
114 double* rdata = jackknife();
119 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
120 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
121 if (isnan(data[2]) || isinf(data[0])) { data[2] = 0; }
131 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
132 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
133 if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
137 catch(exception& e) {
138 m->errorOut(e, "SharedJackknife", "getValues");
143 /***********************************************************************/