Learn R Programming

metricTester (version 1.2.2)

calcMetrics: Calculate phylogenetic community structure metrics

Description

Given a prepped metrics.input object, calculate all phylogenetic community structure metrics of interest.

Usage

calcMetrics(metrics.input, metrics)

Arguments

metrics.input
Prepped metrics.input object
metrics
Optional list of named metric functions to use. If invoked, this option will likely be used to run a subset of the defined metrics.

Value

A data frame with the calculated metrics and the associated species richness of all input "communities".

Details

Currently we are calculating 19 phylogenetic community structure metrics. This function first confirms that the input is of class metrics.input and, if so, then confirms that the metrics to be calculated are in a named list (via checkMetrics), then lapplies all metric functions to the input metrics.input object.

References

Miller, E. T., D. R. Farine, and C. H. Trisos. 2015. Phylogenetic community structure metrics and null models: a review with new methods and software. bioRxiv 025726.

Examples

Run this code
#simulate tree with birth-death process
tree <- geiger::sim.bdtree(b=0.1, d=0, stop="taxa", n=50)

sim.abundances <- round(rlnorm(5000, meanlog=2, sdlog=1))

cdm <- simulateComm(tree, richness.vector=10:25, abundances=sim.abundances)

prepped <- prepData(tree, cdm)

results <- calcMetrics(prepped)

#an example of how to define ones own metrics for use in the metricTester framework
#this "metric" simply calculates the richness of each plot in the CDM
exampleMetric <- function(metrics.input)
{
output <- apply(metrics.input$picante.cdm, 1, lengthNonZeros)
output
}

calcMetrics(prepped, metrics=list("example"=exampleMetric))

Run the code above in your browser using DataLab