In this tutorial we describe two simple scripts in R to generate random virtual species, and to calculate species distribution models (SDM's) using ensemble models.
Those scripts may be useful to test hypotesis, or to work with ModestR or other tools
Similar to 21.- Creating virtual species and calculating simple ensemble models with R (that can be later used with Version ModestR 5.6 or higher) (20)
21.- Creating virtual species and calculating simple ensemble models with R (that can be later used with Version ModestR 5.6 or higher)
1. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Step by step tutorial:
Creating virtual species and
calculating simple ensemble
models with R
(that can be later used with ModestR)
2. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
What do you need for this tutorial:
1. R version 3.4.0 of higher installed
2. Internet connection
3. About 25 minutes
R software can be freely downloaded from https://www.r-project.org/
3. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
We’ll describe a simple script to create
random virtual species in R.
We’ll also describe a simple script to
calculate to perform species distribution
modelling with ensemble models in R
Follow the next steps!
4. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
First of all, download the zip file from this link and decompress it.
You’ll find two scripts:
5. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Open R console or any other user interface tool for R.
We recommend for example Rwizard (http://www.ipez.es/RWizard/)
Then open the script “Simple Virtual Species.R”
1) Go to menu “File/Open Script” then select the
downloaded script file “Simple virtual Species.R”
6. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
As you can see at the beginning of the script, it uses the packages raster, rgdal, virtualspecies and dismo. Therefore you
have to install them if you haven’t done it yet. To install packages in R, go to “Packages/Install packages” menu.
You need to have those packages
installed in R
7. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Following down in the script, there is a section with all the relevant parameters that you have to set to customize it to your
needs. The first part of those parameters concern the folders to be used and the format of the output:
Set in this parameter the CSV format you want
for the output (English-like or Spanish-like)
Set in this parameter the folder where
results will be stored. If the folder does not
exist, the script will create it
Set in this parameter the folder where the environmental
variables to be used to generate virtual species can be
found. They can be, for example, those from WorldClim,
NOOA, Bio-Oracle, etc…
They should be in raster format (geoTiff, ASC, GRD, etc.)
Each parameter is preceded
by an explanatory comment
8. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The next parameters are related to the geographical extent to be used, the number of virtual species to create, etc.
Set in this parameter the coordinates of the rectangle that
defines the work area. The coordinates must be passed in this
order:
min_longitude, max_longitude, min_latitude, max_latitude
To use the whole available extent covered by the environmental
variables, comment this line.
Set in this parameter the number
of virtual species to be generated
Set in this parameter the number of variables to be used to
generate each virtual species. Those variables will be randomly
selected for each species among the available variables. For
each variable a response function will be randomly selected
among linear, logistic and normal functions.
9. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The next parameters are related to the number of occurrences wanted.
Set in those parameters the range of prevalence of the species to be
generated. The prevalence for each species will be randomly chosen
between those limits.
To use the same prevalence for all species, specify the same value for
minimum and maximum.
Set in those parameters the range for the number of occurrences
you want to obtain for each species. The number of occurrences for
each species will be randomly chosen between those limits.
To obtain always an exact number of occurrences for each species,
specify the same value for minimum and maximum.
10. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The next parameters are related to the number of occurrences wanted.
Set in this parameter TRUE/FALSE depending if you want to
allow duplicate occurences. That is, if multiple samples can
occur in the same cell. This can be useful to mimic real datasets
where samplings can be duplicated or repeated in time.
Set in this parameter to TRUE species suitability will be used to
increase the likehood of sampling in areas with high suitability.
If false, no bias will be used.
Set in this parameter TRUE to rescale all environmental
variables to 0-1. FALSE otherwise. As response functions such
as "dnorm" (normal) will be used expecting a [0-1] range it is
recommend to set it to TRUE
11. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Once those parameters set according to you needs, you can run the script! This can be done in the Rgui going to the menu
Edit/Run All. Once the work ends, you can see in the console window a report of the virtual species created.
12. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Let’s see now the results. You can find them in the folder you indicated in the OUTPUTFOLDER parameter.
This folder will contains that:
13. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The Suitability folder contains the suitability map for each species in ASC raster format. Those rasters can be visualized in
any GIS tool, or in ModestR MapMaker, for example, using the menu “Layers/Rasters/Load Raster from ESRI/ASC”.
The values in the suitability map of a species ranges from 0 (unsuitable areas) to 1 (totally suitable areas)
In ModestR MapMaker the
raster is displayed like this
14. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The Presence folder contains the presence/absence map for each species in ASC raster format. Those rasters can be
visualized in any GIS tool, or in ModestR MapMaker, for example, using the menu “Layers/Rasters/Load Raster from
ESRI/ASC”.
The values in the the presence/absence map of a species are 0 (absence) or 1 (presence)
In ModestR MapMaker the
raster is displayed like this
15. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The Report.CSV file contains the list of variables used to generate each virtual species
16. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The VirtualSpeciesOccurrences.CSV contains the occurrences generated for all virtual species. This file may be used to
calculate species distribution models (SDM), as we’ll see next.
17. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Let’s see now how to generate species distribution models (SDM’s) using the script Simple Ensemble models SSMD.R,
which uses the SSDM package.
To do that, in this tutorial we’ll use the virtual species we’ve generated previously.
First of all, load the script in R.
1) Go to menu “File/Open Script” then select the
downloaded script file “Simple Ensemble models SSMD.R”
18. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
As you can see at the beginning of the script, it uses the packages SSDM, sp and raster. Therefore you have to install them
if you haven’t done it yet. To install packages in R, go to “Packages/Install packages” menu.
You need to have those packages
installed in R
19. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Following down in the script, there is a section with all the relevant parameters that you have to set to customize it to your
needs. The first part of those parameters concern the folders to be used and the format of the output:
Set in this parameter the CSV format you want
for the output (English-like or Spanish-like)
Set in this parameter the folder where
results will be stored. If the folder does not
exist, the script will create it
Each parameter is preceded
by an explanatory comment
Set in this parameter the folder where the environmental
variables to be used to generate virtual species can be
found. They can be, for example, those from WorldClim,
NOOA, Bio-Oracle, etc…
They should be in raster format (geoTiff, ASC, GRD, etc.)
20. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The next parameters are related to the geographical extent to be used, the location of the occurrences file and the models
to be used.
Set in this parameter the file (with the full pathname) where the species
occurrences to be used are. For this tutorial you can use the occurrences file
generated previously for the virtual species
Set in this parameter the coordinates of the rectangle that defines the work
area. The coordinates must be passed in this order:
min_longitude, max_longitude, min_latitude, max_latitude
To use the whole available extent covered by the environmental variables,
comment this line
Set in this parameter the models to be used for the ensemble modelling.
The list of available models is enumerated in the comment below. But you can
also see the help for the "ensemble_modelling" function from the SSDM
package for details.
21. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Once those parameters set according to you needs, you can run the script!
This can be done in the Rgui going to the menu Edit/Run All
22. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
Let’s see now the results. You can find them in the folder you indicated in the OUTPUTFOLDER parameter.
This folder will contains that:
23. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The tmp folder contains the output of the “ensemble_modelling” function for each species.
See the help for the "ensemble_modelling" function from the SSDM package for details.
24. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
The OUTPUTFOLDER contains the estimated suitability rasters for each species (not to be confused with the suitability rasters seen
before in this tutorial for the virtual species; the former ones where directly generated using response functions and complete information from
environmental variables; the later ones are estimations of suitability of a species using partial information about the species presence).
Those rasters can be used for different purposes, such as:
• Estimating species composition in one or more regions with KnowBR and ModestR (see tutorial 18 in
http://www.ipez.es/ModestR/Manual_Tutorial.html)
• Importing those suitability rasters to MapMaker or to DataManager , transforming them in species distributions by
selecting a suitability threshold. This feature is explained in the ModestR user manual
(http://www.ipez.es/ModestR/Manual_Tutorial.html)
In ModestR MapMaker the
raster is displayed like this
25. MODESTR QUICK TUTORIALS HTTP://WWW.IPEZ.ES/MODESTR/
It was the Step by step tutorial:
Creating virtual species and calculating simple
ensemble models with R
Thank you for your interest.
You can find this one and other tutorials in http://www.ipez.es/ModestR
By the ModestR team