Skip to contents

An accumulation curve depends on the rule that decides which site enters next. This article runs every rule of spacc() on one simulated survey, maps the route each one takes, and ends with guidance on which rule answers which sampling question. The formal definition of each rule is in How spatial accumulation works; installation is in Get started. The figures need ggplot2.

  1. Run the seven methods on the same data.

  2. Map the order in which each method visits the sites.

  3. Tune the rules that take parameters.

  4. Supply your own orders.

  5. Choose a rule for the question at hand.

Seven methods on one survey

The survey is the one from Get started: 80 sites in a 100 by 100 square and 40 species, each occupying a patch about 60 units across around its own centre.

set.seed(42)
n_sites <- 80
n_species <- 40
coords <- data.frame(x = runif(n_sites, 0, 100), y = runif(n_sites, 0, 100))
species <- matrix(0L, n_sites, n_species)
for (j in seq_len(n_species)) {
  cx <- runif(1, 20, 80)
  cy <- runif(1, 20, 80)
  p <- exp(-0.001 * ((coords$x - cx)^2 + (coords$y - cy)^2))
  species[, j] <- rbinom(n_sites, 1, p)
}

The method argument selects the rule:

  • knn draws a focal point in the study area and adds sites by distance from that fixed point (the default).

  • kncn adds the site nearest to the centroid of the sites already visited.

  • nn_walk moves from the current site to the nearest unvisited site.

  • gaussian moves to a random unvisited site, favouring near ones.

  • cone adds sites inside a wedge pointing in a random direction first, then the rest, each by distance.

  • random adds sites in random order, ignoring space.

  • collector adds sites in the row order of the data, once.

Every method except collector draws n_seeds orders, each from its own starting point or direction. The loop below runs all seven with the same seed.

methods <- c("knn", "kncn", "nn_walk", "gaussian", "cone", "random",
             "collector")
fits <- lapply(methods, function(m) {
  spacc(species, coords, method = m, n_seeds = 50, seed = 1,
        progress = FALSE)
})
names(fits) <- methods
fits$collector
#> spacc: 80 sites, 40 species, 1 seeds (collector)

collector returns one curve, so it has no band. c() combines the seven objects into one grouped object for plotting; facet = TRUE draws each in its own panel.

all_fits <- do.call(c, fits)
plot(all_fits, facet = TRUE) + theme(legend.position = "none")

Seven accumulation curves in separate panels. random and gaussian rise fastest; knn, kncn and nn_walk rise slowest with wide bands; cone lies close to them; collector is a single line. collector gaussian cone random knn kncn nn_walk 0 20 40 60 80 0 20 40 60 80 0 20 40 60 80 0 20 40 60 80 0 20 40 60 80 0 20 40 60 80 0 20 40 60 80 0 10 20 30 40 0 10 20 30 40 0 10 20 30 40 Sites sampled Cumulative species Species Accumulation Curves

The spread is easier to read from the mean number of species after 10 and 20 sites:

early <- sapply(fits, function(f) colMeans(f$curves)[c(10, 20)])
round(early, 1)
#>      knn kncn nn_walk gaussian cone random collector
#> [1,]  31 29.8    29.7     37.3 30.9   37.4        40
#> [2,]  37 37.0    36.8     39.8 36.9   39.8        40

The random order finds more species early than the spatial rules, because each step can draw a site from any patch. The three distance rules (knn, kncn, nn_walk) find the fewest, because they stay among neighbours that share species. With its default bandwidth, the median distance between sites, gaussian is close to random on this survey. The rows of the simulated data are in random spatial order, so the single collector curve is one random order; here it happened to find all 40 species within 10 sites. The gap between the random curve and a spatial one measures the spatial structure of the community; the curves only coincide when neighbouring sites are no more alike than distant ones.

The routes behind the curves

Each spacc object stores its orders in orders, a matrix with one row per seed and one column per step, holding site indices. Mapping the first row shows the route of one seed. The helper below takes the first 25 sites of that route and joins them in visiting order.

route <- function(fit, name, k = 25) {
  o <- fit$orders[1, seq_len(k)]
  data.frame(method = name, step = seq_len(k),
             x = coords$x[o], y = coords$y[o])
}
routes <- do.call(rbind, Map(route, fits[1:6], methods[1:6]))
routes$method <- factor(routes$method, levels = methods[1:6])
ggplot(routes, aes(x, y)) +
  geom_point(data = coords, colour = "grey75") +
  geom_path(colour = "grey40") +
  geom_point(aes(colour = step), size = 2) +
  facet_wrap(~ method, ncol = 3) +
  scale_colour_viridis_c(name = "Step") +
  coord_equal()

Six maps of the same eighty sites, each with a path through the first twenty-five sites visited. knn and kncn cover a compact disc; nn_walk follows a chain; gaussian makes longer jumps; cone runs in one direction; random jumps across the whole square. gaussian cone random knn kncn nn_walk 0 25 50 75 100 0 25 50 75 100 0 25 50 75 100 0 25 50 75 100 0 25 50 75 100 x y Step 5 10 15 20 25

