recpd_calc: Calculate the RecPD of a feature and other associated...

View source: R/recpd_calc.R

recpd_calcR Documentation

Calculate the RecPD of a feature and other associated measures.

Description

See Bundalovic-Torma, Guttman; (2021).

Usage

recpd_calc(
  tree,
  tab,
  option = c("nn", "mpr", "ace"),
  params = list(nn_select = c("min", "median"), model_type = c("ER", "ARD"), kappa = 1,
    lik_cut = 0.99),
  calc = FALSE,
  prune = TRUE
)

Arguments

tree

A phylogenetic tree, in phylo format.

tab

A feature(s) presence/absence array, matrix, or data.frame: columns should be named according to the tip labels of the tree.

option

Ancestral state reconstruction method to apply, either 'nn', 'mpr', or 'ace'.

params

Additional paramaters to pass to ancestral reconstruction methods.

calc

logical. If TRUE, calculate additional measures: span, clustering, longevity, and lability.

prune

logical. If TRUE and option == 'nn', will provide a conservative reconstruction of feature lineages.

Value

A named list including metrics and ancestral state annotations for tree nodes and branches for each feature in tab.

Author(s)

Cedoljub Bundalovic-Torma

References

Insert reference with Rdpack.

Examples

library(ape)
library(dplyr)

##Test case for a randomly generated tree (10 tips) and 10 randomly generated
##feature presence/absence (1, 0) data.frame.

#Generate a random phylogenetic tree:
n_tip <- 10
tree <- rtree(n_tip)

#Generate 10 randomly distributed features (rows = features, columns =
#phylogenetic tree tips):
tab <- replicate(10,
                 sapply(10, function(x) sample(c(0,1), x, replace=TRUE)),
                 simplify='matrix') %>%
  t() %>%
  data.frame(check.names=FALSE) %>%
  rename_with(function(x) tree$tip.label[as.numeric(x)])

#Note: columns should be labelled by tip.label of the tree. This also means that
#all of the tips in the tree should have an associated feature presence absence
#state. If tips lack this information, the tree should be parsed (see
#ape::keep.tip()).


#Run recpd_calc() without calculating additional measures (span, cluster,
#longevity, lability):
recpd_calc(tree, tab, calc=FALSE)

#Run recpd_calc() with additional measures calculated:
recpd_calc(tree, tab, calc=TRUE)


DSGlab/recpd documentation built on July 2, 2023, 6:12 a.m.