---
title: "sdmApp package: A user-friendly application for species distribution modeling"
author: "Aboubacar HEMA, Babacar NDAO, Louise LEROUX, Abdoul Aziz DIOUF"
date: "`r Sys.Date()`"
output: 
  rmarkdown::html_vignette:
    fig_caption: yes
    toc: true
vignette: >
  %\VignetteIndexEntry{A user-friendly application for species distribution modeling}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
  
---

# Introduction and Main Features
*sdmApp* is a *R package* containing a *Shiny* application that allows non-expert *R* users to easily model species distribution. It offers a reproducible work flow for species distribution modeling into a single and user friendly environment. *sdmApp* takes *Raster* data (in format supported by the *Raster package*) and species occurrence data (several format supported) as input argument. This *package* provides an interactive graphical user interface (*GUI*).
 This document will give an overview of the main functionalities of the graphical user interface. The main features of the *GUI* is:

* Uploading data (*raster* and species occurrence files)
* View correlation between *raster*
* Use [CENFA](https://CRAN.R-project.org/package=CENFA) to select species predictors
* Apply a spatial blocking for cross-validation based on the [blockCV](https://CRAN.R-project.org/package=blockCV) package
* Apply species distribution models with or without a spatial blocking strategy 

* Export results
* Keep reproduce (*R* code) by being able do download the underlying code from *sdmApp*.

 The *GUI* is build around 5 main windows, which can be selected from the navigation bar at the top of the screen. Initially, some of these windows will be empty and their content changes once data (both *raster* and species occurrence files) have been uploaded.
 
# Installation 

The **sdmApp** is available both GitHub and **CRAN** . It is recommended to install the dependencies of the package.

To install the package from GitHub use:

```{r eval=FALSE}
remotes::install_github("Abson-dev/sdmApp", dependencies = TRUE)

```

Or installing from CRAN:

```{r eval=FALSE}
install.packages("sdmApp", dependencies = TRUE)
```



```{r eval=FALSE}
# loading the package
library(sdmApp)
```

```{r eval=FALSE}
# Graphical User Interface (GUI)
sdmApp()
```

# Package data

## Occurence data

It is a dataset of 9258 trees georeferenced encompassing 3 (*Faidherbia albida*,*Balanites aegyptiaca* and *Anogeissus leiocarpus*)
 species (Ndao et al., 2019).

## Environmental Variables

These are a suite of 34 variables
relating to  **bioclimatic drivers**, **soil properties**, **water productivity**, **vegetation phenology and productivity**, **watersheds topography**. We preprocessed the environmental
variables by setting them on the same projection system **(WGS 84, UTM, Zone 28N)**, cropping
them with the same extent and resampling them at the same spatial resolution of **250 m**.

### Bioclimatic variables

Bioclimatic variables are derived from the monthly temperature and
rainfall values in order to generate more biologically meaningful variables. They represent annual
trends (e.g., mean annual temperature, annual precipitation) seasonality (e.g., annual range in
temperature and precipitation) and extreme or limiting environmental factors (e.g., temperature of
the coldest and warmest month, and precipitation of the wet and dry quarters (1/4 of the year)).
The bioclimatic variables we used was extracted from the worldclim database version 2
(http://www.worldclim.com/). They are the average for the years 1970-2000 (Fick &amp; Hijmans,
2017) .

### Soil properties

We used 7 variables of soil properties from the ISRIC - World Soil Information
portal (https://www.isric.org/projects/soil-property-maps-africa-250-m-resolution). The dataset
results from the “Mapping soil properties of Africa at 250 m Resolution” produced from the
Africa Soil Information Service (AfSIS) project. Over 85 thousand samples (over 28 thousand
sampling locations), covering the Period 1950–2012, were used for spatial predictions of soil
properties (Hengl et al., 2015) .

### Water productivity

Two variables of water productivity were retrieved from the FAO WaPOR
database (https://wapor.apps.fao.org/home/1) i.e the Food and Agriculture Organization of the
United Nations (FAO) portal to monitor Water Productivity through Open access of Remotely
sensed derived data The Net biomass water productivity (NBWP) expresses the quantity of
output (total biomass production) in relation to the volume of water beneficially consumed
(through canopy transpiration) in the year, and thus net of soil evaporation. The actual
evapotranspiration and interception (AETI) represents the sum of the soil evaporation (E),
the canopy transpiration (T) and the interception (I) i.e the rainfall intercepted by the leaves
of the plants that will be directly evaporated from their surface (FAO, 2020) . NBWP and
AETI are also agrometeorological variables particularly useful in monitoring how effectively
vegetation uses water to develop biomass (NBWP) and for analyzing the soil-air interface and
plant functioning (AETI – WMO, 2012)

### Vegetation phenology and productivity

AFS were described as lanscapes with interactions
between crops, trees and crop practices. That is why we integrated two phenological metrics
related to the season of crop in order to take into account interactions with species distribution.
We derived the phenological metrics from normalized difference vegetation index (NDVI) time
series such as 16-day MODIS NDVI time series (MOD13Q1) using timesat software (Eklundh &amp;
Jönsson, 2011).

### Watersheds topography

Topographic variables were derived from the Soil &amp; Water
Assessment Tool (SWAT) using the 30 m NASA SRTM digital elevation model
(https://dwtkns.com/srtm30m/). SWAT is a small watershed to river basin-scale model used to
simulate the quality and quantity of surface and ground water and predict the environmental
impact of land use, land management practices, and climate change (https://swat.tamu.edu/). We
used the watershed delineator of SWAT which allows to delineate sub-watersheds within the
study area (Winchell et al., 2010) . We extracted 69 sub-basins in a vector file format with their
attribute table including topographic variables values.

# References:
- Bahn, V., & McGill, B. J. (2012). Testing the predictive performance of distribution models. Oikos, 122(3), 321–331.
   
- Hiemstra, P. H., Pebesma, E. J., Twenhöfel, C. J., & Heuvelink, G. B. (2009). Real-time automatic interpolation of ambient gamma dose rates from the Dutch radioactivity monitoring network. Computers & Geosciences, 35(8), 1711–1721.

- Hastie, T., Tibshirani, R., & Friedman, J. (2009). The elements of statistical learning: Data Mining, Inference, and Prediction (2nd ed., Vol. 1). Springer series in statistics New York.
   
- Leta, S., Fetene, E., Mulatu, T., Amenu, K., Jaleta, M.B., Beyene, T.J., Negussie, H., Revie, C.W., 2019. Modeling the global distribution of Culicoides imicola: an Ensemble approach. Sci. Rep. 9. [doi: 
10.1038/s41598-019-50765-1](https://doi.org/10.1038/s41598-019-50765-1)

- Luo, D., Silva, D.P., De Marco Júnior, P., Pimenta, M., Caldas, M.M., 2020. Model approaches to estimate spatial distribution of bee species richness and soybean production in the Brazilian Cerrado during 2000 to 2015. Sci. Total Environ. 737, 139674. [doi: 10.1016/j.scitotenv.2020.139674](https://doi.org/https://doi.org/10.1016/j.scitotenv.2020.139674)

- Mudereri, B.T., Abdel-Rahman, E.M., Dube, T., Landmann, T., Khan, Z., Kimathi, E., Owino, R., Niassy, S., 2020. Multi-source spatial data-based invasion risk modeling of Striga ( Striga asiatica ) in Zimbabwe. GIScience Remote Sens. 1–19. [doi: 10.1080/15481603.2020.1744250](https://doi.org/10.1080/15481603.2020.1744250)

- Ndao B., Leroux, L., Diouf, A.A., Soti, V., Sambou, B., 2019, A remote sensing based approach for optimizing sampling strategies in crop monitoring and crop yield estimation studies, in: Wade, S. (Ed.), Earth Observations and Geospatial Science in Service of Sustainable Development Goals, Southern Space Studies, Springer Nature Switzerland AG 2019, pp. 25–36,  [doi: 10.1007/978-3-030-16016-6_3](https://doi.org/10.1007/978-3-030-16016-6_3) 

- O’Sullivan, D., & Unwin, D. J. (2010). Geographic Information Analysis (2nd ed.). John Wiley & Sons.

- Phillips, S. J., Anderson, R. P., Dudík, M., Schapire, R. E., & Blair, M. E. (2017). Opening the black box: an open-source release of Maxent. Ecography.
   
- Roberts, D.R., Bahn, V., Ciuti, S., Boyce, M.S., Elith, J., Guillera-Arroita, G., Hauenstein, S., Lahoz-Monfort, J.J., Schröder, B., Thuiller, W., others, 2017. Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure. Ecography. 40: 913-929.

- Schindler, S., von Wehrden, H., Poirazidis, K., Hochachka, W.M., Wrbka, T., Kati, V., 2015. Performance of methods to select landscape metrics for modelling species richness. Ecol. Modell. 295, 107–112.[doi: 
10.1016/J.ECOLMODEL.2014.05.012](https://doi.org/10.1016/J.ECOLMODEL.2014.05.012)

- Simensen, T., Horvath, P., Vollering, J., Erikstad, L., Halvorsen, R., Bryn, A., 2020. Composite landscape predictors improve distribution models of ecosystem types. Divers. Distrib. 26, 928–943. [doi: 10.1111/ddi.13060](https://doi.org/10.1111/ddi.13060)

- Telford, R. J., & Birks, H. J. B. (2009). Evaluation of transfer functions in spatially structured environments. Quaternary Science Reviews, 28(13), 1309–1316.

- Thuiller, W., Georges, D., Engler, R., & Breiner, F. (2017). biomod2: Ensemble Platform for Species Distribution Modeling. R package version 3.3-7. https://CRAN.R-project.org/package=biomod2.

- Valavi R, Elith J, Lahoz-Monfort JJ, Guillera-Arroita G. blockCV: An R package for generating spatially or environmentally separated folds for k-fold cross-validation of species distribution models. *Methods Ecol Evol.* 2019; 10:225–232. [doi: 10.1111/2041-210X.13107](https://doi.org/10.1111/2041-210X.13107)
