5 * Created by Thomas Ryabin on 3/6/09.
6 * Copyright 2009 __MyCompanyName__. All rights reserved.
10 #include "sharedkstest.h"
11 #include "calculator.h"
14 /***********************************************************************/
16 EstOutput SharedKSTest::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
20 //Must return shared1 and shared2 to original order at conclusion of kstest
21 vector <individual> initData1 = shared1->getData();
22 vector <individual> initData2 = shared2->getData();
26 int numNZ1 = shared1->numNZ();
27 int numNZ2 = shared2->numNZ();
28 double numInd1 = (double)shared1->getNumSeqs();
29 double numInd2 = (double)shared2->getNumSeqs();
34 for(int i = 1; i < shared1->getNumBins(); i++)
36 sum1 += shared1->get(i).abundance;
37 sum2 += shared2->get(i).abundance;
38 double diff = fabs((double)sum1/numInd1 - (double)sum2/numInd2);
43 double DStatistic = maxDiff*numNZ1*numNZ2;
44 double a = pow((double)(numNZ1 + numNZ2)/(numNZ1*numNZ2),.5);
45 //double pVal = exp(-2*pow(maxDiff/a,2));
46 double critVal = 1.36*a*numNZ1*numNZ2;
48 /*cout << "Kolmogorov-Smirnov 2-sample test:\n";
49 if(numNZ1 > 25 && numNZ2 > 25) //If the sample sizes are both bigger than 25.
50 cout << "P-Value = " << pVal << "\nP-Value is the probability that the data sets are significantly different.\n";
53 //cout << "90% Confidence Critical Value = " << 1.22*a*numNZ1*numNZ2 << "\n";
54 cout << "D-Statistic = " << DStatistic << "\n";
55 cout << "95% Confidence Critical Value = " << critVal << "\n";
56 cout << "If D-Statistic is greater than the critical value then the data sets are significantly different at the 95% confidence level.\n\n";
59 shared1->setData(initData1);
60 shared2->setData(initData2);
64 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
65 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
70 cout << "Standard Error: " << e.what() << " has occurred in the NPShannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
74 cout << "An unknown error has occurred in the NPShannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
79 /***********************************************************************/