5 * Created by Sarah Westcott on 1/7/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12 /***********************************************************************/
13 EstOutput Chao1::getValues(SAbundVector* rank){
17 double sobs = (double)rank->getNumBins();
19 //this is a modification do to a vector fill error that occurs when an empty sharedRabund creates a sabund
20 //in that case there is no 1 0r 2.
22 if (rank->size() > 1) {
23 singles = (double)rank->get(1);
24 }else{ singles = 0.0; }
27 if (rank->size() > 2) {
28 doubles = (double)rank->get(2);
29 }else{ doubles = 0.0; }
31 double chaovar = 0.0000;
32 //cout << "singles = " << singles << " doubles = " << doubles << " sobs = " << sobs << endl;
33 double chao = sobs + singles*(singles-1)/(2*(doubles+1));
35 if(singles > 0 && doubles > 0){
36 chaovar = singles*(singles-1)/(2*(doubles+1))
37 + singles*pow(2*singles-1, 2)/(4*pow(doubles+1,2))
38 + pow(singles, 2)*doubles*pow(singles-1, 2)/(4*pow(doubles+1,4));
40 else if(singles > 0 && doubles == 0){
41 chaovar = singles*(singles-1)/2 + singles*pow(2*singles-1, 2)/4 - pow(singles, 4)/(4*chao);
43 else if(singles == 0){
44 chaovar = sobs*exp(-1*rank->getNumSeqs()/sobs)*(1-exp(-1*rank->getNumSeqs()/sobs));
47 double chaohci, chaolci;
50 double denom = pow(chao-sobs,2);
51 double c = exp(1.96*pow((log(1+chaovar/denom)),0.5));
52 chaolci = sobs+(chao-sobs)/c;//chao lci
53 chaohci = sobs+(chao-sobs)*c;//chao hci
56 double p = exp(-1*rank->getNumSeqs()/sobs);
57 chaolci = sobs/(1-p)-1.96*pow(sobs*p/(1-p), 0.5);
58 chaohci = sobs/(1-p)+1.96*pow(sobs*p/(1-p), 0.5);
59 if(chaolci < sobs){ chaolci = sobs; }
66 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
67 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
68 if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
73 m->errorOut(e, "Chao1", "getValues");
78 /***********************************************************************/