X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fis.ultrametric.R;h=792684f000e1a8c1dcc3a9b358cb2996063129b0;hb=2653eb671caf9234635e44b895ef48b377a89a78;hp=76abc58503889c55cfff9ba951569826e9b671c1;hpb=fc029e0a1be9a5bd338c941b00842cfad95c0336;p=ape.git diff --git a/R/is.ultrametric.R b/R/is.ultrametric.R index 76abc58..792684f 100644 --- a/R/is.ultrametric.R +++ b/R/is.ultrametric.R @@ -1,30 +1,36 @@ -## is.ultrametric.R (2009-03-09) +## is.ultrametric.R (2012-02-09) ## Test if a Tree is Ultrametric -## Copyright 2003-2009 Emmanuel Paradis +## Copyright 2003-2012 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. is.ultrametric <- function(phy, tol = .Machine$double.eps^0.5) { - if (class(phy) != "phylo") - stop('object "phy" is not of class "phylo".') + if (!inherits(phy, "phylo")) + stop('object "phy" is not of class "phylo"') if (is.null(phy$edge.length)) - stop("the tree has no branch lengths.") + stop("the tree has no branch lengths") + phy <- reorder(phy) n <- length(phy$tip.label) - n.node <- phy$Nnode + e1 <- phy$edge[, 1] + e2 <- phy$edge[, 2] + EL <- phy$edge.length + + ## xx: vecteur donnant la distance d'un noeud + ## ou d'un tip à partir de la racine + xx <- numeric(n + phy$Nnode) - ## xx: vecteur donnant la distance d'un - ## noeud ou tip à partir de la racine - xx <- numeric(n + n.node) + ## the following must start at the root and follow the + ## edges contiguously; so the tree must be either in cladewise + ## order (or in pruningwise but the for loop must start from + ## the bottom of the edge matrix) - for (i in 1:dim(phy$edge)[1]) - xx[phy$edge[i, 2]] <- xx[phy$edge[i, 1]] + phy$edge.length[i] + for (i in seq_len(length(e1))) + xx[e2[i]] <- xx[e1[i]] + EL[i] - if (identical(all.equal.numeric(var(xx[1:n]), - 0, tolerance = tol), TRUE)) TRUE - else FALSE + isTRUE(all.equal.numeric(var(xx[1:n]), 0, tolerance = tol)) }