wpd_table: wpd_table

View source: R/wpd_table.r

wpd_tableR Documentation

wpd_table

Description

Calculates phylogenetic entropy (Hp) for each column vector s of species observations within matrix m, weighted by the frequency of each species within s. Can also calculate Faith's PD.

Usage

wpd_table(
  m,
  s_phylo,
  s_names = NULL,
  nested_set = NULL,
  metric = "Hp",
  ncores = 4
)

Arguments

m

numeric matrix or data.frame of weights, where columns are species and rows are samples.

s_phylo

phylo object. Tree containing all unique names in s as tips. Must not contain duplicate tip labels.

s_names

species names for m if not colnames(m). NULL will use colnames (default: NULL)

nested_set

matrix. The output of make_nested_set(s_phylo). If not provided, will be calculated on the fly. Precalculation only provides speedup with very large trees (default: NULL).

metric

character. Abbreviated name of desired tree-based phylogenetic diversity metric. Available metrics are:

Hp:

Phylogenetic Entropy. Insensitive to 0 weights, cannot increase with removal of taxa. Allen et al. 2009.

WF:

Weighted Faith's PD. Sensitive to 0 weights, i.e. a clade that was heavily sampled but has lots of zeroes will cause its sister clades to be underrepresented. Swenson 2014.

PD:

Original Faith's Phylogenetic Diversity. Unweighted. Simply a sum of branch- lengths in your tree (but only for taxa in s). Faith 1992.

ncores

integer. Number of CPU cores to use for parallel operations. If set to 1, lapply will be used instead of mclapply. A warning will be shown if n_cores > 1 on Windows, which does not support forked parallelism (default: 2).

Value

multiple WPD or PD values, one for each column of m.

Author(s)

John L. Darcy

References

  • Allen B, Kon M, Bar-Yam Y (2009) A new phylogenetic diversity measure generalizing the Shannon index and its application to Phyllostomid bats. American Naturalist 174(2).

  • Swenson NG (2014) Functional and Phylogenetic Ecology in R. Springer UseR! Series, Springer, New York, New York, U.S.A.

  • Faith DP (1992) Conservation evaluation and phylogenetic diversity. Biological Conservation 61.

Examples

# library(specificity)
# set.seed(12345)
# s_phylo <- get(data(endophyte))$supertree
# w <- sample(c(0, 1), replace=TRUE, size=10)
# nspec <- 12
# m <- t(as.matrix(data.frame(
#   a=runif(nspec, 0, 100),
#   b=runif(nspec, 0, 100),
#   c=runif(nspec, 0, 100)
# )))
# colnames(m) <- sample(s_phylo$tip.label, ncol(m))
# wpd_table(m, s_phylo)


darcyj/specificity documentation built on Aug. 1, 2023, 8 a.m.