1 ## sh.test.R (2006-07-06)
3 ## Shimodaira-Hasegawa Test
5 ## Copyright 2006 Emmanuel Paradis
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
10 sh.test <- function(..., x, model = DNAmodel(), B = 100)
12 ## Prepare the list of trees:
14 if (length(phy) == 1 && class(phy[[1]]) != "phylo")
15 phy <- unlist(phy, recursive = FALSE)
18 ## Arrange the sequences as a matrix:
24 x <- matrix(x, n, nL/n, byrow = TRUE)
30 attr(mlphylo(model, x, PHY, search.tree = FALSE, quiet = TRUE), "loglik")
31 Talpha <- sapply(phy, foo)
32 Talpha <- max(Talpha) - Talpha
34 ## Do the bootstrap resampling (Step 2):
35 M <- matrix(NA, ntree, B)
37 boot.samp <- x[, sample(ncol(x), replace = TRUE)]
39 M[j, i] <- attr(mlphylo(model, boot.samp, phy[[j]],
40 search.tree = FALSE, quiet = TRUE),
43 M <- M - rowMeans(M) # Step 3
44 ## Step 4: <FIXME> This can greatly simplified </FIXME>
47 M[j, i] <- max(M[j, i] - M[, i])
49 count <- numeric(ntree)
51 count[j] <- sum(M[j, ] > Talpha[j])
53 names(count) <- names(phy)