R/J_stat.R

Defines functions entropy_j

Documented in entropy_j

#' Intensive quadratic entropy statistic J.
#' @description The intensive quadratic entropy statistic J is given by the
#' average distance between two randomly chosen species, thus given by the
#' sum of all pairwise distances, divided by S^2, where S is the number of tips
#' of the tree.
#' @param phy phylo object or ltable
#' @return intensive quadratic entropy statistic J
#' @references  Izsák, János, and Laszlo Papp. "A link between ecological
#' diversity indices and measures of biodiversity."
#' Ecological Modelling 130.1-3 (2000): 151-156.
#' @export
entropy_j <- function(phy) {
  if (inherits(phy, "matrix")) {
    phy <- treestats::l_to_phylo(phy)
  }
  if (inherits(phy, "phylo")) {
    return(calc_J_cpp(as.vector(t(phy$edge)),
                      phy$edge.length))
  }
  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.