R/avg_vertex_depth.R

Defines functions avg_vert_depth

Documented in avg_vert_depth

#' Average vertex depth metric
#' @description The average vertex depth metric, measures the average path
#' (in edges), between the tips and the root.
#' @param phy phylo object or ltable
#' @return Average depth (in number of edges)
#' @references  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.
#' @export
avg_vert_depth <- function(phy) {
  if (inherits(phy, "matrix")) {
    phy <- treestats::l_to_phylo(phy, drop_extinct = FALSE)
  }
  if (inherits(phy, "phylo")) {
    max_d_stat <- calc_avg_vert_depth_cpp(as.vector(t(phy$edge)))
    return(max_d_stat)
  }
  stop("input object has to be phylo or ltable")
}

Try the treestats package in your browser

Any scripts or data that you put into this service are public.

treestats documentation built on Sept. 14, 2024, 9:08 a.m.