MyNixOS website logo
Description

Fast Spatial Species Accumulation Curves.

High-performance spatial species accumulation curves using nearest-neighbor algorithms. Implements 'kNN' and 'kNCN' sampling methods with a 'C++' backend for speed. Supports Hill numbers (q=0,1,2), beta diversity partitioning (turnover/nestedness), coverage-based rarefaction and extrapolation, phylogenetic diversity (Faith's PD, mean pairwise distance, mean nearest taxon distance), functional diversity accumulation, diversity-area relationships (DAR), endemism-area curves, sampling-effort correction and fragmentation analysis, and species-area relationship (SAR) models based on extreme value theory (EVT). Multiple starting points (seeds) provide uncertainty quantification. Methods are described in 'Chao' et al. (2014) <doi:10.1890/13-0133.1>, 'Baselga' (2010) <doi:10.1111/j.1466-8238.2009.00490.x>, 'Chao' and 'Jost' (2012) <doi:10.1890/11-1952.1>, 'Faith' (1992) <doi:10.1016/0006-3207(92)91201-3>, 'Ma' (2018) <doi:10.1002/ece3.4526>, 'Borda-de-Agua' et al. (2025) <doi:10.1038/s41467-025-59239-7>, 'Hanski' et al. (2013) <doi:10.1073/pnas.1311190110>, and 'Jost' (2007) <doi:10.1890/06-1736.1>.

spacc

species accumulating in the neighbourhood

R-CMD-check codecov License: MIT

Spatial species accumulation curves built by nearest-neighbour expansion in C++.

Pick a starting site, then walk outward to its nearest neighbours, counting new species as you go. spacc does that from many starting points (Rcpp/RcppParallel backend), so the curve carries a confidence ribbon showing how richness depends on where you begin. The classical curve in vegan::specaccum() shuffles sites in random order and never sees the map. spacc reproduces that random-order curve and adds the spatial one, so you can read the gap between them.

library(spacc)

coords  <- data.frame(x = runif(100), y = runif(100))
species <- matrix(rbinom(100 * 50, 1, 0.3), nrow = 100)

# spatial accumulation: walk outward by nearest neighbour
sac <- spacc(species, coords, method = "knn", n_seeds = 100)
plot(sac)

Spatial order, not random order

vegan::specaccum() accumulates sites in random or collector order, so geography drops out. spacc() keeps it: each curve follows nearest-neighbour expansion from a real seed site, and the spread across seeds is the spatial signal. Run both and compare them directly.

sac        <- spacc(species, coords, method = "knn",    n_seeds = 100)
sac_random <- spacc(species, coords, method = "random", n_seeds = 100)

comp <- compare(sac, sac_random)   # permutation, bootstrap, or AUC test
plot(comp)

Seven expansion methods are available: knn and kncn (nearest-neighbour and nearest-centroid walks), radius, gaussian, and cone (distance- and direction-weighted growth), random (the classical null), and collector (data order). Geographic coordinates use distance = "haversine" with no projection step.

Backend selection

Nearest-neighbour queries pick a backend by site count, overridable with backend.

BackendDistanceCost per queryWhen
Exact (brute force)anyO(n)<= 500 sites (auto)
k-d tree (nanoflann)EuclideanO(log n)> 500 sites (auto)
Ball treeHaversineO(log n)> 500 sites, distance = "haversine"
sac <- spacc(species, coords_lonlat, distance = "haversine", n_seeds = 50)
sac <- spacc(species, coords, backend = "kdtree", n_seeds = 50)

Diversity beyond richness

Accumulation works for more than species counts. Each function carries the spatial ordering through to a different diversity measure, with map = TRUE and as_sf() for GIS output.

  • spaccHill(): Hill numbers (q = 0, 1, 2) along the accumulation, extending the iNEXT framework to spatial order.
  • spaccBeta(): beta diversity with turnover and nestedness components (Baselga 2010).
  • spaccCoverage(): coverage-based rarefaction via the Good-Turing estimator (Chao & Jost 2012).
  • spaccPhylo() / spaccFunc(): phylogenetic (MPD, MNTD) and functional (FDis, FRic) accumulation.
  • alphaDiversity() / gammaDiversity() / diversityPartition(): local, regional, and alpha-beta-gamma decomposition (Jost 2007).
hill <- spaccHill(species, coords, q = c(0, 1, 2), n_seeds = 50, map = TRUE)
plot(hill)                       # accumulation curves
plot(hill, type = "map", q = 0)  # per-site richness map

beta <- spaccBeta(species, coords, index = "sorensen", n_seeds = 50)
plot(beta, partition = TRUE)     # turnover vs nestedness

Grouped and spatiotemporal accumulation

Split species into groups (native vs alien, families, any factor) and accumulate each under the same spatial site ordering, or add a temporal axis to weight space against time.

# same spatial walk, separate curve per group
sac_grouped <- spacc(species, coords, groups = status, seed = 42)
plot(sac_grouped, facet = TRUE)

# sites sampled across years: weighted space-time distance
sac_st <- spacc(species, coords, method = "knn",
                time = site_years, w_space = 1, w_time = 0.5)

Fitting and standardizing

  • extrapolate(): asymptotic richness models (Michaelis-Menten, Lomolino, Weibull, logistic, EVT).
  • compare(): permutation, bootstrap, or AUC tests between curves.
  • rarefy() / subsample(): rarefaction to common effort, spatial subsampling.
  • coleman() / mao_tau() / spatialRarefaction(): analytical (non-simulation) curves.
  • as_spacc(): bring an existing vegan::specaccum() object into the same plotting and comparison machinery.

Installation

install.packages("pak")
pak::pak("gcol33/spacc")

Documentation

Support

"Software is like sex: it's better when it's free." — Linus Torvalds

I'm a PhD student who builds R packages in my free time because I believe good tools should be free and open. I started these projects for my own work and figured others might find them useful too.

If this package saved you some time, buying me a coffee is a nice way to say thanks. It helps with my coffee addiction.

Buy Me A Coffee

License

MIT (see the LICENSE.md file)

Citation

@software{spacc,
  author = {Colling, Gilles},
  title = {spacc: Fast Spatial Species Accumulation Curves},
  year = {2025},
  url = {https://github.com/gcol33/spacc}
}
Metadata

Version

0.8.3

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows