Generate a random virtual species distribution from environmental variables
Description
This function generates randomly a virtual species distribution.
Usage
1 2 3 4 5 6  generateRandomSp(raster.stack, approach = "automatic", rescale = TRUE,
convert.to.PA = TRUE, relations = c("gaussian", "linear", "logistic",
"quadratic"), rescale.each.response = TRUE, realistic.sp = TRUE,
species.type = "multiplicative", niche.breadth = "any",
sample.points = FALSE, nb.points = 10000, PA.method = "probability",
alpha = 0.1, beta = "random", species.prevalence = NULL, plot = TRUE)

Arguments
raster.stack 
a RasterStack object, in which each layer represent an environmental variable. 
approach 

rescale 

convert.to.PA 

relations 
[response approach] a vector containing the possible types of response function.
The implemented type of relations are 
rescale.each.response 

realistic.sp 
[response approach] 
species.type 
[response approach] 
niche.breadth 
[pca approach] 
sample.points 
[pca approach] 
nb.points 
[pca approach] a numeric value. Only useful if 
PA.method 

alpha 

beta 

species.prevalence 

plot 

Details
This function generate random virtual species, either using a PCA approach, or using a response approach. In case of a response approach, only four response functions are currently used: gaussian, linear, logistic and quadratic functions.
Note that in case of numerouse predictor variables, the "response" approach will not work well because it will often generate contradicting response functions (e.g., mean annual temperature optimum at degrees C and temperature of the coldest month at 10 degrees C). In these case, it is advised to use the PCA approach (by default, a PCA approach will be used if there are more than 6 predictor variables).
If rescale.each.response = TRUE
, then the probability response to each
variable will be normalised between 0 and 1 according to the following formula:
P.rescaled = (P  min(P)) / (max(P)  min (P)). Simlarly, if rescale = TRUE
,
the final environmental suitability will be rescaled between 0 and 1 with the same formula.
By default, the function will perform a probabilistic conversion into presence absence, with a randomly chosen beta threshold. If you want to custmose the conversion parameters, you have to define two of the three following parameters:
beta
: the 'threshold' of the logistic function (i.e. the inflexion point)alpha
: the slope of the logistic functionspecies.prevalence
: the proportion of sites in which the species occur
If you provide beta
and alpha
, the species.prevalence
is calculated immediately calculated after conversion into presenceabsence.
As explained in convertToPA
, if you choose choose a precise
species.prevalence
, it may not be possible to reach this particular
value because of the availability of environmental conditions. Several
runs may be necessary to reach the desired species.prevalence
.
Value
a list
with 3 to 5 elements (depending if the conversion to presenceabsence was performed):
approach
: the approach used to generate the species, i.e.,"response"
details
: the details and parameters used to generate the speciessuitab.raster
: the virtual species distribution, as a Raster object containing the environmental suitability)PA.conversion
: the parameters used to convert the suitability into presenceabsencepa.raster
: the presenceabsence map, as a Raster object containing 0 (absence) / 1 (presence) / NA
The structure of the virtualspecies can object be seen using str()
Author(s)
Boris Leroy leroy.boris@gmail.com
with help from C. N. Meynard, C. Bellard & F. Courchamp
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  # Create an example stack with six environmental variables
a < matrix(rep(dnorm(1:100, 50, sd = 25)),
nrow = 100, ncol = 100, byrow = TRUE)
env < stack(raster(a * dnorm(1:100, 50, sd = 25)),
raster(a * 1:100),
raster(a * logisticFun(1:100, alpha = 10, beta = 70)),
raster(t(a)),
raster(exp(a)),
raster(log(a)))
names(env) < paste("Var", 1:6, sep = "")
# More than 6 variables: by default a PCA approach will be used
generateRandomSp(env)
# Manually choosing a response approach
generateRandomSp(env, approach = "response")
# Randomly choosing the approach
generateRandomSp(env, approach = "random")
