1 ## is.ultrametric.R (2007-12-18)
3 ## Test if a Tree is Ultrametric
5 ## Copyright 2003-2007 Emmanuel Paradis
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
10 is.ultrametric <- function(phy, tol = .Machine$double.eps^0.5)
12 ### the tree must be in cladewise order
13 if (class(phy) != "phylo")
14 stop('object "phy" is not of class "phylo".')
15 if (is.null(phy$edge.length))
16 stop("the tree has no branch lengths.")
17 n <- length(phy$tip.label)
20 ## xx: vecteur donnant la distance d'un
21 ## noeud ou tip à partir de la racine
22 xx <- numeric(n + n.node)
24 for (i in 1:dim(phy$edge)[1])
25 xx[phy$edge[i, 2]] <- xx[phy$edge[i, 1]] + phy$edge.length[i]
27 if (identical(all.equal.numeric(var(xx[1:n]),
28 0, tolerance = tol), TRUE)) TRUE