1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
|
/*
* treetest.c
*
*
* Part of TREE-PUZZLE 5.2 (July 2004)
*
* (c) 2003-2004 by Heiko A. Schmidt, Korbinian Strimmer, and Arndt von Haeseler
* (c) 1999-2003 by Heiko A. Schmidt, Korbinian Strimmer,
* M. Vingron, and Arndt von Haeseler
* (c) 1995-1999 by Korbinian Strimmer and Arndt von Haeseler
*
* All parts of the source except where indicated are distributed under
* the GNU public licence. See http://www.opensource.org for details.
*
* ($Id$)
*
*/
#include <treetest.h>
#ifndef STDOUT
# define STDOUT stdout
#endif
/*****************************************************************************/
/* ELW/SR Test (Expected Likelihood Weights, Strimmer & Rambaut, 2002) */
/*****************************************************************************/
void elw_test(ivector Alias,
dmatrix allsites,
int numutrees,
int numsites,
double siglevel,
int numboots,
ivector *elw_test_passed,
dvector *elw_Support)
{
/*
* Determine posterior probabilties and support values
* for each hypothesis and store results in public arrays
* posterior, support etc which will automatically be
* created by this procedure.
*
* allsites log-likelihoods of each pattern
* Alias map of patterns to sites in sequence
* numboots number of bootstraps
*/
dvector deltaL; /* delta of likelihoods (double[numH]) */
dvector elw_support; /* (double[numH]) */
dvector posterior; /* (double[numH]) */
ivector likelihoodOrder; /* (int[numH]) */
ivector supportOrder; /* (int[numH]) */
dvector rs; /* (int[numH]) */
double sum1;
double sum;
int numH; /* number of hypotheses */
int numSites; /* number of sites */
int s, p;
int i, j, k;
/* int j; */
double maxL;
double maxLogL;
ivector sr_test_res; /* [numutrees]; */
int elw_numboots = 1000;
/* number of hypothesis */
numH = numutrees;
/* allocate public arrays */
deltaL = new_dvector(numH);
elw_support = new_dvector(numH);
posterior = new_dvector(numH);
likelihoodOrder = new_ivector(numH);
supportOrder = new_ivector(numH);
sr_test_res = new_ivector(numutrees);
*elw_test_passed = sr_test_res;
*elw_Support = elw_support;
/* number of sites */
numSites = numsites;
/******************************************/
/* Compute log-likelihoods, their order, */
/* their deltas and their posteriors */
/******************************************/
/* initialize delta vector for each tree */
for (j = 0; j < numSites; j++) {
if (Alias == NULL) {
p = j;
} else {
p = Alias[j];
}
for (k = 0; k < numH; k++) {
deltaL[k] -= allsites[k][p];
}
}
/* sort likelihoods -> sorted index list likelihoodOrder */
/* insertion sort */
{
int tmp;
int idx;
for (k=0; k < numH; k++) likelihoodOrder[k] = k;
for (j=0; j < numH-1; j++) {
idx=j;
for (k=j+1; k < numH; k++) {
if (deltaL[likelihoodOrder[k]] < deltaL[likelihoodOrder[idx]]) idx=k;
}
tmp = likelihoodOrder[j];
likelihoodOrder[j] = likelihoodOrder[idx];
likelihoodOrder[idx] = tmp;
}
}
/* Compute deltas */
maxL= -deltaL[likelihoodOrder[0]];
for (j = 0; j < numH; j++) {
deltaL[j] = -(deltaL[j]+maxL);
}
/* compute posterior probabilities */
sum1 = 0.0;
for (j = 0; j < numH; j++) {
posterior[j] = exp(deltaL[j]);
sum1 += posterior[j];
}
for (j = 0; j < numH; j++) {
posterior[j] = posterior[j]/sum1;
}
/* reverse sign of delta L */
for (j = 0; j < numH; j++) {
deltaL[j] = -deltaL[j];
}
deltaL[likelihoodOrder[0]] = 0.0;
/* Bootstrap/Resample data */
/***************************/
/* temporary memory */
rs = new_dvector(numH);
/* MersenneTwisterFast mt = new MersenneTwisterFast(); */
for (i = 0; i < elw_numboots; i++) { /* num bootstraps */
for (k = 0; k < numH; k++) {
rs[k] = 0;
}
for (j = 0; j < numSites; j++) { /* bootstrapping sites for ...*/
/* int s = mt.nextInt(numSites); */
s = randominteger(numSites);
if (Alias == NULL) {
p = s;
} else {
p = Alias[s];
}
for (k = 0; k < numH; k++) { /* ...each utree <k> */
/* rs[k] += pLogL[k][p]; */
rs[k] += allsites[k][p];
}
}
/* find ml hypothesis */
/* maxLogL = findMax(rs); */
{
int best = 0; /* can be removed (HAS) */
int idx;
double max = rs[0];
for (idx = 1; idx < numH; idx++) {
if (rs[idx] > max) {
best = idx; /* can be removed (HAS) */
max = rs[idx];
}
}
maxLogL = max;
}
/* compute log-likelihood difference */
for (k = 0; k < numH; k++) {
rs[k] = rs[k] - maxLogL;
}
/* compute posteriors and sum over resampled data set */
sum = 0.0;
for (k = 0; k < numH; k++) {
rs[k] = exp(rs[k]);
sum += rs[k];
}
for (k = 0; k < numH; k++) {
elw_support[k] += rs[k]/sum;
}
}
/* compute support values */
for (j = 0; j < numH; j++) {
elw_support[j] = elw_support[j]/elw_numboots;
}
/* determine order of elw_support (smallest->largest) */
/* HeapSort.sort(elw_support, supportOrder); */
{
int tmp;
int idx;
for (k=0; k < numH; k++) supportOrder[k] = k;
for (j=0; j < numH-1; j++) {
idx=j;
for (k=j+1; k < numH; k++) {
if (elw_support[supportOrder[k]] > elw_support[supportOrder[idx]]) idx=k;
}
tmp = supportOrder[j];
supportOrder[j] = supportOrder[idx];
supportOrder[idx] = tmp;
}
}
sum = 0.0;
for (k=0; k<numH; k++) {
if(sum <= .95) {
sum += elw_support[supportOrder[k]];
sr_test_res[supportOrder[k]] = 1; /* within confidence set */
} else {
/* sum += elw_support[supportOrder[k]]; */ /* shouldn't the sum increase after exclusion ??? (HAS) */
sum += elw_support[supportOrder[k]]; /* included to code */
sr_test_res[supportOrder[k]] = 0; /* excluded from confidence set */
}
}
} /* elw_test */
/* TODO: move to treetest.c */
/*****************************************************************************/
/* SH Test (Shimodaira & Hasegawa, 1999) */
/*****************************************************************************/
void sh_test(ivector Alias, /* site pattern translat array */
dmatrix allsites, /* tree site log-likelihoods */
int numutrees, /* number of trees */
int numsites, /* number of sites */
double siglevel, /* significance level to test */
int numboots, /* number of bootstraps to draw */
ivector *sh_test_passed, /* has tree passed tests */
dvector *sh_Pval) /* and p-value */
{
/*
* Shimodaira-Hasegawa-Test (1999) to
* compare a set of evolutionary hypotheses.
* Compare all given hypotheses to the best (ML) hypothesis
* and store results in public arrays delta, pval
* (which will automatically be created by this procedure).
*
* allsites log-likelihoods of each pattern
* Alias map of patterns to sites in sequence
* numboots number of bootstraps
*/
int bestH; /* number of maximum likelihood hypothesis */
dvector sh_delta; /* log-LH difference to ml hypothesis */
dvector sh_pval; /* corresponding p-value */
dvector sh_logL;
int sh_numboots = 1000;
double maxLogL;
double m;
dmatrix bs; /* = new int[numH,sh_numboots]; */
int best;
double colmax;
int count;
double sh_prob = .05;
ivector sh_test_res; /* [numutrees]; */
int numH;
int numSites;
int i, j, k;
int p, s;
/* number of hypothesis */
numH = numutrees;
/* allocate memory for results */
sh_delta = new_dvector(numH);
sh_pval = new_dvector(numH);
sh_test_res = new_ivector(numutrees);
*sh_Pval = sh_pval;
*sh_test_passed = sh_test_res;
/* number of sites */
numSites = numsites;
/* log likelihood of each hypothesis */
sh_logL = new_dvector(numH);
for (i = 0; i < numSites; i++) {
if (Alias == NULL) {
p = i;
} else {
p = Alias[i];
}
for (j = 0; j < numH; j++) {
/* sh_logL[j] += pLogL[j][p]; */
sh_logL[j] += allsites[j][p];
}
}
/* find maximum-likelihood hypothesis */
bestH = 0;
maxLogL = sh_logL[0];
for (i = 1; i < numH; i++) {
if (sh_logL[i] > maxLogL) {
bestH = i;
maxLogL = sh_logL[i];
}
}
/* compute log-likelihood differences to best hypothesis */
for (i = 0; i < numH; i++) {
sh_delta[i] = sh_logL[bestH]-sh_logL[i];
}
/* allocate temporary memory for resampling procedure */
bs = new_dmatrix(numH,sh_numboots);
/* Resample data */
/* MersenneTwisterFast mt = new MersenneTwisterFast(); */
for (i = 0; i < sh_numboots; i++) {
for (j = 0; j < numSites; j++) {
/* int s = mt.nextInt(numSites); */
s = randominteger(numSites);
if (Alias == NULL) {
p = s;
} else {
p = Alias[s];
}
for (k = 0; k < numH; k++) {
/* rs[k][i] += pLogL[k][p]; */
bs[k][i] += allsites[k][p];
}
}
}
/* center resampled log-likelihoods */
for (i = 0; i < numH; i++) {
/* double m = DiscreteStatistics.mean(rs[i]); */
m = 0.0;
for (j = 0; j < sh_numboots; j++) {
m += bs[i][j];
}
m /= sh_numboots;
for (j = 0; j < sh_numboots; j++) {
bs[i][j] = bs[i][j] - m;
}
}
/* compute resampled log-likelihood differences */
for (i = 0; i < sh_numboots; i++) {
/* double max = findMaxInColumn(rs, i); */
{
best = 0;
colmax = bs[0][i];
for (j = 1; j < numH; j++) {
if (bs[j][i] > colmax) {
best = j;
colmax = bs[j][i];
}
}
}
for (j = 0; j < numH; j++) {
bs[j][i] = colmax - bs[j][i];
}
}
/* compute p-values for each hypothesis */
for (i = 0; i < numH; i++) {
count = 0;
for (j = 0; j < sh_numboots; j++) {
if (bs[i][j] >= sh_delta[i]) {
count++;
}
}
sh_pval[i] = (double) count/(double) sh_numboots;
if (sh_pval[i] >= sh_prob) {
sh_test_res[i] = 1;
} else {
sh_test_res[i] = 0;
}
}
/* free memory */
free_dmatrix(bs);
free_dvector(sh_logL);
} /* sh_test */
/* TODO: move to treetest.c */
/* print tree statistics */
void printtreestats(FILE *ofp,
dvector ulkl,
dvector ulklc,
int numutrees,
dmatrix allsites, /* tree site log-likelihoods */
dmatrix allsitesc, /* tree site log-likelihoods */
ivector Alias, /* link site -> corresponding site pattern */
int Maxsite,
int Numptrn,
ivector Weight,
int compclock)
{
int i, j; /* counter variables */
int besttree; /* best tree */
/* for the KH Test (Kishino & Hasegawa, 1989) */
double bestlkl; /* best likelihood */
double difflkl; /* best likelihood difference */
double difflklps; /* best likelihood difference per site */
double temp;
double sum;
/* variables for the SH Test (Shimodaira & Hasegawa, 1999) */
dvector sh_pval; /* corresponding p-value */
double sh_prob = .05; /* significance level */
int sh_numboots = 1000; /* number of bootstrap samples */
ivector sh_test_res; /* result vector [numutrees]; */
/* variables for the ELW/SR Test (Expected Likelihood Weights) */
/* (Strimmer & Rambaut, 2002) */
dvector elw_support; /* = new double[numH; */
ivector elw_test_res; /* result vector [numutrees]; */
int elw_numboots = 1000; /* number of bootstrap samples */
double elw_prob = .05; /* significance level */
/* variables for the one-sided KH Test using SH */
dvector kh1_pval_tmp; /* temp p-value arry for pairwise SH */
ivector kh1_test_res_tmp; /* temp result arry for pairwise SH */
dvector kh1_pval; /* p-values */
ivector kh1_test_res; /* result vector [numutrees]; */
dvector kh1_allsites_tmp[2]; /* temp arry for pairwise SH test */
int kh1_numboots = 1000; /* number of bootstrap samples */
double kh1_prob = .05; /* significance level */
/* find best tree */
besttree = 0;
bestlkl = ulkl[0];
for (i = 1; i < numutrees; i++) {
if (ulkl[i] > bestlkl) {
besttree = i;
bestlkl = ulkl[i];
}
}
/* one sided KH = pairwise SH test between tree and besttree */
fprintf(STDOUT, "Performing single sided KH test.\n");
fflush(STDOUT);
kh1_pval = new_dvector(numutrees);
kh1_test_res = new_ivector(numutrees);
kh1_allsites_tmp[0] = allsites[besttree]; /* set best tree */
for (i = 0; i < numutrees; i++) {
if (i == besttree) { /* if best tree -> no test */
kh1_pval[i] = 1.0;
kh1_test_res[i] = 1;
} else { /* other wise test pairwise SH */
if ((ulkl[besttree]-ulkl[i]) < MINKHDIFF) {
/* if approx equal to best tree -> no test */
kh1_pval[i] = 1.0;
kh1_test_res[i] = 1;
} else { /* other wise test pairwise SH */
kh1_allsites_tmp[1] = allsites[i]; /* set site log-lh */
sh_test(Alias, kh1_allsites_tmp, 2, Maxsite, kh1_prob, kh1_numboots, &kh1_test_res_tmp, &kh1_pval_tmp); /* pairwise SH */
kh1_pval[i] = kh1_pval_tmp[1]; /* store p-value */
kh1_test_res[i] = kh1_test_res_tmp[1]; /* save result */
}
}
}
free_ivector(kh1_test_res_tmp); /* moved out of loop */
free_dvector(kh1_pval_tmp);
/* ELW */
fprintf(STDOUT, "Performing ELW test.\n");
fflush(STDOUT);
elw_test(Alias, allsites, numutrees, Maxsite, elw_prob, elw_numboots, &elw_test_res, &elw_support);
/* SH */
fprintf(STDOUT, "Performing SH test.\n");
fflush(STDOUT);
sh_test(Alias, allsites, numutrees, Maxsite, sh_prob, sh_numboots, &sh_test_res, &sh_pval);
/*****************************************************************************/
/* two-sided KH Test (Kishino & Hasegawa, 1989) */
/* and output */
/*****************************************************************************/
fprintf(ofp, "\n\nCOMPARISON OF USER TREES (NO CLOCK)\n\n");
# ifdef KHTWOSIDED
fprintf(ofp, "Tree log L difference S.E. Sig. worse p-1sKH p-SH c-ELW \n");
fprintf(ofp, "-------------------------------------------------------------------------------\n");
# else
fprintf(ofp, "Tree log L difference S.E. p-1sKH p-SH c-ELW 2sKH\n");
fprintf(ofp, "-------------------------------------------------------------------------------\n");
# endif
for (i = 0; i < numutrees; i++) {
difflkl = ulkl[besttree]-ulkl[i];
if (difflkl < MINKHDIFF) {
/* if lkls (approx) equal to best tree, no difference */
difflkl = 0.0;
fprintf(ofp, "%2d %10.2f %8.2f ", i+1, ulkl[i], difflkl);
} else {
fprintf(ofp, "%2d %10.2f %8.2f ", i+1, ulkl[i], difflkl);
}
/* fprintf(ofp, "%2d %10.2f %8.2f ", i+1, ulkl[i], difflkl); */
if (i == besttree) {
# ifdef KHTWOSIDED
fprintf(ofp, " <-------------- best ");
# else
fprintf(ofp, " <---- best ");
/* fprintf(ofp, " <---- best "); */
# endif
if (kh1_test_res[i] == 1)
fprintf(ofp, " %6.4f +", kh1_pval[i]);
else
fprintf(ofp, " %6.4f -", kh1_pval[i]);
if (sh_test_res[i] == 1)
fprintf(ofp, " %6.4f +", sh_pval[i]);
else
fprintf(ofp, " %6.4f -", sh_pval[i]);
if (elw_test_res[i] == 1)
fprintf(ofp, " %6.4f +", elw_support[i]);
else
fprintf(ofp, " %6.4f -", elw_support[i]);
# ifdef KHTWOSIDED
# else
fprintf(ofp, " best");
# endif
} else {
/* compute variance of Log L differences over sites */
#ifndef USE_WINDOWS
difflklps = difflkl/(double)Maxsite;
#else
difflklps = difflkl/(double)alimaxsite;
#endif
sum = 0.0;
for (j = 0; j < Numptrn; j++) {
temp = allsites[besttree][j] - allsites[i][j] - difflklps;
sum += temp*temp*Weight[j];
}
#ifndef USE_WINDOWS
sum = sqrt( fabs(sum/(Maxsite-1.0)*Maxsite) );
#else
sum = sqrt(fabs(sum/(alimaxsite-1.0)*alimaxsite));
#endif
# ifdef KHTWOSIDED
fprintf(ofp, "%11.2f ", sum);
if (difflkl > 1.96*sum)
fprintf(ofp, "yes ");
else
fprintf(ofp, "no ");
# else
fprintf(ofp, "%11.4f ", sum);
/* fprintf(ofp, "%11.2f ", sum); */
# endif
if (kh1_test_res[i] == 1)
fprintf(ofp, " %6.4f +", kh1_pval[i]);
else
fprintf(ofp, " %6.4f -", kh1_pval[i]);
if (sh_test_res[i] == 1)
fprintf(ofp, " %6.4f +", sh_pval[i]);
else
fprintf(ofp, " %6.4f -", sh_pval[i]);
if (elw_test_res[i] == 1)
fprintf(ofp, " %6.4f +", elw_support[i]);
else
fprintf(ofp, " %6.4f -", elw_support[i]);
# ifdef KHTWOSIDED
# else
#if 0
if (difflkl > 1.96*sum)
fprintf(ofp, " - (diff=%.4f 1.96*sum=%.4e)", difflkl, 1.96*sum);
else
fprintf(ofp, " + (diff=%.4f 1.96*sum=%.4e)", difflkl, 1.96*sum);
#endif
if (difflkl > 1.96*sum)
fprintf(ofp, " -");
else
fprintf(ofp, " +");
# endif
}
fprintf(ofp, "\n");
}
fprintf(ofp, "\nThe columns show the results and p-values of the following tests:\n");
fprintf(ofp, "1sKH - one sided KH test based on pairwise SH tests (Shimodaira-Hasegawa\n");
fprintf(ofp, " 2000, Goldman et al., 2001, Kishino-Hasegawa 1989)\n");
fprintf(ofp, "SH - Shimodaira-Hasegawa test (2000)\n");
fprintf(ofp, "ELW - Expected Likelihood Weight (Strimmer-Rambaut 2002)\n");
fprintf(ofp, "2sKH - two sided Kishino-Hasegawa test (1989)\n");
fprintf(ofp, "\n");
fprintf(ofp, "Plus signs denote the confidence sets. Minus signs denote significant\n");
fprintf(ofp, "exclusion. All tests used 5%% significance level. 1sKH, SH, and ELW\n");
fprintf(ofp, "performed 1000 resamplings using the RELL method.\n");
fprintf(ofp, "1sKH and 2sKH are correct to the 2nd position after the the decimal\n");
fprintf(ofp, "point of the log-likelihoods.\n");
if (compclock) {
/* find best tree */
besttree = 0;
bestlkl = ulklc[0];
for (i = 1; i < numutrees; i++)
if (ulklc[i] > bestlkl) {
besttree = i;
bestlkl = ulklc[i];
}
/* one sided KH */
fprintf(STDOUT, "Performing single sided KH test (clock).\n");
fflush(STDOUT);
kh1_pval = new_dvector(numutrees);
kh1_test_res = new_ivector(numutrees);
kh1_allsites_tmp[0] = allsitesc[besttree];
for (i = 0; i < numutrees; i++) {
if (i != besttree) {
if ((ulklc[besttree]-ulklc[i]) < MINKHDIFF) {
/* if approx equal to best tree -> no test */
kh1_pval[i] = 1.0;
kh1_test_res[i] = 1;
} else { /* other wise test pairwise SH */
kh1_allsites_tmp[1] = allsitesc[i];
sh_test(Alias, kh1_allsites_tmp, 2, Maxsite, kh1_prob, kh1_numboots, &kh1_test_res_tmp, &kh1_pval_tmp);
kh1_pval[i] = kh1_pval_tmp[1];
kh1_test_res[i] = kh1_test_res_tmp[1];
free_ivector(kh1_test_res_tmp);
free_dvector(kh1_pval_tmp);
}
} else {
kh1_pval[i] = 1.0;
kh1_test_res[i] = 1;
}
}
/* ELW */
fprintf(STDOUT, "Performing ELW test (clock).\n");
fflush(STDOUT);
elw_test(Alias, allsitesc, numutrees, Maxsite, elw_prob, elw_numboots, &elw_test_res, &elw_support);
/* SH */
fprintf(STDOUT, "Performing SH test (clock).\n");
fflush(STDOUT);
sh_test(Alias, allsitesc, numutrees, Maxsite, sh_prob, sh_numboots, &sh_test_res, &sh_pval);
fprintf(ofp, "\n\nCOMPARISON OF USER TREES (WITH CLOCK)\n\n");
# ifdef KHTWOSIDED
fprintf(ofp, "Tree log L difference S.E. Sig. worse p-1sKH p-SH c-ELW \n");
fprintf(ofp, "-------------------------------------------------------------------------------\n");
# else
fprintf(ofp, "Tree log L difference S.E. p-1sKH p-SH c-ELW 2sKH\n");
fprintf(ofp, "-------------------------------------------------------------------------------\n");
# endif
for (i = 0; i < numutrees; i++) {
difflkl = ulklc[besttree]-ulklc[i];
if (difflkl < MINKHDIFF) {
/* if lkls (approx) equal to best tree, no difference */
difflkl = 0.0;
fprintf(ofp, "%2d %10.2f %8.2f ", i+1, ulklc[i], difflkl);
} else {
fprintf(ofp, "%2d %10.2f %8.2f ", i+1, ulklc[i], difflkl);
}
if (i == besttree) {
# ifdef KHTWOSIDED
fprintf(ofp, " <-------------- best ");
# else
fprintf(ofp, " <---- best ");
# endif
if (kh1_test_res[i] == 1)
fprintf(ofp, " %6.4f +", kh1_pval[i]);
else
fprintf(ofp, " %6.4f -", kh1_pval[i]);
if (sh_test_res[i] == 1)
fprintf(ofp, " %6.4f +", sh_pval[i]);
else
fprintf(ofp, " %6.4f -", sh_pval[i]);
if (elw_test_res[i] == 1)
fprintf(ofp, " %6.4f +", elw_support[i]);
else
fprintf(ofp, " %6.4f -", elw_support[i]);
# ifdef KHTWOSIDED
# else
fprintf(ofp, " best");
# endif
} else {
/* compute variance of Log L differences over sites */
#ifndef USE_WINDOWS
difflklps = difflkl/(double)Maxsite;
#else
difflklps = difflkl/(double)alimaxsite;
#endif
sum = 0.0;
for (j = 0; j < Numptrn; j++) {
temp = allsitesc[besttree][j] - allsitesc[i][j] - difflklps;
sum += temp*temp*Weight[j];
}
#ifndef USE_WINDOWS
sum = sqrt(fabs(sum/(Maxsite-1.0)*Maxsite));
#else
sum = sqrt(fabs(sum/(alimaxsite-1.0)*alimaxsite));
#endif
# ifdef KHTWOSIDED
fprintf(ofp, "%11.2f ", sum);
if (difflkl > 1.96*sum)
fprintf(ofp, "yes ");
else
fprintf(ofp, "no ");
# else
fprintf(ofp, "%11.2f ", sum);
# endif
if (kh1_test_res[i] == 1)
fprintf(ofp, " %6.4f +", kh1_pval[i]);
else
fprintf(ofp, " %6.4f -", kh1_pval[i]);
if (sh_test_res[i] == 1)
fprintf(ofp, " %6.4f +", sh_pval[i]);
else
fprintf(ofp, " %6.4f -", sh_pval[i]);
if (elw_test_res[i] == 1)
fprintf(ofp, " %6.4f +", elw_support[i]);
else
fprintf(ofp, " %6.4f -", elw_support[i]);
# ifdef KHTWOSIDED
# else
if (difflkl > 1.96*sum)
fprintf(ofp, " -");
else
fprintf(ofp, " +");
# endif
}
fprintf(ofp, "\n");
}
fprintf(ofp, "\nThe columns show the results and p-values of the following tests:\n");
fprintf(ofp, "1sKH - one sided KH test based on pairwise SH tests (Shimodaira-Hasegawa\n");
fprintf(ofp, " 2000, Goldman et al., 2001, Kishino-Hasegawa 1989)\n");
fprintf(ofp, "SH - Shimodaira-Hasegawa test (2000)\n");
fprintf(ofp, "ELW - Expected Likelihood Weight (Strimmer-Rambaut 2002)\n");
fprintf(ofp, "2sKH - two sided Kishino-Hasegawa test (1989)\n");
fprintf(ofp, "\n");
fprintf(ofp, "Plus signs denote the confidence sets. Minus signs denote significant\n");
fprintf(ofp, "exclusion. All tests used 5%% significance level. 1sKH, SH, and ELW\n");
fprintf(ofp, "performed 1000 resamplings using the RELL method.\n");
fprintf(ofp, "1sKH and 2sKH are correct to the 2nd position after the the decimal\n");
fprintf(ofp, "point of the log-likelihoods.\n");
#if 0
fprintf(ofp, "\nColmn 5 gives the results of the (old) two-sided Kishino-Hasegawa test \n");
fprintf(ofp, "following Kishino and Hasegawa (1989). It tests whether a likelihood is \n");
fprintf(ofp, "significantly worse than the best one, marked with 'best'. This test should \n");
fprintf(ofp, "only be used for data not having been determined with the data tested on.\n");
fprintf(ofp, "1sKH is the one-sided KH test (Goldman et al., 2001). It is applicable\n");
fprintf(ofp, "to test whether likelihoods are worse than the lielihood of the ML tree.\n");
fprintf(ofp, "SH tests for the best trees (Shimodaira and Hasegawa, 2000).\n");
fprintf(ofp, "Note that KH, 1sKH, and SH assume to have the 'true' topologies among the tested.\n");
fprintf(ofp, "ELW (Expected likelihood weights) seems to work even without this restriction\n");
fprintf(ofp, "(Strimmer and Rambaut, 2002). Still plausible trees should be among the tested.\n");
fprintf(ofp, "For 1sKH, SH, and ELW plus signs '+' mark the topologies belonging to the\n");
fprintf(ofp, "confidence sets the numbers give the p-values (1sKH and SH) or the confidence\n");
fprintf(ofp, "weight (ELW).\n");
fprintf(ofp, "All tests used 5%% significance level. 1sKH, SH, and ELW used 1000 resamplings.\n");
#endif
}
} /* printtreestats */
/********************************************************/
|