View source: R/create_env_nsets.R
create_env_nsets | R Documentation |
Essentially a wrapper around create_env_set
. Each
set of environmental variables (can be just 1 variable) that are related
but have some random variation between them. The first variable is
generated using unconditional Gaussian simulation using a variogram model
with the specified model and psill parameter, using
vgm
from the gstat
package, plus a random
range value extracted using the specified distribution. New conditional
Gaussian simulations are then made for subsequent variables using a random
subsample of cells from the first variable plus a new random range value.
Each set starts from a newly generated base variables.
create_env_nsets( cellDims = c(100, 100), sets = c(5, 4, 3, 1), model = "Sph", psill = 1.5, dep1 = 1, rangeFun = "vrangeFun", propSamp = 0.25 )
cellDims |
vector containing variable dimensions (n cell width, n cell height) |
sets |
a vector with the number of variables for each set (generated by
|
model |
model for variogram; default = "Sph" (see
|
psill |
(partial) sill of the variogram model; default = 1.5 (see
|
dep1 |
multiplied by the psill in submodels (default = 1) |
rangeFun |
name of function, or specified function, to generate random number for the range parameter of the variogram model. E.g. function() exp(runif(1, 1, 6)) |
propSamp |
proportion of cells to sample for each submodel (default = 0.5) |
The model and psill are kept constant across all variables, but a new range value is drawn from the specified distribution each time. The distribution is specified using a user-generated function. The user can either input the name of the function or define the function as the argument.
Subsequent variables are generated based on a random sample of the 1st
variable. The number of cells selected is defined by propsamp
; the
larger the value the more similar the new variable will be to the original.
The psill and model type of the variogram is kept constant across all new
variables, although the psill can be altered using the parameter
dep1
, which is multiplied by the psill of the first variable (must
be >0 and <2; default = 1).
A raster stack of environmental variables. For each variable all values are standardised between 0 and 1. The name of each raster relates to the number of the variable set, and then the number of the variable within that set.
Charlie Marsh (charlie.marsh@mailbox.org) & Yoni Gavish, based on the original code from http://santiago.begueria.es/2010/10/generating-spatially-correlated-random-fields-with-r/
Variations on this method have been used to generate virtual species in:
Gavish, Y., Marsh, C.J., Kuemmerlen, M., Stoll, S., Haase, P., Kunin, W.E., 2017. Accounting for biotic interactions through alpha-diversity constraints in stacked species distribution models. Methods in Ecology and Evolution 8, 1092–1102. https://doi.org/10.1111/2041-210X.12731
Marsh, C.J., Gavish, Y., Kunin, W.E., Brummitt, N.A., 2019. Mind the gap: Can downscaling Area of Occupancy overcome sampling gaps when assessing IUCN Red List status? Diversity and Distributions 025, 1832–1845. https://doi.org/10.1111/ddi.12983
### generate 3 sets of related variables. ### set1 = 4 variables; set 2 = 3 variables; set 3 = 1 variable # the sampling distribution for range can either be a saved function vrangeFun <- function() exp(runif(1, 1, 6)) envSet <- create_env_nsets(cellDims = c(100, 100), sets = c(4, 3, 1), model = "Sph", psill = 1.5, dep1 = 1, rangeFun = vrangeFun, propSamp = 0.25) # or we can define the function within the argument itself envSet <- create_env_nsets(cellDims = c(100, 100), sets = c(4, 3, 1), model = "Sph", psill = 1.5, dep1 = 1, rangeFun = function() 100 + runif(1, -100, 100), propSamp = 0.05) # the output is a raster stack which can be plotted plot(envSet)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.