# Getting started

#### Thijs Janzen

#### 2026-06-16

# Using treestats

The treestats package provides an easy to use interface to calculate summary statistics on phylogenetic trees. To obtain a list of all supported summary statistics use:

    list_statistics()

    ##  [1] "area_per_pair"          "average_leaf_depth"     "avg_ladder"
    ##  [4] "avg_vert_depth"         "b1"                     "b2"
    ##  [7] "beta"                   "blum"                   "cherries"
    ## [10] "colless"                "colless_corr"           "colless_quad"
    ## [13] "crown_age"              "diameter"               "double_cherries"
    ## [16] "eigen_centrality"       "eigen_centralityW"      "ew_colless"
    ## [19] "four_prong"             "gamma"                  "i_stat"
    ## [22] "il_number"              "imbalance_steps"        "j_one"
    ## [25] "j_stat"                 "laplace_spectrum_a"     "laplace_spectrum_e"
    ## [28] "laplace_spectrum_g"     "laplace_spectrum_p"     "max_adj"
    ## [31] "max_betweenness"        "max_closeness"          "max_closenessW"
    ## [34] "max_del_width"          "max_depth"              "max_ladder"
    ## [37] "max_laplace"            "max_width"              "mean_branch_length"
    ## [40] "mean_branch_length_ext" "mean_branch_length_int" "mean_inv_branch_dist"
    ## [43] "min_adj"                "min_laplace"            "mntd"
    ## [46] "mpd"                    "mw_over_md"             "nltt_base"
    ## [49] "number_of_lineages"     "phylogenetic_div"       "pigot_rho"
    ## [52] "pitchforks"             "psv"                    "rogers"
    ## [55] "root_imbalance"         "rquartet"               "sackin"
    ## [58] "stairs"                 "stairs2"                "symmetry_nodes"
    ## [61] "tot_coph"               "tot_internal_path"      "tot_path"
    ## [64] "tree_height"            "treeness"               "var_branch_length"
    ## [67] "var_branch_length_ext"  "var_branch_length_int"  "var_depth"
    ## [70] "vpd"                    "wiener"

If your favourite summary statistic is missing, please let the maintainer know, treestats is a dynamic package always under development, and the maintainers are always looking for new statistics!

Given a phylogenetic tree, you can now use of the available functions to calculate your summary statistic of choice. Let’s take for instance the Colless statistic (and we generate a dummy tree):

    phy <- ape::rphylo(n = 100, birth = 1, death = 0.1)

    treestats::colless(phy)

    ## [1] 324

Looking at the documentation of the colless statistic (`?colless`), we find that the function also includes options to normalize for size: either ‘pda’ or ‘yule’:

    treestats::colless(phy, normalization = "yule")

    ## [1] -0.2492387

## Multiple statistics

The treestats package supports calculating many statistics in one go. For this, several functions have been set up aptly. Firstly, the function `calc_all_stats` will calculate all statistics:

    all_stats <- calc_all_stats(phy)

Similarly, we can also blanket apply all topology associated summary statistics:

    balance_stats <- calc_topology_stats(phy)
    unlist(balance_stats)

    ##      area_per_pair average_leaf_depth         avg_ladder     avg_vert_depth
    ##       1.382141e+01       8.420000e+00       2.444444e+00       7.467337e+00
    ##                 b1                 b2               beta               blum
    ##       5.220239e+01       5.199585e+00      -3.631946e-01       1.177402e+02
    ##           cherries            colless       colless_corr       colless_quad
    ##       3.300000e+01       3.240000e+02       6.679035e-02       5.884000e+03
    ##           diameter    double_cherries   eigen_centrality         ew_colless
    ##       2.700000e+01       4.000000e+00       2.445037e-01       4.667148e-01
    ##         four_prong             i_stat          il_number    imbalance_steps
    ##       6.000000e+00       5.185230e-01       3.400000e+01       8.500000e+01
    ##              j_one    max_betweenness      max_closeness      max_del_width
    ##       7.890566e-01       1.174100e+04                 NA       8.000000e+00
    ##          max_depth         max_ladder          max_width         mw_over_md
    ##       1.400000e+01       3.000000e+00       3.200000e+01       2.285714e+00
    ##         pitchforks             rogers     root_imbalance           rquartet
    ##       1.400000e+01       6.000000e+01       5.200000e-01       4.926423e+06
    ##             sackin             stairs            stairs2     symmetry_nodes
    ##       8.420000e+02       6.060606e-01       6.448332e-01       6.200000e+01
    ##           tot_coph  tot_internal_path    tot_path_length          var_depth
    ##       7.471000e+03       6.440000e+02       1.486000e+03       6.143600e+00