Aggregation, richness gradients and sampling all leave marks in a
turnover curve that can look like the outcome of community assembly, so
a raw curve cannot show on its own whether a pattern is non-random. A
null model randomises the species matrix while holding chosen features
fixed, reruns the analysis on each randomised matrix and measures how
far the observed curve sits from the randomised ones. This article tests
a richness accumulation curve against two null models with
ses() and compares what each one detects. Installation is
covered in Get started; the plots need
ggplot2. The descriptive turnover measures for the same simulated
community are in Measuring distance decay and
zeta diversity.
Build the accumulation curve to test with
spacc().Randomise the community and compute standardised effect sizes with
ses().Compare the result under a second null model.
Example
Effect sizes and permutation p-values
The standardised effect size is
\[ \mathrm{SES} = \frac{\text{obs} - \overline{\text{null}}}{\mathrm{sd}_{\text{null}}}, \]
the number of null standard deviations between the observed statistic
and the mean of the null distribution. For a richness accumulation
curve, ses() computes it at every accumulation step. Under
a two-tailed convention, \(|\mathrm{SES}| >
1.96\) flags a departure at roughly the 5% level when the null
distribution is approximately normal. A positive SES means more species
accrue than the null predicts (spatial overdispersion); a negative SES
means fewer accrue (clustering, or redundant encounters of aggregated
species).
ses() also returns a permutation p-value, which does not
rely on the normal approximation. With \(b_{\le}\) the number of the \(n_{\text{perm}}\) null values at or below
the observed value and \(b_{\ge}\) the
number at or above it,
\[ p = \min\left(1,\; \frac{2 \cdot (\min(b_{\le},\, b_{\ge}) + 1)}{n_{\text{perm}} + 1}\right). \]
Each tail counts the observed value as one more permutation, so the p-value is never zero (Phipson & Smyth 2010), and the smaller tail is doubled for the two-tailed test. A null value equal to the observed one counts in both tails, so a step at which every null curve equals the observed curve has \(p = 1\). The smallest p-value the formula can return is \(2/(n_{\text{perm}} + 1)\), which sets how many permutations a test needs (Practical guidance).
Simulating a structured community
The simulated arena is a 100 by 100 unit square with 60 sites placed at random and 25 species. Each species has a centre, and its abundance at a site is drawn from a Poisson distribution with mean \(3 e^{-d/30}\) for a site \(d\) units from that centre. Each species therefore occupies a patch: it is common near its centre and rare beyond about twice the 30-unit decay scale. Because aggregated species are encountered redundantly by nearby sites, richness should accumulate more slowly than under a null model that shuffles co-occurrences.
Simulation code
set.seed(123)
n_sites <- 60
coords <- data.frame(
x = runif(n_sites, 0, 100),
y = runif(n_sites, 0, 100)
)
n_species <- 25
species <- matrix(0, nrow = n_sites, ncol = n_species)
centers_x <- runif(n_species, 0, 100)
centers_y <- runif(n_species, 0, 100)
for (sp in seq_len(n_species)) {
dists <- sqrt((coords$x - centers_x[sp])^2 +
(coords$y - centers_y[sp])^2)
prob <- exp(-dists / 30)
species[, sp] <- rpois(n_sites, lambda = prob * 3)
}
colnames(species) <- paste0("sp", seq_len(n_species))species is a 60 by 25 matrix of abundances and
coords holds the site positions in columns x
and y.
Building the curve to test
ses() reruns an existing analysis on each randomised
matrix, so it starts from a fitted object. Ten seeds give a stable mean
curve and keep the permutation loops fast.
sac <- spacc(species, coords, n_seeds = 10, progress = FALSE)Testing against the curveball null
ses() takes the
spacc object together with the species matrix and
coordinates, because a spacc object does not store the raw
matrix. The curveball algorithm (Strona et al. 2014) holds
both row totals (site richness) and column totals (species frequency)
fixed while shuffling which species occur together. It tests whether the
spatial arrangement of species, beyond their marginal totals, drives the
observed curve. Nineteen permutations keep this illustration fast; Practical guidance explains why a real
test needs many more.
result <- ses(sac, species, coords,
null_model = "curveball", n_perm = 19,
progress = FALSE, seed = 1)
print(result)
#> Standardized Effect Size (SES)
#> ------------------------------------
#> Input class: spacc
#> Metric: richness
#> Null model: curveball (19 permutations)
#> SES range: [-5.37, 0.42]
#> Mean SES: -0.54
#> Significant (p < 0.05): 0 / 60 values (0%)The SES curve traces the effect size along the accumulation steps. The dashed lines mark \(\pm 1.96\), the solid line marks zero, and steps with a permutation p-value below 0.05 are highlighted in red.
plot(result, type = "curve")The SES is 0 at the first step, falls to about \(-5.4\) by the fifth step, is back near zero at the twelfth and is 0 from the thirteenth on, so over the first eleven steps observed richness accumulates more slowly than the curveball null predicts. When a species occupies a compact patch, the nearby sites that the accumulation visits early carry redundant occurrences of it, and fewer new species appear than in a community with shuffled co-occurrences. Once the observed and the randomised curves have found all 25 species, they agree and the deficit disappears.
Where the null curves do not vary, ses() sets the SES to
0. This happens at the first step, because the curveball null keeps the
richness of every site and the first step counts the species of the
starting sites, and at every step after all 25 species are found. The
mean SES printed above averages over all 60 steps, 49 of which are
0.
The histogram collects the SES values of all accumulation steps, with the same \(\pm 1.96\) reference lines.
plot(result, type = "histogram")The tall bar at zero holds the steps where all curves agree, and the steps of the deficit form a tail past \(-1.96\). With 19 permutations the smallest attainable two-tailed p-value is \(2/20 = 0.1\), so no step can reach \(p < 0.05\) however extreme its SES, as the printed count of significant steps shows. That limit comes from the permutation count and says nothing about the strength of the pattern.
Comparing null models
The conclusion of a null-model test depends on what the null holds
fixed. The frequency null shuffles each species column
independently. It preserves species frequencies but breaks site richness
and all co-occurrence structure, and asks whether composition matters
given the observed frequencies.
res_freq <- ses(sac, species, coords,
null_model = "frequency", n_perm = 19,
progress = FALSE, seed = 1)
steps <- 1:12
round(rbind(curveball = result$ses[steps],
frequency = res_freq$ses[steps]), 1)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#> curveball 0 -1.4 -4.1 -4.2 -5.4 -4.5 -4.5 -2.4 -3.3 -0.9 -1.9 0.4
#> frequency 1 0.9 -1.6 -2.6 -4.1 -2.4 -3.2 -1.4 -1.7 0.0 -0.3 0.5Both nulls show the deficit from the third step on, and the
frequency null gives the smaller effect sizes on this
community. The standard deviations of the null curves show why.
round(rbind(curveball = result$null_sd[steps],
frequency = res_freq$null_sd[steps]), 2)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#> curveball 0.00 0.33 0.37 0.33 0.27 0.19 0.18 0.15 0.10 0.06 0.04 0.04
#> frequency 0.97 0.77 0.54 0.41 0.31 0.28 0.22 0.18 0.15 0.12 0.09 0.06By breaking site richness, the frequency null lets the
randomised curves vary more: their standard deviation is 0.97 species at
the first step, where the curveball curves do not vary at
all. The same deficit is then fewer null standard deviations away. A
pattern that survives the curveball test leaves fewer
alternative explanations open, because that null already reproduces the
richness of every site and the frequency of every species.
Choosing a null model
The null model is the substance of the test. A null randomises some features of the species matrix and pins others, and the pinned features define what the test cannot detect. Holding species frequencies fixed but shuffling their placement asks whether composition is spatially structured given those frequencies. Fixing both row and column totals asks the stricter question of whether species co-occur more or less often than expected once richness and frequency are both accounted for. Spatial nulls preserve autocorrelation, so they test for structure beyond what proximity alone explains. Two nulls applied to the same data can disagree, and the disagreement localises which feature of the matrix carries the signal. An SES reported without its null model is as incomplete as a p-value without its test statistic.
null_model |
Holds fixed | Tests |
|---|---|---|
"frequency" |
species frequencies (column totals) | whether composition matters given the frequencies |
"richness" |
site richness (row totals) | whether species identity matters given site richness |
"both" |
both totals, by independent swaps (Gotelli 2000) | non-random co-occurrence |
"curveball" |
both totals, by the curveball algorithm (Strona et al. 2014) | non-random co-occurrence |
"torus" |
spatial autocorrelation, by a random toroidal shift of the coordinates | structure beyond proximity |
"spatial_swap" |
both totals, with swaps restricted to nearby site pairs | co-occurrence given spatial structure |
"shift_rotate" |
the community; moves the user-supplied focal points of a
method = "knn" design (Ridder et al. 2024) |
whether the curve depends on where the fixed design sits |
The three spatial nulls need coordinates. ses() accepts
most spacc curve objects (spacc, spacc_hill,
spacc_phylo, spacc_func,
spacc_beta, spacc_metrics,
spacc_alpha, spacc_partition), and
metric picks one curve from a multi-metric object.
The null models answer one of three complementary questions about turnover; the other two are measured in Measuring distance decay and zeta diversity.
| Approach | Question | Key output | Reads turnover via |
|---|---|---|---|
| Distance decay | How fast does similarity decline with distance? | Decay rate, half-distance, AIC-best model | Pairwise dissimilarity against distance |
| Zeta diversity | Stochastic or niche-driven multi-site turnover? | Zeta decline, ratio, exponential and power-law fit | Species shared across \(k\) sites |
| SES null models | Is the pattern non-random? | SES, p-value, null model | Observed against randomised accumulation |
On this community the three agree: distance decay, exponential zeta decline and negative richness SES describe moderate, stochastic turnover driven by spatial aggregation rather than niche partitioning.
Practical guidance
Permutation count. The smallest two-tailed p-value a permutation test can return is \(2/(n_{\text{perm}} + 1)\). With 19 permutations the floor is \(p = 0.1\) and nothing can clear 0.05, as in the example above. With 99 permutations the floor is 0.02, which resolves 0.05 but leaves p-values coarse; use at least 199 to resolve \(p < 0.05\) reliably. Use 999 (the default) for any result that will be reported, and treat anything under 199 as a check that the code runs.
Minimum sites. SES on an accumulation curve needs enough sites for the curve to have shape, roughly 20 or more.
| If the goal is to … | Use | Watch out for |
|---|---|---|
| Test richness against co-occurrence | ses(null_model = "curveball") |
Too few n_perm caps the p-value |
| Test composition given frequencies | ses(null_model = "frequency") |
Breaks richness totals, so a richness gradient is part of what it tests |
SES null models should not carry the headline when the marginal
totals themselves are the pattern of interest. A null that holds
richness fixed cannot detect a richness gradient, so a
curveball SES near zero does not rule out structure in the
marginals that a frequency or richness null would expose. Match the null
to the hypothesis, and name the model next to every SES value.
References
Gotelli, N.J. (2000). Null model analysis of species co-occurrence patterns. Ecology, 81, 2606-2621.
Phipson, B. & Smyth, G.K. (2010). Permutation p-values should never be zero: calculating exact p-values when permutations are randomly drawn. Statistical Applications in Genetics and Molecular Biology, 9(1). https://doi.org/10.2202/1544-6115.1585
Ridder, G., Hardy, O.J. & Ovaskainen, O. (2024). Generating spatially realistic environmental null models with the shift-&-rotate approach helps evaluate false positives in species distribution modelling. Methods in Ecology and Evolution, 15, 2331-2342. https://doi.org/10.1111/2041-210X.14443
Strona, G., Nappo, D., Boccacci, F., Fattorini, S. & San-Miguel-Ayanz, J. (2014). A fast and unbiased procedure to randomize ecological binary matrices with fixed row and column totals. Nature Communications, 5, 4114.