knn and kncn fill a compact area around their reference point, the centroid of the visited sites in the case of kncn. nn_walk follows a chain of nearest neighbours and can leave a cluster through a narrow gap. gaussian takes the occasional longer jump, cone advances in one direction, and random covers the whole square from the start.

Tuning gaussian, cone and knn

Three rules take parameters. sigma sets the bandwidth of the gaussian rule, in the units of the coordinates; by default it is the median of all non-zero distances between sites. A small bandwidth makes the rule behave like nn_walk, a large one like random.

sig <- lapply(c(5, 20, 80), function(s) {
  spacc(species, coords, method = "gaussian", sigma = s, n_seeds = 50,
        seed = 1, progress = FALSE)
})
round(sapply(sig, function(f) colMeans(f$curves)[10]), 1)
#> [1] 29.4 35.1 37.3

The mean after 10 sites rises with the bandwidth, from close to the nn_walk value towards the random one in Seven methods on one survey.

cone_width is the half-width of the cone wedge in radians; the default pi / 4 gives a wedge of 90 degrees. Directions are planar angles for distance = "euclidean" and great-circle bearings for distance = "haversine".

narrow <- spacc(species, coords, method = "cone", cone_width = pi / 12,
                n_seeds = 50, seed = 1, progress = FALSE)
round(colMeans(narrow$curves)[c(10, 20)], 1)
#> [1] 31.0 36.8

A wedge a third as wide as the default changes the mean after 10 and 20 sites by a few tenths of a species on this survey.

For knn, focal_points fixes the focal points instead of drawing them, one curve per row. Using the sites themselves as focal points gives one curve per site, the plot-seeded version of the rule.

at_sites <- spacc(species, coords, method = "knn", focal_points = coords,
                  progress = FALSE)
at_sites
#> spacc: 80 sites, 40 species, 80 seeds (knn)

By default the focal points are drawn uniformly over the convex hull of the sites. focal_domain takes an sf polygon of the study area instead, which keeps concave edges, holes and separate parts out of or in the domain as drawn. Both arguments are only accepted with method = "knn".

Supplying your own orders

When the sequence follows something other than distance, such as a survey date, a position along a transect or an elevation rank, pass it through order. A vector gives one curve. Here the sites enter from west to east.

west_east <- spacc(species, coords, order = order(coords$x),
                   progress = FALSE)
west_east
#> spacc: 80 sites, 40 species, 1 seeds (user)

The method label becomes user. A matrix with one order per row, or a list of order vectors, gives one curve per order and a band across them. Each order must contain every site index exactly once. Here 20 orders run roughly from west to east: each adds random noise to the x coordinate before sorting, so sites at similar positions swap places between orders.

set.seed(2)
jittered <- t(replicate(20, order(coords$x + rnorm(n_sites, sd = 5))))
we_band <- spacc(species, coords, order = jittered, progress = FALSE)
we_band$n_seeds
#> [1] 20

The orders element of any result can be passed back through order. This reuses the exact routes of one run for another species table, for example a second survey of the same sites.

second <- spacc(species[, 1:20], coords, order = fits$nn_walk$orders,
                progress = FALSE)
identical(second$orders, fits$nn_walk$orders)
#> [1] TRUE

order cannot be combined with support or time, because a supplied order already fixes the sequence over all sites.

Which order for which question

Each rule stands for a sampling design. The table pairs them with the question their curve answers.

Method Next site Question the curve answers
knn nearest to a fixed focal point How many species does a survey of a growing area around a point record?
kncn nearest to the centroid of the visited sites The same for a compact area grown from a starting site
nn_walk nearest to the current site How many species does a route from site to neighbouring site record?
gaussian random, weighted towards near sites A route with occasional longer moves, set by sigma
cone nearest inside a wedge, then the rest A survey advancing in one direction, such as up a valley
random random The classical curve, and the baseline for spatial structure
collector next row of the data The survey in the order it was carried out

For a species-area question, knn is the default and follows the spatially constrained rarefaction of Chiarucci et al. (2009). When planning a survey that expands from the sites already visited, the slope of a spatial curve estimates how many new species one more nearby site adds; the random curve’s slope would overstate it whenever neighbouring sites share species. Draw a random curve next to any spatial one, since their difference is what the spatial order adds. When sites carry no meaningful positions, or the design already randomised them, random alone answers the question. Comparing curves between groups and regions tests such differences; Running on many sites gives the run times of each rule on large site sets.

References

Chiarucci, A., Bacaro, G., Rocchini, D., Ricotta, C., Palmer, M. W., & Scheiner, S. M. (2009). Spatially constrained rarefaction: incorporating the autocorrelated structure of biological communities into sample-based rarefaction. Community Ecology, 10, 209-214.