]> git.donarmstrong.com Git - ape.git/blob - R/branching.times.R
some news for ape 3.0-8
[ape.git] / R / branching.times.R
1 ## branching.times.R (2009-05-10)
2
3 ##    Branching Times of a Phylogenetic Tree
4
5 ## Copyright 2002-2009 Emmanuel Paradis
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 branching.times <- function(phy)
11 {
12 ### the tree must be in cladewise order
13     if (!inherits(phy, "phylo"))
14       stop('object "phy" is not of class "phylo"')
15     n <- length(phy$tip.label)
16     N <- dim(phy$edge)[1]
17     xx <- numeric(phy$Nnode)
18     interns <- which(phy$edge[, 2] > n)
19     ## we loop only on the internal edges, this assumes
20     ## that `xx' is already set with 0
21     for (i in interns)
22       xx[phy$edge[i, 2] - n] <- xx[phy$edge[i, 1] - n] + phy$edge.length[i]
23     depth <- xx[phy$edge[N, 1] - n] + phy$edge.length[N]
24     xx <- depth - xx
25     names(xx) <-
26       if (is.null(phy$node.label)) (n + 1):(n + phy$Nnode) else phy$node.label
27     xx
28 }