asc_null: Null Models for Multi-Layer Functional Shifts

View source: R/asc_null.R

asc_nullR Documentation

Null Models for Multi-Layer Functional Shifts

Description

Tests each ASC-CFD layer (position, dispersion, volume) against two complementary null models, and dispatches on the class of x:

  • objects from asc_paired (class ascent_paired) get one set of tests per contrast (reference vs comparison);

  • objects from asc_pairwise (class ascent_pairwise) get a single global test over all communities at once (no p-value per pair).

The letters differ from version 0.1.x: A is now the sampling null model and B the stratified trait null model. The 0.1.x models (Curveball, SAD reshuffle and trait shuffle), written A0, B0 and C0 since 0.5.0, were removed.

Usage

asc_null(
  x,
  n_perm = 999,
  seed = NULL,
  stratum_size = 5,
  entities = NULL,
  two_sided = c("centred", "doubled"),
  p_adjust = "BH"
)

Arguments

x

An object of class ascent_paired (from asc_paired) or ascent_pairwise (from asc_pairwise). Objects created with ascent 0.5.0 (classes ascfcd and ascfcd_pw) are accepted.

n_perm

Integer. Number of permutations. Default is 999. When the number of possible allocations of samples is at most n_perm, all of them are used instead (exact test).

seed

Integer or NULL. If given, results are reproducible and the user's random number stream is left unchanged.

stratum_size

Integer. Number of species per abundance stratum in null model B. Default 5 (the validated value). Strata group species of similar abundance; larger values approach the unstratified permutation.

entities

Optional. An object from asc_entities or a named vector (names = species) giving each species' entity.

two_sided

Character. Convention for the two-tailed p-value of dispersion and volume (see Two-tailed p-values): "centred" (default) or "doubled".

p_adjust

Character. Method used to adjust the p-values of the three layers within each contrast and test (see Multiple testing). One of stats::p.adjust.methods; default "BH" (Benjamini and Hochberg, 1995). "none" keeps them unadjusted.

Value

The input object with null_models appended: a data frame with one row per contrast, test and layer, and columns Contrast, Test, Layer, Observed, Null_mean, Null_sd, SES, P_upper, P_lower and P_two (two-tailed, with the convention set by two_sided), and P_adj (the p-value used for interpretation, adjusted with p_adjust). P-values are (b + 1)/(n + 1) and are not rounded. For B, the row of position refers to the axis-standardised statistic (Observed, Null_mean, Null_sd, SES and the p-values). b_position_norm gives B for position with the statistic of 0.5.0 (||\Delta C||, or the mean distance to the common centroid in the global test), one row per contrast. trait_shifts (see Which trait changed) gives, per contrast, Trait, Type ("numeric" or "level"), Delta and Std_shift, ordered by |Std_shift|; in the global test Delta is the standard deviation among communities of the weighted mean of the trait and Std_shift its variance relative to the null mean. For pairwise objects, site_contribution is also appended. null_settings records the options used and, in permutation, how samples were permuted for A in each contrast (design, number of blocks, number of possible allocations, exact enumeration or not, and the smallest attainable p-value for position). Use summary() for a reading of each test.

Null model A (sampling)

H0: the communities are samples of the same community. Individuals are pooled and reassigned at random keeping sample sizes. When both states of a contrast have replicates, whole replicates are permuted instead (A by samples), which accounts for variation among replicates (individuals that are captured in groups inflate A by individuals). If the samples of both states were taken in matched units (blocks in asc_paired), samples are exchanged only within each block. A needs counts of individuals; with relative abundances it is skipped with a warning.

Choosing the permutation for A

