Title: | Computation of Tree (Im)Balance Indices |
---|---|
Description: | The aim of the 'R' package 'treebalance' is to provide functions for the computation of a large variety of (im)balance indices for rooted trees. The package accompanies the book ''Tree balance indices: a comprehensive survey'' by M. Fischer, L. Herbst, S. Kersting, L. Kuehn and K. Wicke (2023) <ISBN: 978-3-031-39799-8>, <doi:10.1007/978-3-031-39800-1>, which gives a precise definition for the terms 'balance index' and 'imbalance index' (Chapter 4) and provides an overview of the terminology in this manual (Chapter 2). For further information on (im)balance indices, see also Fischer et al. (2021) <https://treebalance.wordpress.com>. Considering both established and new (im)balance indices, 'treebalance' provides (among others) functions for calculating the following 18 established indices and index families: the average leaf depth, the B1 and B2 index, the Colijn-Plazzotta rank, the normal, corrected, quadratic and equal weights Colless index, the family of Colless-like indices, the family of I-based indices, the Rogers J index, the Furnas rank, the rooted quartet index, the s-shape statistic, the Sackin index, the symmetry nodes index, the total cophenetic index and the variance of leaf depths. Additionally, we include 9 tree shape statistics that satisfy the definition of an (im)balance index but have not been thoroughly analyzed in terms of tree balance in the literature yet. These are: the total internal path length, the total path length, the average vertex depth, the maximum width, the modified maximum difference in widths, the maximum depth, the maximum width over maximum depth, the stairs1 and the stairs2 index. As input, most functions of 'treebalance' require a rooted (phylogenetic) tree in 'phylo' format (as introduced in 'ape' 1.9 in November 2006). 'phylo' is used to store (phylogenetic) trees with no vertices of out-degree one. For further information on the format we kindly refer the reader to E. Paradis (2012) <http://ape-package.ird.fr/misc/FormatTreeR_24Oct2012.pdf>. |
Authors: | Mareike Fischer [aut], Lina Herbst [aut], Sophie Kersting [aut], Luise Kuehn [aut, cre], Kristina Wicke [aut] |
Maintainer: | Luise Kuehn <[email protected]> |
License: | GPL-3 |
Version: | 1.2.0 |
Built: | 2024-12-09 06:32:31 UTC |
Source: | CRAN |
This function calculates the area per pair index for a given rooted
tree
. The tree must not necessarily be binary.
is defined as
in which denotes the
number of leaves in
, and
denotes the number of edges on the path between the two
leaves
and
. Note that
can also be
computed from the Sackin index
and the total cophenetic
index
of
as
enabling efficient computation.
The area per pair index does not fulfill the definition of an (im)balance
index given in "Tree balance indices: a comprehensive survey" (Fischer et al., 2023).
For details on the area per pair index, see
also Chapter 24 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_24).
areaPerPairI(tree)
areaPerPairI(tree)
tree |
A rooted tree in phylo format. |
areaPerPairI
returns the area per pair index of the given tree.
Luise Kuehn
T. Araujo Lima, F. M. D. Marquitti, and M. A. M. de Aguiar. Measuring Tree Balance with Normalized Tree Area. arXiv e-prints, art. arXiv:2008.12867, 2020.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") areaPerPairI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") areaPerPairI(tree)
This function calculates the average leaf depth for a given
rooted tree
. The tree must not necessarily be binary.
is
defined as
in which denotes the number of leaves in
,
denotes the set of inner nodes of
and
denotes the number of leaves in the pending subtree that is rooted
at the inner node
. Note that
can also be
computed from the Sackin index
as
.
The average leaf depth is an imbalance index.
For the function returns
and a warning.
For details on the average leaf depth, see also Chapter 6 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_6).
avgLeafDepI(tree)
avgLeafDepI(tree)
tree |
A rooted tree in phylo format. |
avgLeafDepI
returns the average leaf depth of the given tree.
Luise Kuehn
M. J. Sackin. "Good" and "Bad" Phenograms. Systematic Biology, 21(2):225-226, 1972. doi: 10.1093/sysbio/21.2.225.
K.-T. Shao and R. R. Sokal. Tree Balance. Systematic Zoology, 39(3):266, 1990.
doi: 10.2307/2992186.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") avgLeafDepI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") avgLeafDepI(tree)
This function calculates the average vertex depth for a given rooted
tree
. The tree must not necessarily be binary.
is defined as
in
which denotes the set of vertices of
, and
denotes the depth of the vertex
. The average vertex depth is a normalised version of the total path length and an
imbalance index.
For the function returns
and a warning.
For details on the average vertex depth, see
also Chapter 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_23).
avgVertDep(tree)
avgVertDep(tree)
tree |
A rooted tree in phylo format. |
avgVertDep
returns the average vertex depth of the given tree.
Luise Kuehn
A. Herrada et al. Scaling properties of protein family phylogenies. BMC Evolutionary Biology, 11(1), June 2011. doi: 10.1186/1471-2148-11-155.
tree <- ape::read.tree(text="((((,),),(,)),(((,,),),(,)));") avgVertDep(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,,),),(,)));") avgVertDep(tree)
This function calculates the index
for a given rooted
tree
. The tree must not necessarily be binary.
is defined as
in which
denotes the set of inner vertices of
without the root, and
denotes the height of the pending subtree rooted at
.
When restricted to binary trees, the
index is a balance index. For
arbitrary trees it does not fulfill the definition of an (im)balance index.
For the function returns
and a warning.
For details on the B1 index, see
also Chapter 10 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_10).
B1I(tree)
B1I(tree)
tree |
A rooted tree in phylo format. |
B1I
returns the B1 index of the given tree.
Sophie Kersting
K.-T. Shao and R. R. Sokal. Tree Balance. Systematic Zoology, 39(3):266, 1990.
doi: 10.2307/2992186.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") B1I(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") B1I(tree)
This function calculates the B2 index for a given rooted
tree
. The tree must not necessarily be binary.
is defined as
in which denotes the leaf
set of
, and in which
denotes
the probability of reaching leaf when starting at the root and assuming
equiprobable branching at each vertex
with
denoting the set of ancestors of
excluding
.
denotes the set of children of the inner vertex
.
The index is a balance index.
For the function returns
and a warning.
For details on the B2 index, see
also Chapter 11 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_11).
B2I(tree, logbase = 2)
B2I(tree, logbase = 2)
tree |
A rooted tree in phylo format. |
logbase |
The base that shall be used for the logarithm. For binary trees it is common to use base 2. |
B2I
returns the B2 index of the given tree.
Sophie Kersting, Luise Kuehn
K.-T. Shao and R. R. Sokal. Tree Balance. Systematic Zoology, 39(3):266, 1990.
doi: 10.2307/2992186.
P.-M. Agapow and A. Purvis. Power of Eight Tree Shape Statistics to Detect Nonrandom Diversification: A Comparison by Simulation of Two Models of Cladogenesis. Systematic Biology, 51(6):866-872, 2002.doi: 10.1080/10635150290102564.
URL https://doi.org/10.1080/10635150290102564.
M. Hayati, B. Shadgar, and L. Chindelevitch. A new resolution function to evaluate tree shape statistics. PLOS ONE, 14(11):e0224197, 2019. doi: 10.1371/journal.pone.0224197.
URL https://doi.org/10.1371/journal.pone.0224197.
M. Kirkpatrick and M. Slatkin. Searching for evolutionary patterns in the shape of a phylogenetic tree. Evolution, 47(4):1171-1181, 1993. doi: 10.1111/j.1558-5646.1993.tb02144.x.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") B2I(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") B2I(tree)
This function calculates the cherry index for a
given rooted tree
. The tree must not necessarily be binary.
is defined as the number of cherries in the tree. A cherry
is a pair of leaves that have the same direct ancestor. Note, if a vertex
has
leaves as direct descendants, the number of cherries induced by
is
.
The cherry index does not fulfill the definition
of an (im)balance index given in "Tree balance indices: a comprehensive survey"
(Fischer et al., 2023).
For details on the cherry index, see
also Chapter 24 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_24).
cherryI(tree)
cherryI(tree)
tree |
A rooted tree in phylo format. |
cherryI
returns the cherry index of the given tree.
Sophie Kersting
A. McKenzie and M. Steel. Distributions of cherries for two models of trees. Mathematical Biosciences, 164(1):81-92, 2000. doi: 10.1016/s0025-5564(99)00060-7.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") cherryI(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") cherryI(tree) tree <- ape::read.tree(text="((,,,),(,,));") cherryI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") cherryI(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") cherryI(tree) tree <- ape::read.tree(text="((,,,),(,,));") cherryI(tree)
This function calculates variants of the Colless index for a given rooted
binary tree . All of them are imbalance indices.
The original Colless index is defined as
in which denotes the set of all inner vertices
of
, and in which
and
denote the number of leaves in the two pending subtrees that are
rooted at the direct descendants of
.
The corrected Colless index of
is defined as
for
and
and for
as
in which denotes the
total number of leaves in
.
The quadratic Colless index of
is defined as
Special cases: For the function returns
and a warning.
For details on the original, corrected and quadratic Colless indices, see
also Chapters 12, 13 and 15 in "Tree balance indices: a comprehensive survey"
(https://doi.org/10.1007/978-3-031-39800-1_12, https://doi.org/10.1007/978-3-031-39800-1_13,
https://doi.org/10.1007/978-3-031-39800-1_15).
collessI(tree, method = "original")
collessI(tree, method = "original")
tree |
A rooted binary tree in phylo format. |
method |
A character string specifying the version that shall be computed. It can be one of the following: "original", "corrected", "quadratic". |
collessI
returns the Colless index of the given tree according to the chosen method.
Luise Kuehn and Sophie Kersting
D. Colless. Review of Phylogenetics: the theory and practice of phylogenetic systematics. Systematic Zoology, 1982. ISSN 00397989.
T. M. Coronado, M. Fischer, L. Herbst, F. Rossello, and K. Wicke. On the minimum value of the Colless index and the bifurcating trees that achieve it. Journal of Mathematical Biology, 2020.doi: 10.1007/s00285-020-01488-9.
S. B. Heard. Patterns in tree balance among cladistic, phenetic, and randomly generated phylogenetic trees. Evolution, 1992. doi: 10.1111/j.1558-5646.1992.tb01171.x.
K. Bartoszek, T. M. Coronado, A. Mir, and F. Rossello. Squaring within the Colless index yields a better balance index. Mathematical Biosciences, 331:108503, 2021. doi: 10.1016/j.mbs.2020.108503.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") collessI(tree, method="original") collessI(tree, method="corrected") collessI(tree, method="quadratic")
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") collessI(tree, method="original") collessI(tree, method="corrected") collessI(tree, method="quadratic")
This function calculates the Colless-like index for a given rooted
tree according to the chosen weight function
and dissimilarity
.
The Colless-like index
relative to
and
is the sum of the
-balance values
over all inner vertices of the tree. More precisely,
where is the
set of inner vertices of
. The
-balance value
of
with children
is computed as
with denoting the dissimilarity and
denoting the f.size.
The f.size of a tree
uses the function
, which maps any
integer to a non-negative real number, to build a weighted sum of
the out-degrees of all vertices in
. More precisely,
where is the set of all
vertices of
and
denotes the out-degree (i.e. the number of
children) of the vertex
. The
-functions that are already
implemented are
and
.
The dissimilarity of a vector
assigns
a non-negative value to the vector, is independent of the order of the vector
entries and equals zero if and only if
. In this
implementation the following dissimilarity functions are already built-in:
mean deviation from the median (
),
the sample variance (
) and the sample standard deviation (
).
collesslikeI
also allows the use of other functions for the weight function
and the dissimilarity
.
Special cases: For the function returns
and a warning.
For details on the family of Colless-like indices, see
also Chapter 16 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_16).
collesslikeI(tree, f.size, dissim)
collesslikeI(tree, f.size, dissim)
tree |
A rooted binary tree in phylo format. |
f.size |
A character string specifying the function |
dissim |
A character string specifying the dissimilarity that shall be used. It can be one of the following: "mdm", "var", "sd" or the name of a function as a string. |
collesslikeI
returns the Colless-like index of the given tree according to the chosen
function and dissimilarity.
Luise Kuehn, Sophie Kersting
A. Mir, L. Rotger, and F. Rossello. Sound Colless-like balance indices for multifurcating trees. PLOSONE, 13(9):e0203401, 2018. doi: 10.1371/journal.pone.0203401
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") collesslikeI(tree, f.size="exp", dissim="mdm") collesslikeI(tree, f.size="exp", dissim="var") collesslikeI(tree, f.size="ln", dissim="sd") myfsize <- function(x) return(x+1) mydissim <- function(x) return (var(x)) collesslikeI(tree, f.size="myfsize",dissim = "mydissim")
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") collesslikeI(tree, f.size="exp", dissim="mdm") collesslikeI(tree, f.size="exp", dissim="var") collesslikeI(tree, f.size="ln", dissim="sd") myfsize <- function(x) return(x+1) mydissim <- function(x) return (var(x)) collesslikeI(tree, f.size="myfsize",dissim = "mydissim")
This function calculates the Colijn-Plazzotta rank for a
given rooted binary tree
.
For a binary tree , the Colijn-Plazzotta rank
is
recursively defined as
if
consists of only
one leaf and otherwise
with being the ranks of the two pending
subtrees rooted at the children of the root of
. This rank
of
corresponds to its position in the
lexicographically sorted list of (
): (1),(1,1),(2,1),(2,2),(3,1),...
The Colijn-Plazzotta rank of binary trees has been shown to be an imbalance index.
For the function returns
and a warning.
Note that problems can sometimes arise even for trees with small leaf numbers due
to the limited range of computable values (ranks can reach INF quickly).
For details on the Colijn-Plazzotta rank, see
also Chapter 21 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_21).
colPlaLab(tree)
colPlaLab(tree)
tree |
A rooted binary tree in phylo format. |
colPlaLab
returns the Colijn-Plazotta rank of the given tree. Since the values can get quite large, the
function returns them in big.z format (package gmp).
Sophie Kersting, Luise Kuehn
C. Colijn and G. Plazzotta. A Metric on Phylogenetic Tree Shapes. Systematic Biology, doi: 10.1093/sysbio/syx046.
N. A. Rosenberg. On the Colijn-Plazzotta numbering scheme for unlabeled binary rooted trees. Discrete Applied Mathematics, 2021. doi: 10.1016/j.dam.2020.11.021.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") colPlaLab(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") colPlaLab(tree)
This function generates the unique rooted binary tree (in phylo
format) that corresponds to the given Colijn-Plazzotta rank
. It
is the inverse function of colPlaLab().
colPlaLab()
:
For a given rooted binary tree ,
is recursively defined as
if
consists of only one vertex and otherwise
with
being the
ranks of the two pending subtrees rooted at the children of the root of
.
The rank
of
corresponds to its position in the
lexicographically sorted list of (
): (1),(1,1),(2,1),(2,2),(3,1),...
colPlaLab_inv()
:
For a given rank the corresponding tree
can be reconstructed
by starting from one vertex
(labelled
) and recursively
splitting vertices whose labels
are greater than 1 into two children with the labels:
and
until there are no more vertices to split.
For the function returns the smallest possible tree in the
phylo format: the tree consisting of a single edge.
Note that problems can arise for extremely high input values (>10e+18).
For details on the Colijn-Plazzotta rank, see
also Chapter 21 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_21).
colPlaLab_inv(rank)
colPlaLab_inv(rank)
rank |
An integer denoting the Colijn-Plazzotta rank of the sought tree. |
colPlaLab_inv
returns the unique rooted binary tree for the given rank.
Sophie Kersting
C. Colijn and G. Plazzotta. A Metric on Phylogenetic Tree Shapes. Systematic Biology, 67(1):113-126,2018. doi: 10.1093/sysbio/syx046.
N. A. Rosenberg. On the Colijn-Plazzotta numbering scheme for unlabeled binary rooted trees. Discrete Applied Mathematics, 291:88-98, 2021. doi: 10.1016/j.dam.2020.11.021.
colPlaLab_inv(22)
colPlaLab_inv(22)
This function calculates the equal weights Colless index for a
given rooted binary tree
.
is defined as
in which denotes the set of all inner vertices of
,
and in which
,
and
denote the number of
leaves in the pending subtrees that are rooted at
and the two direct
descendants of
. The equal weights Colless index is an imbalance index.
For and
the function returns
and a warning.
For details on the equal weigths Colless index, see
also Chapter 14 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_14).
ewCollessI(tree)
ewCollessI(tree)
tree |
A rooted binary tree in phylo format. |
ewCollessI
returns the equal weights Colless index of the given tree.
Luise Kuehn
A. O. Mooers and S. B. Heard. Inferring Evolutionary Process from Phylogenetic Tree Shape. The Quarterly Review of Biology, 72(1), 1997. doi: 10.1086/419657.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") ewCollessI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") ewCollessI(tree)
This function calculates the Furnas rank for a given rooted
binary tree
.
is the unique rank of the tree
among all rooted binary trees with
leaves in the left-light rooted
ordering. For details on the left-light rooted ordering as well as details
on how the Furnas rank is computed, see "The generation
of random, binary unordered trees" by G.W. Furnas (1984) or "Tree balance
indices: a comprehensive survey" by Fischer et al. (2023). The Furnas rank
is a balance index.
The concept of assigning each rooted binary tree a unique tuple
allows to store many trees with minimal storage use.
For details on the Furnas rank, see
also Chapter 22 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_22).
furnasI(tree)
furnasI(tree)
tree |
A rooted binary tree in phylo format. |
furnasI
returns the unique Furnas rank of the given tree, i.e.
the rank of the tree among all rooted binary trees with leaves in the
left-light rooted ordering. Since the values can get quite large, the function
returns them in
format (package
).
Luise Kuehn, Lina Herbst
G. W. Furnas. The generation of random, binary unordered trees. Journal of Classification, 1984. doi: 10.1007/bf01890123. URL https://doi.org/10.1007/bf01890123.
M. Kirkpatrick and M. Slatkin. Searching for evolutionary patterns in the shape of a phylogenetic tree. Evolution, 1993. doi: 10.1111/j.1558-5646.1993.tb02144.x.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") furnasI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") furnasI(tree)
This function calculates the unique tree (in phylo format) for two
given integer values
and
, with
denoting the number
of leaves of
and
denoting the rank of
in the
left-light rooted ordering of all rooted binary trees with
leaves.
It is the inverse function of
furnasI()
. For details on how to calculate
(including algorithm) see "The generation of random, binary
unordered trees" by G.W. Furnas (1984) or "Tree balance indices: a comprehensive
survey" by Fischer et al. (2023).
furnasI_inv
can be used e.g. to generate random rooted binary trees with a
certain number of leaves. Also, the concept of assigning each rooted binary
tree a unique tuple allows to store many trees with minimal
storage use.
For details on the Furnas rank, see
also Chapter 22 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_22).
furnasI_inv(rank, n)
furnasI_inv(rank, n)
rank |
An integer denoting the rank of the sought tree among all rooted
binary trees with |
n |
An integer denoting the number of leaves of the sought tree. |
furnasI_inv
returns the unique tree (in phylo format) for
the given leaf number and rank.
Sophie Kersting
G. W. Furnas. The generation of random, binary unordered trees. Journal of Classification, 1984. doi: 10.1007/bf01890123. URL https://doi.org/10.1007/bf01890123.
furnasI_inv(rank=6,n=8)
furnasI_inv(rank=6,n=8)
getDescMatrix
- Creates a matrix that contains the descendants of
node in row
.
getAncVec
- Creates a vector that contains the parent (direct ancestor) of
node at position
.
getNodesOfDepth
- Creates a matrix that contains the nodes of
depth in row
.
symBucketLexicoSort
- Sorts the pairs of numbers lexicographically and
returns ranking. Uses bucket sort.
getAllAncestors
- Returns all ancestors of including
itself.
cPL_inv
- Returns the binary tree that belongs to the input label in an incomplete
Newick format.
maxDepthLeaf
- Returns the maximumy< depth of a leaf in the subtree that
is rooted at .
get.subtreesize
- Creates a vector that contains at the -th position
the number of leaves in the pending subtree rooted at
.
getlca
- Returns the name of the lowest common ancestor of the two
input vertices and
.
we_eth
- Returns the Wedderburn-Etherington number
for a given non-negative integer
.
getfurranks
- Returns for each vertex the Furnas rank of the
subtree rooted at
.
getsubtree
- Returns the pending subtree (in phylo format) that is
rooted at the input vertex. If the input vertex is a leaf, the function returns
the standard tree for (with 1 edge).
is_binary
- Returns TRUE if the input tree is binary and FALSE otherwise.
is_phylo
- Tests all requirements of the phylo format, and returns TRUE
if the tree is correctly formatted, else FALSE with detailed feedback on the
features that are not met.
tree_decomposition
- Returns a list of length two, which
contains the two pending subtrees that are rooted at the children of the root
of the input tree. The
smaller one (according to the number of leaves) is stated first.
tree_merge
- Returns a rooted tree in phylo
format, which contains the input trees
and
as
"left" and "right" maximal pending subtrees.
treenumber
- Returns the unique tree number of the given tree.
is the rank of the tree
among all
rooted binary trees in the left-light rooted ordering. It can
be calculated as follows:
in which is the number of leaves in
,
is the Furnas
rank of
, i.e. the rank of
in the left-light rooted ordering
of all rooted binary trees with
leaves, and
is the
Wedderburn-Etherington number of
.
The concept of assigning each rooted binary tree a unique tree number allows
to store many trees with minimal storage use.
For
the function returns
and a warning.
treenumber_inv
- Returns the unique tree (in phylo format) for
the given tree number.
auxE_l_X
- Returns the sum of all products of l different values in X.
getDescMatrix(tree) getAncVec(tree) getNodesOfDepth(mat, root, n) symBucketLexicoSort(workLabs) getAllAncestors(tree, v) cPL_inv(label) maxDepthLeaf(tree, v = length(tree$tip.label) + 1) get.subtreesize(tree) getlca(tree, v, w) we_eth(n) getfurranks(tree) getsubtree(tree, subroot) is_binary(tree) is_phylo(tree) tree_decomposition(tree) tree_merge(tree1, tree2) treenumber(tree) treenumber_inv(treenum) auxE_l_X(subX, Xset)
getDescMatrix(tree) getAncVec(tree) getNodesOfDepth(mat, root, n) symBucketLexicoSort(workLabs) getAllAncestors(tree, v) cPL_inv(label) maxDepthLeaf(tree, v = length(tree$tip.label) + 1) get.subtreesize(tree) getlca(tree, v, w) we_eth(n) getfurranks(tree) getsubtree(tree, subroot) is_binary(tree) is_phylo(tree) tree_decomposition(tree) tree_merge(tree1, tree2) treenumber(tree) treenumber_inv(treenum) auxE_l_X(subX, Xset)
tree |
A rooted tree in phylo format, >= 2 leaves |
mat |
Descendants matrix from |
root |
Number (label) of the root of the tree |
n |
Number of leaves of the tree |
workLabs |
numeric matrix (2 columns) |
v |
A vertex of the tree. |
label |
A Colijn-Plazotta label of desired tree, a positive integer. |
w |
A vertex of the tree. |
subroot |
A vertex of the tree. It is not recommended to use leaves as subroots. |
tree1 |
A rooted tree in phylo format. |
tree2 |
A rooted tree in phylo format. |
treenum |
An integer denoting the tree number of the sought tree. |
subX |
integer >=1, size of the subsets of X. |
Xset |
Vector (multiset) of numeric values. |
desc_mat
numeric matrix
anc_vec
numeric vector
nodes_of_depth
numeric matrix
ranking
numeric vector
vectorWithAncs
numeric vector
Sophie Kersting, Luise Kuehn and Lina Herbst
mat <- cbind(c(7,7,6,5,5,6),c(1,2,3,4,6,7)) tree <- list(edge=mat, tip.label=c("","","",""), Nnode=3) getDescMatrix(tree) mat <- cbind(c(5,5,5,5),c(1,2,3,4)) tree <- list(edge=mat, tip.label=c("","","",""), Nnode=1) getDescMatrix(tree) getAncVec(tree) getNodesOfDepth(mat=getDescMatrix(tree),root=length(tree$tip.label)+1, n=length(tree$tip.label)) myWorkLabs <- cbind(c(0,1,2,3,1,0),c(0,2,2,4,1,0)) symBucketLexicoSort(myWorkLabs) getAllAncestors(tree,v=6) cPL_inv(label=6) maxDepthLeaf(tree,v=6) get.subtreesize(tree) getlca(tree,1,2) we_eth(5) getfurranks(tree) getsubtree(tree,4) is_binary(ape::read.tree(text="((((,),),(,)),(((,),),(,)));")) is_phylo(ape::read.tree(text="((((,),),(,)),(((,),),(,)));")) tree_decomposition(ape::read.tree(text="((((,),),(,)),(((,),),(,)));")) treeA <- ape::read.tree(text="(((,),),(,));") treeB <- ape::read.tree(text="((,),);") tree_merge(treeA, treeB) treenumber(ape::read.tree(text="((((,),),(,)),(((,),),(,)));")) treenumber_inv(192) auxE_l_X(subX=3,Xset=c(1,1,2,2))
mat <- cbind(c(7,7,6,5,5,6),c(1,2,3,4,6,7)) tree <- list(edge=mat, tip.label=c("","","",""), Nnode=3) getDescMatrix(tree) mat <- cbind(c(5,5,5,5),c(1,2,3,4)) tree <- list(edge=mat, tip.label=c("","","",""), Nnode=1) getDescMatrix(tree) getAncVec(tree) getNodesOfDepth(mat=getDescMatrix(tree),root=length(tree$tip.label)+1, n=length(tree$tip.label)) myWorkLabs <- cbind(c(0,1,2,3,1,0),c(0,2,2,4,1,0)) symBucketLexicoSort(myWorkLabs) getAllAncestors(tree,v=6) cPL_inv(label=6) maxDepthLeaf(tree,v=6) get.subtreesize(tree) getlca(tree,1,2) we_eth(5) getfurranks(tree) getsubtree(tree,4) is_binary(ape::read.tree(text="((((,),),(,)),(((,),),(,)));")) is_phylo(ape::read.tree(text="((((,),),(,)),(((,),),(,)));")) tree_decomposition(ape::read.tree(text="((((,),),(,)),(((,),),(,)));")) treeA <- ape::read.tree(text="(((,),),(,));") treeB <- ape::read.tree(text="((,),);") tree_merge(treeA, treeB) treenumber(ape::read.tree(text="((((,),),(,)),(((,),),(,)));")) treenumber_inv(192) auxE_l_X(subX=3,Xset=c(1,1,2,2))
This function calculates -based indices
for a given rooted
tree
. Note that the leaves of the tree may represent single species or
groups of more than one species. Thus, a vector is required that contains for
each leaf the number of species that it represents.
The tree may contain few polytomies, which are not allowed to concentrate in
a particular region of the tree (see p. 238 in Fusco and Cronk (1995)).
Let be a vertex of
that fulfills the following criteria: a)
The number of descendant (terminal) species of
is
(note that if each leaf represents only one species
is simply the
number of leaves in the pending subtree rooted at
), and
b)
has exactly two children.
Then, we can calculate the value as follows:
in which denotes the number of descendant (terminal) species
in the bigger one of the two pending subtrees rooted at
.
As the expected value of under the Yule model depends on
,
Purvis et al. (2002) suggested to take the corrected values
or
instead.
The value of
is defined as follows:
if
is odd and
if
is even.
The value of
is defined as follows:
where is the set of inner vertices of
that have precisely
two children and
, and
is a weight function with
if
is odd and
if
is even and
, and
if
is even and
.
The -based index of
can now be calculated using different methods.
Here, we only state the version for the
correction method, but the non-corrected
version or the
corrected version works analoguously.
1) root: The
index of
equals the
value of the root of
, i.e.
, provided that the root fulfills the two
criteria. Note that this method does not fulfil the definition of an (im)balance index.
2) median: The
index of
equals the median
value of all
vertices
that fulfill the two criteria.
3) total: The
index of
equals the summarised
values of all
vertices
that fulfill the two criteria.
4) mean: The
index of
equals the mean
value of all
vertices
that fulfill the two criteria.
5) quartile deviation: The
index of
equals the quartile
deviation (half the difference between third and first quartile) of the
values of all
vertices
that fulfill the two criteria.
For details on the family of I-based indices, see
also Chapter 17 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_17).
IbasedI( tree, specnum = rep(1, length(tree$tip.label)), method = "mean", correction = "none", logs = TRUE )
IbasedI( tree, specnum = rep(1, length(tree$tip.label)), method = "mean", correction = "none", logs = TRUE )
tree |
A rooted tree in phylo format (with possibly few polytomies). |
specnum |
A vector whose |
method |
A character string specifying the method that shall be used to
calculate |
correction |
A character string specifying the correction method that shall be applied to the I values. It can be one of the following: "none", "prime", "w". |
logs |
Boolean value, (default true), determines if the number of suitable nodes (i.e. nodes that fulfill the criteria) and polytomies in the tree should be printed. |
IbasedI
returns an -based balance index of the given tree according to the chosen (correction and) method.
Luise Kuehn and Sophie Kersting
G. Fusco and Q. C. Cronk. A new method for evaluating the shape of large phylogenies. Journal of Theoretical Biology, 1995. doi: 10.1006/jtbi.1995.0136. URL https://doi.org/10.1006/jtbi.1995.0136.
A. Purvis, A. Katzourakis, and P.-M. Agapow. Evaluating Phylogenetic Tree Shape: Two Modifications to Fusco & Cronks Method. Journal of Theoretical Biology, 2002. doi: 10.1006/jtbi.2001.2443. URL https://doi.org/10.1006/jtbi.2001.2443.
tree <- ape::read.tree(text="(((((,),),),),);") IbasedI(tree, method="mean") IbasedI(tree, method="mean", correction="prime", specnum=c(1,1,2,1,1,1))
tree <- ape::read.tree(text="(((((,),),),),);") IbasedI(tree, method="mean") IbasedI(tree, method="mean", correction="prime", specnum=c(1,1,2,1,1,1))
This function calculates the maximum difference in widths and
the modified maximum difference in width
for a
given rooted tree
. The tree must not necessarily be binary.
is defined as
and is defined as
in which denotes the height of the tree
and
denotes
the number of vertices in
that have depth
. The modified maximum difference
in widths is a balance index, while the maximum difference in widths is neither a balance nor imbalance index.
Note that there was a spelling error in the previous manual of this function - we wrote "maximum difference in widths"
while the given definition and the R code corresponded to the "modified maximum difference in width".
For details on the maximum difference in widths and the modified maximum difference in widths, see
also Chapters 24 and 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_24, https://doi.org/10.1007/978-3-031-39800-1_23).
maxDelW(tree, method = "modified")
maxDelW(tree, method = "modified")
tree |
A rooted tree in phylo format. |
method |
A character string specifying whether the original maximum difference in widths or the modified maximum difference in widths shall be computed. Can be any of "original" or "modified" (default is modified). |
maxDelW
returns the maximum difference in widths of a tree (if method
is set to original
)
or the modified maximum difference in widths (if method
is set to modified
).
Sophie Kersting, Luise Kuehn
C. Colijn, J. Gardy. Phylogenetic tree shapes resolve disease transmission patterns. Evolution, Medicine, and Public Health, 2014(1):96-108, 2014. ISSN 2050-6201. doi: 10.1093/emph/eou018.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") maxDelW(tree, method="original") tree <- ape::read.tree(text="((,),((((,),),),(,)));") maxDelW(tree, method="modified")
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") maxDelW(tree, method="original") tree <- ape::read.tree(text="((,),((((,),),),(,)));") maxDelW(tree, method="modified")
This function calculates the maximum depth of any vertex in a rooted tree , which
is at the same time its height
. The tree must not necessarily be binary. Formally,
is defined as
with being the depth of the vertex
.
The maximum depth is an imbalance index.
For the function returns
and a warning.
For details on the maximum depth, see
also Chapter 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_23).
maxDepth(tree)
maxDepth(tree)
tree |
A rooted tree in phylo format. |
maxDepth
returns the maximum depth, i.e. height, of a tree.
Luise Kuehn, Sophie Kersting
C. Colijn and J. Gardy. Phylogenetic tree shapes resolve disease transmission patterns. Evolution, Medicine, and Public Health, 2014(1):96-108, 2014. ISSN 2050-6201. doi: 10.1093/emph/eou018.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") maxDepth(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") maxDepth(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") maxDepth(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") maxDepth(tree)
This function calculates the maximum width for a
given rooted tree
. The tree must not necessarily be binary.
is defined as
in which denotes the height of the tree
and
denotes
the number of vertices in
that have depth
. The maximum width
is a balance index.
For details on the maximum width, see
also Chapter 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_23).
maxWidth(tree)
maxWidth(tree)
tree |
A rooted tree in phylo format. |
maxWidth
returns the maximum width of a tree.
Sophie Kersting
C. Colijn and J. Gardy. Phylogenetic tree shapes resolve disease transmission patterns. Evolution, Medicine, and Public Health, 2014(1):96-108, 2014. ISSN 2050-6201. doi: 10.1093/emph/eou018.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") maxWidth(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") maxWidth(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") maxWidth(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") maxWidth(tree)
This function calculates the modified cherry index for a
given rooted binary tree
. Note that compared to the original cherry index
,
the modified cherry index is defined for binary trees only.
is defined as
, i.e. it counts the
number of leaves of the tree which are not in a cherry. A cherry
is a pair of leaves that have the same direct ancestor.
The modified cherry index does not fulfill the definition
of an (im)balance index given in "Tree balance indices: a comprehensive survey"
(Fischer et al., 2023).
For details on the modified cherry index, see
also Chapter 24 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_24).
mCherryI(tree)
mCherryI(tree)
tree |
A rooted binary tree in phylo format. |
mCherryI
returns the modified cherry index of the given tree.
Luise Kuehn
S. J. Kersting, M. Fischer. Measuring tree balance using symmetry nodes — A new balance index and its extremal properties. Mathematical Biosciences, 341:108690, 2021. doi: 10.1016/j.mbs.2021.108690.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") mCherryI(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") mCherryI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") mCherryI(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") mCherryI(tree)
This function calculates the maximum width over maximum depth for a
given rooted tree
. The tree must not necessarily be binary. For
,
is defined as
in which denotes the height of the tree
, which is the same as the
maximum depth of any leaf in the tree, and
denotes
the maximum width of the tree
. The maximum width over maximum depth
is a balance index.
For details on the maximum width over maximum depth, see
also Chapter 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_23).
mWovermD(tree)
mWovermD(tree)
tree |
A rooted tree in phylo format. |
mWovermD
returns the maximum width over maximum depth of a tree.
Luise Kuehn
C. Colijn and J. Gardy. Phylogenetic tree shapes resolve disease transmission patterns. Evolution, Medicine, and Public Health, 2014(1):96–108, 2014. doi: 10.1093/emph/eou018.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") mWovermD(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") mWovermD(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") mWovermD(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") mWovermD(tree)
This function calculates the Rogers J index for a given rooted
binary tree
. It is defined as the number of inner vertices whose balance
value is unequal to zero, more precisely
in which denotes the set of all inner vertices
of
, and in which
and
denote the number of leaves in the two pending subtrees that are
rooted at the direct descendants of
.
Special cases: For , the function returns
and a warning.
For details on the Rogers J index, see
also Chapter 19 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_19).
rogersI(tree)
rogersI(tree)
tree |
A rooted binary tree in phylo format. |
rogersI
returns the Rogers J index of the given tree.
Sophie Kersting
J. S. Rogers. Central Moments and Probability Distributions of Three Measures of Phylogenetic Tree Imbalance. Systematic Biology, 45(1):99-110, 1996. doi: 10.1093/sysbio/45.1.99.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") rogersI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") rogersI(tree)
This function calculates the rooted quartet index for a given
rooted tree
. The tree must not necessarily be binary.
Let be a rooted tree, whose leaves are
. Let
denote the set of all subsets of
that have
cardinality 4. Let
denote the rooted quartet on
that is obtained by taking the subgraph of
that is induced by
and supressing its outdegree-1 vertices.
can have one of
the five following shapes:
- : This is the caterpillar tree shape on 4 leaves, i.e.
"(,(,(,)));"
in Newick format. It has 2 automorphisms.
- : This is the tree shape on 4 leaves that has three pending
subtrees rooted at the children of the root of
, one of them being
a cherry and the other two
being single vertices, i.e.
"((,),,);"
in Newick format. It has 4
automorphisms.
- : This is the tree shape on 4 leaves that has two pending
subtrees rooted at the children of the root of
, one of them being
a star tree shape on 3 leaves
and the other one being a single vertex, i.e.
"((,,),);"
in Newick
format. It has 6 automorphisms.
- : This is the fully balanced binary tree shape on 4 leaves,
i.e.
"((,),(,));"
in Newick format. It has 8 automorphisms.
- : This is the star tree shape on 4 leaves, i.e.
"(,,,);"
in Newick format. It has 24 automorphisms. is assigned an rQI-value based on its shape, i.e.
if
has the shape
. The values
are
chosen in such a way that they increase with the symmetry of the shape as
measured by means of its number of automorphisms. Coronado et al. (2019)
suggested the values
and
or
for
.
The rooted quartet index of the tree
is then defined as
the sum of the rQI-values of its rooted quartets:
The rooted quartet index is a balance index.
For details on the rooted quartet index, see
also Chapter 20 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_20).
rQuartetI(tree, shapeVal = c(0, 1, 2, 3, 4))
rQuartetI(tree, shapeVal = c(0, 1, 2, 3, 4))
tree |
A rooted tree in phylo format. |
shapeVal |
A vector of length 5 containing the shape values |
rQuartetI
returns the rooted quartet index of the given tree based on the chosen shape values (see description for details).
Sophie Kersting
T. M. Coronado, A. Mir, F. Rossello, and G. Valiente. A balance index for phylogenetic trees based on rooted quartets. Journal of Mathematical Biology, 79(3):1105-1148, 2019. doi: 10.1007/s00285-019-01377-w. URL https://doi.org/10.1007/s00285-019-01377-w.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") rQuartetI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") rQuartetI(tree)
This function calculates the Sackin index for a given rooted
tree
. The tree must not necessarily be binary.
is defined as
in
which denotes the leaf set of
,
denotes the depth of the leaf
,
denotes the set of
inner vertices in
, and
denotes the number of leaves
in the pending subtree that is rooted at
. The Sackin index is an
imbalance index.
For the function returns
and a warning.
For details on the Sackin index, see
also Chapter 5 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_5).
sackinI(tree)
sackinI(tree)
tree |
A rooted tree in phylo format. |
sackinI
returns the Sackin index of the given tree.
Luise Kuehn
M.J. Sackin. "Good" and "Bad" Phenograms. Systematic Biology, 21(2):225-226, 1972. doi: 10.1093/sysbio/21.2.225.
K.-T. Shao and R.R. Sokal. Tree Balance. Systematic Zoology, 39(3):266, 1990. doi: 10.2307/2992186.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") sackinI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") sackinI(tree)
This function calculates the s-shape statistic for a given rooted
tree
. The tree must not necessarily be binary, however
only fulfils
the definition of an imbalance index on the space of binary trees.
is defined as
in
which denotes the set of inner vertices of
and
denotes the number of leaves
in the pending subtree that is rooted at
. An arbitrary logarithm base can be used
(for binary trees it is common to use base 2).
For the function returns
and a warning.
For details on the s-shape statistic, see
also Chapter 9 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_9).
sShapeI(tree, logbase = 2)
sShapeI(tree, logbase = 2)
tree |
A rooted tree in phylo format. |
logbase |
The logarithm base that shall be used. |
sShapeI
returns the s-shape statistic of the given tree.
Luise Kuehn
M.G. Blum and O. Francois. Which random processes describe the tree of life? a large-scale study of phylogenetic tree imbalance. Systematic Biology, 2006.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") sShapeI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") sShapeI(tree)
This function calculates the stairs1 value for a given rooted
binary tree
. It is a modified version of the Rogers J index and is
defined as the fraction of inner vertices whose balance
value is unequal to zero, more precisely
in which denotes the set of all inner vertices
of
, and in which
and
denote the number of leaves in the two pending subtrees that are
rooted at the direct descendants of
. The stairs1 value is an imbalance index.
Special cases: For , the function returns
and a warning.
For details on the stairs1 value, see
also Chapter 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_23).
stairs1(tree)
stairs1(tree)
tree |
A rooted binary tree in phylo format. |
stairs1
returns the stairs1 value of the given tree.
Sophie Kersting
M. M. Norstrom, M. C. Prosperi, R. R. Gray, A. C. Karlsson, and M. Salemi. PhyloTempo: A Set of R Scripts for Assessing and Visualizing Temporal Clustering in Genealogies Inferred from Serially Sampled Viral Sequences. Evolutionary Bioinformatics, 8:EBO.S9738, 2012. ISSN 1176-9343, 1176-9343. doi:10.4137/EBO.S9738.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") stairs1(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") stairs1(tree)
This function calculates the stairs2 value for a given rooted
binary tree
. It is defined as the mean ratio between the leaf
numbers of the smaller and larger pending subtree over all inner vertices, more precisely
in which denotes the set of all inner vertices
of
, and in which
denote the number of leaves
in the two pending subtrees that are
rooted at the direct descendants of
. The stairs2 value is an imbalance index.
Special cases: For , the function returns
and a warning.
For details on the stairs2 value, see
also Chapter 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_23).
stairs2(tree)
stairs2(tree)
tree |
A rooted binary tree in phylo format. |
stairs2
returns the stairs2 value of the given tree.
Sophie Kersting
C. Colijn, J. Gardy. Phylogenetic tree shapes resolve disease transmission patterns. Evolution, Medicine, and Public Health, 2014(1):96-108, 2014. ISSN 2050-6201. doi: 10.1093/emph/eou018.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") stairs2(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") stairs2(tree)
This function calculates the symmetry nodes index for a given rooted
binary tree
.
is defined as the number of inner vertices
that are not
symmetry nodes, i.e. the two pending subtrees rooted at the children of
do not
have the same tree shape.
For the function returns
and a warning.
For details on the symmetry nodes index, see
also Chapter 18 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_18).
symNodesI(tree)
symNodesI(tree)
tree |
A rooted binary tree in phylo format. |
symNodesI
returns the symmetry nodes index of the given tree.
Sophie Kersting
S. J. Kersting, M. Fischer. Measuring tree balance using symmetry nodes — A new balance index and its extremal properties. Mathematical Biosciences, page 108690, 2021. ISSN 0025-5564. doi:https://doi.org/10.1016/j.mbs.2021.108690
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") symNodesI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") symNodesI(tree)
This function calculates the total cophenetic index of a given
rooted tree
. The tree must not necessarily be binary.
is defined as
in which denotes the depth of the lowest
common ancestor of the two leaves
and
and
denotes the set of all inner vertices exept the root and
denotes the
number of descendant leaves of
. The second formula is useful for efficient
computation of
. The total cophenetic index is an imbalance index.
For the function returns
.
For details on the total cophenetic index, see
also Chapter 8 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_8).
totCophI(tree)
totCophI(tree)
tree |
A rooted tree in phylo format. |
totCophI
returns the total cophenetic index of the given tree.
Sophie Kersting
A. Mir, F. Rossello, and L. Rotger. A new balance index for phylogenetic trees. Mathematical Bio-sciences, 241(1):125-136, 2013. doi: 10.1016/j.mbs.2012.10.005.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") totCophI(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") totCophI(tree) tree <- ape::read.tree(text="((,,,),(,,));") totCophI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") totCophI(tree) tree <- ape::read.tree(text="((,),((((,),),),(,)));") totCophI(tree) tree <- ape::read.tree(text="((,,,),(,,));") totCophI(tree)
This function calculates the total internal path length for a given rooted
tree
. The tree must not necessarily be binary.
is defined as
in
which denotes the set of inner vertices of
, and
denotes the depth of the vertex
. The total internal path length is an
imbalance index.
For details on the total internal path length, see
also Chapter 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_23).
totIntPathLen(tree)
totIntPathLen(tree)
tree |
A rooted tree in phylo format. |
totIntPathLen
returns the total internal path length of the given tree.
Luise Kuehn
D. E. Knuth. The art of computer programming: fundamental algorithms, volume 1. Addison-Wesley, Reading, Mass, 3rd edition, 1997. ISBN 9780201896831.
tree <- ape::read.tree(text="((((,),),(,)),(((,,),),(,)));") totIntPathLen(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,,),),(,)));") totIntPathLen(tree)
This function calculates the total path length for a given rooted
tree
. The tree must not necessarily be binary.
is defined as
in
which denotes the set of vertices of
, and
denotes the depth of the vertex
. The total path length is an
imbalance index.
For the function returns
and a warning.
For details on the total path length, see
also Chapter 23 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_23).
totPathLen(tree)
totPathLen(tree)
tree |
A rooted tree in phylo format. |
totPathLen
returns the total path length of the given tree.
Luise Kuehn
see e.g. R. P. Dobrow, J. A. Fill. Total path length for random recursive trees. Combinatorics, Probability and Computing, 8(4):317–333, 1999. doi: 10.1017/S0963548399003855.
see e.g. L. Takacs. On the total heights of random rooted trees. Journal of Applied Probability, 29(3):543–556, 1992. doi: 10.2307/3214892.
see e.g. L. Takacs. On the total heights of random rooted binary trees. Journal of Combinatorial Theory, Series B, 61(2):155–166, 1994. ISSN 0095-8956. doi: 10.1006/jctb.1994.1041.
tree <- ape::read.tree(text="((((,),),(,)),(((,,),),(,)));") totPathLen(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,,),),(,)));") totPathLen(tree)
This function calculates the variance of leaf depths index
for a given rooted tree
. The tree must not necessarily be binary.
is defined as
in which denotes the number of leaves of
,
denotes the set of leaves of
,
denotes the depth of
the leaf
and
denotes the average leaf depth of
.
For the function returns
and a warning.
For details on the variance of leaf depths, see
also Chapter 7 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_7).
varLeafDepI(tree)
varLeafDepI(tree)
tree |
A rooted tree in phylo format. |
varLeafDepI
returns the variance of leaf depths index of the given tree.
Sophie Kersting
T. M. Coronado, A. Mir, F. Rossello, and L. Rotger. On Sackin's original proposal: the variance of the leaves' depths as a phylogenetic balance index. BMC Bioinformatics, 21(1), 2020. doi: 10.1186/s12859-020-3405-1. URL https://doi.org/10.1186/s12859-020-3405-1.
M. J. Sackin. "Good" and "Bad" Phenograms. Systematic Biology, 21(2):225-226, 1972. doi: 10.1093/sysbio/21.2.225.
K.-T. Shao and R. R. Sokal. Tree Balance. Systematic Zoology, 39(3):266, 1990. doi: 10.2307/2992186.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") varLeafDepI(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") varLeafDepI(tree)
Contains a vector of Wedderburn Etherington numbers for to
.
data(wedEth)
data(wedEth)
numerical vector
OEIS Sequence A001190 available at https://oeis.org/A001190
data(wedEth) wedEth[5]
data(wedEth) wedEth[5]
This function calculates the weighted l1 distance index for a
given rooted binary tree
.
is defined as
in which denotes the
number of leaves of
,
denotes the frequency of pending subtrees
of size
in
and
is the expected number of
pending subtrees of size
under the Yule model, i.e.
if
and otherwise
.
For the function returns
.
For details on the weighted l1 distance index, see
also Chapter 24 in "Tree balance indices: a comprehensive survey" (https://doi.org/10.1007/978-3-031-39800-1_24).
weighL1dist(tree)
weighL1dist(tree)
tree |
A rooted binary tree in phylo format. |
weighL1distI
returns the weighted l1 distance index of the given tree.
Sophie Kersting
M. G. Blum and O. Francois. On statistical tests of phylogenetic tree imbalance: The Sackin and other indices revisited. Mathematical Biosciences, 195(2):141-153, 2005. doi: 10.1016/j.mbs.2005.03.003.
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") weighL1dist(tree)
tree <- ape::read.tree(text="((((,),),(,)),(((,),),(,)));") weighL1dist(tree)