### To estimate collinearity and corelation between rasters 

library(usdm)
library(raster)


#In your home directory you should all the rasters to evaluate 

#Set your home directory
setwd("~/Path")


#Load rasters 
Raster1<-raster("./Raster1.tif")
Raster2<-raster("./Raster2.tif")
Raster3<-raster("./Raster3.tif")
#...


#Create a stack 
Raster.stack<-stack(Raster1, Raster2, Raster3)
summary(Raster.stack)

writeRaster(Raster.stack, "./Path/RasterStack.tif", overwrite=TRUE )


#Paerson Correlations, missing data are removed
jnk=layerStats(Raster.stack, 'Pearson', na.rm = T) 


#Collinearity 
vifstep(Raster.stack, th=5, maxobservations=10000) 



