| spaccDiversity | R Documentation |
Accumulate any user-supplied diversity index along a spatial ordering of
sites. At each accumulation step the cumulative community is passed to
fun, which returns a single number. This is the general escape hatch
behind the built-in metric functions: use it for indices that spacc does
not implement directly.
spaccDiversity(
x,
coords,
fun,
...,
method = c("knn", "kncn", "random", "radius", "collector"),
incidence = FALSE,
n_seeds = 50L,
distance = c("euclidean", "haversine"),
progress = TRUE,
seed = NULL
)
x |
A site-by-species matrix (rows = sites, cols = species), abundance or presence/absence. |
coords |
A data.frame with columns |
fun |
A function applied to the cumulative community at each step. It
receives a named numeric vector of length |
... |
Additional arguments passed to |
method |
Character. Spatial ordering of sites: |
incidence |
Logical. If |
n_seeds |
Integer. Number of random starting points / orderings.
Ignored for |
distance |
Character. |
progress |
Logical. Show progress? Default |
seed |
Integer. Random seed for reproducibility. |
The site ordering reuses the same spatial traversals as the built-in
methods (nearest-neighbour, nearest-centroid, random, distance-rank, or
data order), then evaluates fun on the accumulating community. Because the
index is an arbitrary R function, this trades the speed of the compiled
metrics for full flexibility.
An object of class spacc_diversity that inherits from spacc, so
the standard summary(), plot(), as.data.frame() and predict()
methods apply. curves is an n_seeds x n_sites matrix of the metric
along the accumulation.
spaccHill(), spaccPhylo(), spaccFunc() for built-in metrics.
coords <- data.frame(x = runif(40), y = runif(40))
species <- matrix(rpois(40 * 20, 2), nrow = 40)
# Shannon entropy along the accumulation
shannon <- function(comm) {
p <- comm[comm > 0] / sum(comm)
-sum(p * log(p))
}
div <- spaccDiversity(species, coords, shannon, n_seeds = 20)
plot(div)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.