R/get_norm_n.R

Defines functions get_norm_n

Documented in get_norm_n

#' Collect the normalized number of lineages from the stem age
#' @param phylogeny a phylogeny of class 'phylo'
#' @return branching times, in time units before the present
#' @examples
#'   phylogeny <- ape::read.tree(text = "((a:2,b:2):1,c:3);")
#'   phylogeny$root.edge <- 2 # nolint ape variable name
#'     all.equal(as.vector(nLTT::get_branching_times(phylogeny)), c(5, 3, 2))
#' @author Richèl Bilderbeek
#' @export
get_norm_n <- function(phylogeny) {
  ns <- nLTT::get_n_lineages(phylogeny)
  # Repeat the last value to have te ns at the present
  ns <- c(ns, utils::tail(ns, n = 1))
  # Reverse to have 'times ago' (e.g. 4,3,0) -> (0, -1, -4) -> (0,1,4)
  ns <- ns - ns[1]
  ns <- -ns
  # Normalize
  ns <- ns / utils::tail(ns, n = 1)
  return(ns)
}

Try the nLTT package in your browser

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

nLTT documentation built on Aug. 21, 2023, 5:13 p.m.