The permutation is chosen from the design described in asc_paired; summary() reports which one was used.

  • One sample per state: A by individuals. It tests multinomial sampling error only; ordinary variation between samples (e.g. between two months of the same community) can look like a change. Use replicates whenever possible.

  • Replicates taken in matched units (both states sampled in the same months, plots or survey rounds): give that unit as blocks in asc_paired(). Samples are exchanged between states only within each block, so effects shared by the samples of a block (weather of a month, a survey round) are removed from the test. Blocks do not correct temporal autocorrelation within the series of each state: in the validation, with month-to-month persistence like that of the butterfly data (rho = 0.28), A within blocks still gave 6-16\ pseudoreplication.

  • Independent replicates (spaced in time or space, not matched): free permutation of whole samples (no blocks).

  • Consecutive replicates (e.g. consecutive months of each state, matched or not): they are not independent (pseudoreplicates). No permutation removes this dependence; A, like PERMANOVA and other tests that permute samples, becomes liberal (9.7-17\ validation). Space the samples in time or treat the p-values as indicative.

When the number of possible allocations of samples is at most n_perm, all of them are enumerated (exact test). With blocks, there are \prod_j \binom{n_j}{r_j} allocations (n_j samples in block j, r_j of them in the reference state); with one sample of each state per block, 2^{B} for B blocks. Ask for n_perm at least that large to enumerate them. Few blocks give few allocations: with four matched pairs there are 16, and the smallest attainable p-value for position is 0.125, so the test cannot reject at alpha = 0.05 (a warning is given).

Null model B (traits, stratified)

H0: the shift does not depend on which traits the species have. Abundances are kept and species coordinates are permuted only among species of similar abundance (groups of stratum_size species ranked by mean abundance). Stratification calibrates the test in empirical trait spaces; it does not add power. stratum_size = Inf gives the unstratified permutation among the species present, which was biased in empirical trait spaces and is not recommended; values near 5 (e.g. 3 to 10) can be used to check that conclusions do not depend on the stratum size.

B is read from its upper tail: the shift is larger than expected if traits were unrelated to the change in abundances, i.e. the change is directed by traits. Read B where A detects a change. The lower tail (a shift smaller than expected from the traits) is reported for description only: it had little power to detect compensation in the validation.

For position, the statistic of B is axis-standardised: the shift of the centroid along each axis is divided by its standard deviation under the null and the squares are summed over axes (\sum_k (v_k / s_k)^2, about the number of axes when there is no change). Each axis counts in units of its own chance variation, so a change along a minor axis (a trait unrelated to the first axis) is detected as well as one along the first axis. With the length of the shift, ||\Delta C|| (the statistic up to 0.5.0), the first axis dominated and changes in minor traits were rarely detected; the price of the new statistic is somewhat less power when the change lies along the first axis. B with ||\Delta C||, from the same permutations, is kept in b_position_norm; with the same seed the permutations are those of 0.5.0.

