Computation of Tree (Im)Balance Indices
Overview
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) 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 6 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 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) https://emmanuelparadis.github.io/misc/FormatTreeR_24Oct2012.pdf.
- **Changed results and return types:** The Wedderburn-Etherington numbers in
wedEthare now stored exactly as big integers (bigz, packagegmp). Previously they were stored as double, which made them inexact from n = 50 and infinite from n = 793 on. As a consequence,furnasI(),furnasI_inv(),treenumber(),treenumber_inv()andgetfurranks()now compute exactly for all trees with up to 2545 leaves; previously they silently returned wrong results for n >= 51.we_eth()now returnsbigzby default. - **Changed results and return types:**
colPlaLab()now computes the Colijn-Plazzotta rank exactly and returns it asbigzby default; previously the ranks were wrong from n = 10 and infinite from n = 14 on.colPlaLab_inv()andcPL_inv()now also compute exactly. - New argument
type = "double"inwe_eth(),furnasI(),treenumber()andcolPlaLab()to obtain the result as double. It is only available as long as all values can be represented exactly (n <= 48, n <= 47 and n <= 9, respectively); otherwise the functions stop.
Show all changes in 1.2.2Hide the rest of the changes in 1.2.2
furnasI_inv(),treenumber_inv(),colPlaLab_inv()andcPL_inv()accept the rank asbigz, character or double (the latter up to 2^53).- **Changed results:**
collesslikeI(dissim = "mdm")now computes the mean deviation from the median as documented. Previously the sum instead of the mean was returned, i.e. the balance value of every vertex was multiplied by its number of children. rQuartetI()now takes the shape valueq0into account (previously it was ignored, so results were only correct forq0 = 0) and checks thatshapeValhas exactly 5 entries.B1I(),totCophI()andareaPerPairI()now return 0 (resp. the correct value) for star trees instead ofNA.collessI(method = "corrected")now returns 0 forn = 2as documented instead ofNaN.is_binary()now returnsFALSEinstead ofNULLfor non-binary trees, so the binary-only functions show their intended error message.collesslikeI()now also accepts functions forf.sizeanddissimdirectly, not only their names as strings (needed e.g. for functions defined within another function or package).B2I()andsShapeI()now stop for the invalid logarithm base 1 (andsShapeI()also for non-positive bases) instead of returningInf/NaN.tree_merge()now also works for trees with edge lengths (previously it failed with "tree 'x' has no root edge") and keeps tip labels and edge lengths when two single leaves are merged.furnasI_inv()andtreenumber_inv()now also work whentreebalanceis not attached, e.g. when used from within another package.- Updated the citation to the published book "Tree Balance Indices -- A Comprehensive Survey" (Springer, 2023).
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-04
- NOTE12 OK, 1 NOTE2026-08-01
- OK14 OK2026-03-10
Documentation
- Help pages
- 32
- Examples that run
- 100%32 run in a plain check
- Exported functions with examples
- 100%
- Documented parameters
- 99%
- Return-value docs
- 100%
- Help pages citing references
- 91%
Downloads
Dependencies
Installing treebalance adds 8 packages (7 with compiled code, 4.4 MB of source tarballs). Heaviest: Rcpp 1.8 MB, ape 1.4 MB, rlang 766 KB.
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- 1.2.2Latest
- RR 4.6.0 released · 2026-04-24
- RR 4.5.0 released · 2025-04-11
- RR 4.4.0 released · 2024-04-24
- 1.2.0
- RR 4.3.0 released · 2023-04-21
- RR 4.2.0 released · 2022-04-22
- 1.1.02021-10-17 · diff ↗
- 1.0.02021-09-22
- RR 4.1.0 released · 2021-05-18
Package metadata
- First published
- 2021-09-22
- Total releases
- 4 / 5 yrs
- License
- GPL-3 OSI
- Minimum R
- ≥ 3.5.0
- Bundled data
- 526 KB / 1 file
- Download size
- 577 KB
Cite
Cite this package
Run in R for the authors' entry:
citation("treebalance")The package provides a citation file, so citation() returns the authors' own entry.
It points to 10.1007/978-3-031-39800-1.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-22, which the citation names so these numbers can be found later. More on citing and the projects behind them.