Running the analysis

Prepare raster layers for the projection in space and time

First load the necessary libraries and data

> library(biomod2)
> library(rgeos)
> library(raster)
> library(maptools)
> library(gtools)
>data(wrld_simpl)

and the training dataset and the bioclimatic layers (from training area) saved in module 2

> load("krameri.training")
> vars_training<-stack(mixedsort(list.files("predictors/", "gri", full.names=T)))

Then we create a second set of varibles for project at a global scale under current climatic conditions

> r <- getData("worldclim", var = "bio", res = 2.5)
> r<-r[[which(names(r)%in%names(vars_training))]]

For reasons of computational time we reduced the spatial resolution of the bioclimatic layers used for the projections from 5km to 25km.

> vars_proj<-stack(aggregate(r, 5, progress="text"))

Finally, we create a third set of bioclimatic variables to project our models at the global scale under future climate conditions (IPCC, 2013; downloaded from Worldclim).
We download and unzip the files creating a new folder named “future”:

> download.file("http://biogeo.ucdavis.edu/data/climate/cmip5/2_5m/cc85bi70.zip", "future.zip")
> unzip("future.zip", exdir="future")

Load layers:

> future<-stack(mixedsort(list.files("future","tif",full.names=T)))
> names(future)<-paste("bio", 1:19, sep="")
> future<-future[[which(names(future)%in%names(vars_training))]]

and downscale to 25 Km:

> future<-stack(aggregate(future, 5, progress="text"))


Now we are ready to fit the models