pkgdown/mathjax-config.html

Skip to contents

Overview

spacc computes spatial species accumulation curves (SACs) using nearest-neighbour algorithms with a C++ backend for speed. Unlike classical random SACs, spatial SACs respect the geographic arrangement of sampling sites, revealing how species richness accumulates as you expand outward from a focal point.

Simulating Example Data

library(spacc)

set.seed(42)
n_sites <- 80
n_species <- 40

coords <- data.frame(
  x = runif(n_sites, 0, 100),
  y = runif(n_sites, 0, 100)
)

# Simulate presence/absence with spatial structure
species <- matrix(0L, n_sites, n_species)
for (sp in seq_len(n_species)) {
  cx <- runif(1, 20, 80)
  cy <- runif(1, 20, 80)
  prob <- exp(-0.001 * ((coords$x - cx)^2 + (coords$y - cy)^2))
  species[, sp] <- rbinom(n_sites, 1, prob)
}
colnames(species) <- paste0("sp", seq_len(n_species))

Basic Spatial Accumulation Curve

The core function spacc() computes kNN-based accumulation curves from multiple random starting sites (seeds):

sac <- spacc(species, coords, n_seeds = 30, method = "knn", progress = FALSE)
sac
#> spacc: 80 sites, 40 species, 30 seeds (knn)
plot(sac)
0 10 20 30 40 0 20 40 60 80 Sites sampled Cumulative species knn, 30 seeds, 95% CI Species Accumulation Curve

Spatial species accumulation curve with 95% confidence ribbon.

The grey ribbon shows variability across starting points — wider ribbons indicate that species richness depends on where you start sampling.

Comparing Methods

spacc supports several accumulation methods:

  • knn: k-Nearest Neighbour (default, fast)

  • kncn: k-Nearest Centroid Neighbour (geometrically centred expansion)

  • random: Classical random accumulation (no spatial structure)

sac_kncn <- spacc(species, coords, n_seeds = 30, method = "kncn", progress = FALSE)
sac_rand <- spacc(species, coords, n_seeds = 30, method = "random", progress = FALSE)

Combine curves for comparison:

combined <- c(knn = sac, kncn = sac_kncn, random = sac_rand)
plot(combined)
0 10 20 30 40 0 20 40 60 80 Sites sampled Cumulative species Group knn kncn random Species Accumulation Curves

Comparison of accumulation methods.

Extrapolation

Fit an asymptotic model to estimate total species richness:

fit <- extrapolate(sac, model = "lomolino")
#> Waiting for profiling to be done...
fit
#> Extrapolation: lomolino 
#> ------------------------------ 
#> Estimated asymptote: 42.7 species
#> 95% CI: 42.2 - 43.3
#> AIC: 165.3
#> Observed: 40.0 species (94% of estimated)
plot(fit)
Asymptote: 43 10 20 30 40 0 50 100 150 Sites sampled Cumulative species Model: lomolino, AIC: 165.3 Species Accumulation with Extrapolation

Fitted Lomolino curve with asymptote estimate.

Pre-computing Distances

For repeated analyses on the same sites, pre-compute the distance matrix once:

d <- distances(coords, method = "euclidean")

sac1 <- spacc(species[, 1:20], d, n_seeds = 30, progress = FALSE)
sac2 <- spacc(species[, 21:40], d, n_seeds = 30, progress = FALSE)

Comparing Curves

Test whether two accumulation curves differ significantly:

comp <- compare(sac1, sac2, method = "permutation", n_perm = 199)
comp
#> Comparison: sac1 vs sac2 
#> ---------------------------------------- 
#> Method: permutation (n=199)
#> AUC difference: -8.6 (p = 0.573)
#> Saturation: sac1 at 23 sites, sac2 at 19 sites

Next Steps

  • Diversity: Hill numbers, beta diversity, phylogenetic and functional diversity accumulation
  • Extrapolation: Coverage-based extrapolation, EVT models, diversity-area relationships
  • Spatial Analysis: Endemism curves, fragmentation analysis, sampling-effort correction