# A brief tutorial on Ecological Niche Modelling

Bruno M. Carvalho

Barcelona Supercomputing Center

e-mail: [bruno.carvalho@bsc.es](mailto:bruno.carvalho@bsc.es)

ORCID: [0000-0002-0009-5770](https://orcid.org/0000-0002-0009-5770)

</br>

The objective of this short tutorial is to run a simple ecological niche model aimed at predicting the climatic suitability of a given species in a given country.

</br>

### Data used in this tutorial

- Species occurrence records: [GBIF](https://www.gbif.org/)

- Bioclimatic indicators: [WorldClim](https://www.worldclim.org/)

- World country borders: [Esri](https://hub.arcgis.com/datasets/esri::world-countries-generalized/about)

</br>

### Required R packages

- [CoordinateCleaner](https://cran.r-project.org/package=CoordinateCleaner)
- [leaflet](https://CRAN.R-project.org/package=leaflet)
- [sf](https://cran.r-project.org/package=sf)
- [raster](https://cran.r-project.org/package=raster)
- [dismo](https://cran.r-project.org/package=dismo)
- [readr](https://cran.r-project.org/package=readr)
- [dplyr](https://cran.r-project.org/package=dplyr)

</br>

### Before running the scripts

1. Choose a species and country that you want to use in this tutorial ([Google](https://www.google.com/) can help)

2. Navigate to [GBIF](https://www.gbif.org/) and register a username and password

3. Login and use the search engine to find the records for your chosen species:

![](./figs/readme1.png "Click on the species page")

</br>

4. Open the occurrence dataset:

![](./figs/readme2.png "Click on occurrences")

</br>

5. Filter results to your chosen country and go to the download page:

![](./figs/readme3.png "Filter to country of choice")

</br>

6. Download as a simple csv file:

![](./figs/readme4.png "Click on Simple")

</br>

Accept the Terms of Responsibility and proceed. Wait some minutes until the data finishes processing.  

You will receive an automatic email from GBIF when the data is ready for download. At this point, your dataset has a unique DOI which you can use to cite and re-download the data if you need it.  

When the data is ready for download, you can click on the button to download it:

![](./figs/readme5.png "Click on Download")

</br>

7. Unzip the downloaded csv file and move it to the folder "data/gbif/yourdataset.csv"

</br>

### Run each script in the following order

1. R/00_GHR_tutorial_gbif.R

2. R/01_data_harmonization.R

3. R/02_modelling.R