In the validation, B was slightly liberal for dispersion (6.5\ positives at alpha = 0.05), when individuals are captured in groups (7.2\ changes (about 7-8\ 0.05 with caution.

Which trait changed

The same permutations of B give, for each trait, the change of its abundance-weighted mean, returned in trait_shifts; summary() names the trait with the largest standardised shift. Numeric traits are used as they are (Delta in the units of the trait). Each level of a categorical trait (factor, character or logical) is used as a 0/1 indicator, named "trait = level" (only the second level when there are two), so its Delta is the change in the share of abundance of species with that level. Std_shift is the shift in null standard deviations: values of about 1 or less are within chance variation. This describes which trait moved most; it is not a test (no p-value is given: in the validation, with numeric traits, its maximum was liberal under changes not related to traits, and it has not been evaluated with categorical traits). Traits that are correlated move together, so it points to a group of related traits, not necessarily to the trait that caused the change. Missing values are set to the mean of the trait.

Entities

With entities (from asc_entities or a named vector assigning each species to an entity), A is repeated on counts summed by entity. This is exploratory. "A significant for species but not for entities", together with a large fraction of the shift occurring within entities (asc_transitions), is consistent with replacement among functionally similar species. Only replacement within an entity is seen: similar species placed in different entities look like a change between entities, so a negative result does not rule out redundancy. In the validation the signal was weak except for strong compensation, and it depends on the number of entities; check neighbouring values of k.

Global test (pairwise objects)

With many communities, one test per pair would multiply false alarms, so asc_null() runs one global test per layer over all communities. Statistics: the mean distance of the community centroids to their common centroid (position), and the standard deviation among communities of FDis (dispersion) and FRic (volume). A global reassigns individuals among communities; B global applies one stratified trait permutation to all communities. All layers are read from the upper tail. A: the communities differ more than samples of one community would. B: the variation among communities is organised by traits. The lower tail of B is reported for description only. For position, B global uses the axis-standardised statistic: the variance of the community centroids along each axis divided by its mean under the null, summed over axes (with two communities it is equivalent to the paired statistic); B with the mean distance (as in 0.5.0) is kept in b_position_norm. The distance of each community to the common centroid is returned as a descriptive contribution (site_contribution).

Multiple testing

Each test (A, B, A by entities, and each global test) evaluates three layers, so P_adj adjusts, within each contrast and test, the three p-values used for interpretation: the upper tail for position (and for all layers of the global test) and the two-tailed value for dispersion and volume. The method is chosen with p_adjust (any method of p.adjust; default Benjamini-Hochberg). Contrasts are not adjusted against each other; to do so, apply p.adjust to the column of p-values of interest in null_models. The lower tail is not adjusted.

Two-tailed p-values

Dispersion and volume can change in either direction, so they are read with a two-tailed p-value, P_two. Two conventions are available (argument two_sided):

  • "centred" (default, as in 0.5.0): the proportion of null values at least as far from the null mean as the observed value.

  • "doubled": twice the smaller tail, pmin(1, 2 * pmin(P_upper, P_lower)), which judges each direction against its own tail.

Both are valid; they coincide when the null distribution is symmetric and can differ when it is asymmetric, as is common for the volume (FRic). Both tails are always reported, so either convention can be computed from the table. Choose the convention before looking at the results.

References

Benjamini, Y., & Hochberg, Y. (1995). Controlling the false discovery rate: a practical and powerful approach to multiple testing. Journal of the Royal Statistical Society B, 57, 289-300.

Gower, J. C. (1971). A general coefficient of similarity and some of its properties. Biometrics, 27, 857-871.

Examples


# Paired contrasts (see ?birds_sim): five surveys per state at each site
res <- asc_paired(birds_sim$traits, birds_sim$counts,
                  sites = birds_sim$samples$site,
                  time = birds_sim$samples$time, ref_time = "Before")
res <- asc_null(res, n_perm = 199, seed = 1)

# The Reading column interprets each test. At "Logged", A (sampling) and
# B (traits) detect the shift in position: the change is real and directed
# by the species' traits. At "Control" there is no evidence of change.
summary(res)

# The full table (one row per contrast, test and layer)
res$null_models[res$null_models$Layer == "Position", ]

# Which trait moved most at each site (descriptive)
res$trait_shifts

# Matched samples: if the k-th survey of both states had been made in the
# same survey round, the rounds would be given as blocks. With only five
# matched pairs the smallest attainable p-value for position is 2/32, so
# asc_null() warns that A cannot reject at 0.05 (six pairs are the minimum)
round <- ave(seq_along(birds_sim$samples$site),
             birds_sim$samples$site, birds_sim$samples$time, FUN = seq_along)
rb <- asc_paired(birds_sim$traits, birds_sim$counts,
                 sites = birds_sim$samples$site,
                 time = birds_sim$samples$time, ref_time = "Before",
                 blocks = round)
rb <- asc_null(rb, n_perm = 99, seed = 1)
rb$null_settings$permutation

# Many communities: one global test per layer instead of one p per pair
pw <- asc_pairwise(birds_sim$traits, birds_sim$landscape)
pw <- asc_null(pw, n_perm = 99, seed = 1)
summary(pw)



ascent documentation built on Nov. 30, 2026, 1:07 a.m.