Skip to contents

Makes layers that mean nothing to the species, to be modelled together with the real predictors in any software: a real predictor that gets no more importance than these is not informative (see compare_to_random()). Each random layer takes the values of one real layer, so it has exactly the same distribution of values (range, mean, skewness, ties) and the same cells without values, and arranges them anew:

Usage

random_variables(
  env,
  n = 5,
  method = c("field", "shuffle"),
  layers = NULL,
  range_km = NULL,
  seed = NULL,
  filename = "",
  overwrite = FALSE
)

Arguments

env

Predictor layers (terra::SpatRaster or file paths).

n

Number of random layers. They are made from the real layers in turn (the first from the first layer, and so on, starting again after the last), or from those named in layers.

method

"field" or "shuffle".

layers

Optional names of the real layers to imitate.

range_km

With method = "field": size of the patches (range of spatial autocorrelation, km). NULL = that of each imitated layer; one number = the same for all.

seed

Seed.

filename

Optional output file.

overwrite

Overwrite filename.

Value

A terra::SpatRaster with layers named random_1, random_2, ...; attr(, "source") says which real layer each one imitates.

Details

  • "field" (default): in smooth patches with the same range of spatial autocorrelation as the real layer (estimated as in suggest_block_size()). This is the fair comparison: real layers are smooth and records are clustered, so a smooth layer gains importance by chance far more easily than noise does.

  • "shuffle": cell by cell at random (white noise), the classic random variable. A real predictor will almost always beat it; use it only to compare with earlier work.

Limits. The field method reproduces the range of spatial autocorrelation estimated from a variogram, not the whole spatial structure: anisotropy and broad gradients of the real layers are not copied.

References

Fourcade, Y., Besnard, A.G., Secondi, J. (2018) Paintings predict the distribution of species, or the challenge of selecting environmental predictors and evaluation statistics. Global Ecology and Biogeography 27, 245-256. doi:10.1111/geb.12684

Examples

sim <- simulate_enm_data(seed = 1)
rnd <- random_variables(sim$env, n = 2, seed = 1)
terra::plot(c(sim$env, rnd))

# same values as the real layers, arranged differently
range(terra::values(rnd[[1]])) == range(terra::values(sim$env[[1]]))
#> [1] TRUE TRUE