5 * Created by Thomas Ryabin on 3/6/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sharedkstest.h"
12 /***********************************************************************/
14 EstOutput KSTest::getValues(vector<SharedRAbundVector*> shared){
18 //Must return shared1 and shared2 to original order at conclusion of kstest
19 vector <individual> initData1 = shared[0]->getData();
20 vector <individual> initData2 = shared[1]->getData();
24 int numNZ1 = shared[0]->numNZ();
25 int numNZ2 = shared[1]->numNZ();
26 double numInd1 = (double)shared[0]->getNumSeqs();
27 double numInd2 = (double)shared[1]->getNumSeqs();
32 for(int i = 1; i < shared[0]->getNumBins(); i++)
34 sum1 += shared[0]->get(i).abundance;
35 sum2 += shared[1]->get(i).abundance;
36 double diff = fabs((double)sum1/numInd1 - (double)sum2/numInd2);
41 double DStatistic = maxDiff*numNZ1*numNZ2;
42 double a = pow((double)(numNZ1 + numNZ2)/(numNZ1*numNZ2),.5);
43 //double pVal = exp(-2*pow(maxDiff/a,2));
44 double critVal = 1.36*a*numNZ1*numNZ2;
46 /*cout << "Kolmogorov-Smirnov 2-sample test:\n";
47 if(numNZ1 > 25 && numNZ2 > 25) //If the sample sizes are both bigger than 25.
48 cout << "P-Value = " << pVal << "\nP-Value is the probability that the data sets are significantly different.\n";
51 //cout << "90% Confidence Critical Value = " << 1.22*a*numNZ1*numNZ2 << "\n";
52 cout << "D-Statistic = " << DStatistic << "\n";
53 cout << "95% Confidence Critical Value = " << critVal << "\n";
54 cout << "If D-Statistic is greater than the critical value then the data sets are significantly different at the 95% confidence level.\n\n";
57 shared[0]->setData(initData1);
58 shared[1]->setData(initData2);
62 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
63 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
68 cout << "Standard Error: " << e.what() << " has occurred in the KSTest class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
72 cout << "An unknown error has occurred in the KSTest class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
77 /***********************************************************************/