phylobase (version 0.8.2)

hasEdgeLength: edgeLength methods

Description

These functions give information about and allow replacement of edge lengths.

Usage

hasEdgeLength(x)
"hasEdgeLength"(x)
edgeLength(x, ...)
"edgeLength"(x, node)
edgeLength(x, use.names = TRUE, ...) <- value
"edgeLength"(x, use.names = TRUE, ...) <- value
depthTips(x)
"depthTips"(x)
nodeDepth(x, node)
"nodeDepth"(x, node)
nodeHeight(x, node, from)
"nodeHeight"(x, node, from = c("root", "all_tip", "min_tip", "max_tip"))
sumEdgeLength(x, node)
"sumEdgeLength"(x, node)
isUltrametric(x, tol = .Machine$double.eps^0.5)
"isUltrametric"(x, tol = .Machine$double.eps^0.5)

Arguments

x
a phylo4 or phylo4d object.
node
optional numeric or character vector indicating the nodes for which edge
use.names
should the the name attributes of value be used to match the length to a given edge.
value
a numeric vector indicating the new values for the edge lengths
from
The point of reference for calculating the height of the node. root calculates the distance between the root of the tree and the node. all_tip return the distance between the node and all the tips descending from it. min_tip the distance between the node and its closest tip. max_tip the distance between the node and its farther tip. min_tip and max_tip will be identical if the tree is ultrametric. If more than one tip is equidistant from the node, the tip with the lowest node id will be returned.
tol
the tolerance to decide whether all the tips have the same depth to test if the tree is ultrametric. Default is .Machine$double.eps^0.5.
...
optional arguments (none used at present).

Value

hasEdgeLength
whether or not the object has edge lengths (logical)
edgeLength
a named vector of the edge length for the object
isUltrametric
whether or not the tree is ultrametric (all the tips are have the same depth (distance from the root) (logical)
sumEdgeLength
the sum of the edge lengths for a set of nodes (intended to be used with ancestors or descendants)
nodeHeight
the distance between a node and the root or the tips. The format of the result will depend on the options and the number of nodes provided, either a vector or a list.
nodeDepth
Deprecated, now replaced by nodeHeight. A named vector indicating the “depth” (the distance between the root and a given node).
depthTip
Deprecated, now replaced by nodeHeight.

Details

The edgeLength function returns the edge length in the same order as the edges in the matrix.

See Also

ancestors, descendants, .Machine for more information about tolerance.

Examples

Run this code
  data(geospiza)
  hasEdgeLength(geospiza) # TRUE
  topoGeo <- geospiza
  edgeLength(topoGeo) <- NULL
  hasEdgeLength(topoGeo)  # FALSE

  edgeLength(geospiza)[2]       # use the position in vector
  edgeLength(geospiza)["16-17"] # or the name of the edge
  edgeLength(geospiza, 17)      # or the descendant node of the edge

  ## The same methods can be used to update an edge length
  edgeLength(geospiza)[2] <- 0.33
  edgeLength(geospiza)["16-17"] <- 0.34
  edgeLength(geospiza, 17) <- 0.35

  ## Test if tree is ultrametric
  isUltrametric(geospiza)   # TRUE
  ## indeed all tips are at the same distance from the root
  nodeHeight(geospiza, nodeId(geospiza, "tip"), from="root")
  ## compare distances from tips of two MRCA
  nodeHeight(geospiza, MRCA(geospiza, c("pallida", "psittacula")), from="min_tip")
  nodeHeight(geospiza, MRCA(geospiza, c("fortis", "difficilis")), from="min_tip")
  ## or the same but from the root
  nodeHeight(geospiza, MRCA(geospiza, c("pallida", "psittacula")), from="root")
  nodeHeight(geospiza, MRCA(geospiza, c("fortis", "difficilis")), from="root")

Run the code above in your browser using DataCamp Workspace