# 0. Load data & Selecting Data
# species occurances
species_occ <- read.csv(system.file("external/species/species_occ.csv",package="biomod2"))
# we consider only presences of MyocastorCoypus species
myRespName <- 'MyocastorCoypus'
myRespCoord <- species_occ[which(!is.na(species_occ[,myRespName])),c('x','y')]
myResp <- as.numeric(na.omit(species_occ[,myRespName]))
# Environemental variables extracted from BIOCLIM (bio_3, bio_4, bio_7, bio_11 & bio_12)
myExpl = raster::stack(system.file("external/climat/current/bio3.grd",package="biomod2"),
system.file("external/climat/current/bio4.grd",package="biomod2"),
system.file("external/climat/current/bio7.grd",package="biomod2"),
system.file("external/climat/current/bio11.grd",package="biomod2"),
system.file("external/climat/current/bio12.grd",package="biomod2"))
# 1. Formating Data
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,
expl.var = myExpl,
resp.xy = myRespCoord,
resp.name = myRespName,
PA.nb.rep = 1,
PA.nb.absences = 200,
PA.strategy = 'random')
# 2. Defining Models Options using default options.
myBiomodOption <- BIOMOD_ModelingOptions()
# 3. Doing Modelisation
myBiomomodModelOut <- BIOMOD_Modeling( myBiomodData,
models = c('CTA','RF'),
models.options = myBiomodOption,
models.eval.meth ='TSS')
# 4.1 Projection on current environemental conditions
myBiomomodProjection <- BIOMOD_Projection(modeling.output = myBiomomodModelOut,
new.env = myExpl,
proj.name = 'current',
selected.models = 'all',
binary.meth = 'TSS',
compress = FALSE,
build.clamping.mask = FALSE)
# 4.2 Projection on future environemental conditions
myExpl2050 = raster::stack(system.file("external/climat/future/bio3.grd",package="biomod2"),
system.file("external/climat/future/bio4.grd",package="biomod2"),
system.file("external/climat/future/bio7.grd",package="biomod2"),
system.file("external/climat/future/bio11.grd",package="biomod2"),
system.file("external/climat/future/bio12.grd",package="biomod2"))
myBiomomodProjection2050 <- BIOMOD_Projection(modeling.output = myBiomomodModelOut,
new.env = myExpl2050,
proj.name = 't2050',
selected.models = 'all',
binary.meth = 'TSS',
compress = FALSE,
build.clamping.mask = FALSE)
# 5. Detect where our species occurances state is forecasted to change
# load binary projections
# here is rasters objects ('.grd')
currentPred <- stack("MyocastorCoypus/proj_current/proj_current_MyocastorCoypus_TSSbin")
futurePred <- stack("MyocastorCoypus/proj_t2050/proj_t2050_MyocastorCoypus_TSSbin")
# call the Range size function
myBiomodRangeSize <- BIOMOD_RangeSize(
CurrentPred=currentPred,
FutureProj=futurePred)
# see the results
myBiomodRangeSize$Compt.By.Models
#plot(myBiomodRangeSize$Diff.By.Pixel)
Run the code above in your browser using DataLab