# \donttest{
library(terra)
library(dismo)
# coordinates of the plots
xy <- ecospat.testData[,2:3]
# environmental data
predictors <- terra::rast(system.file("extdata","ecospat.testEnv.tif",package="ecospat"))
env <- terra::extract(predictors,xy,ID=FALSE)
spData <- cbind.data.frame(occ=ecospat.testData$Veronica_alpina,env)
mod <- glm(occ~ddeg0+I(ddeg0^2)+srad68+I(srad68^2),data=spData,family = binomial())
# predict to entire dataset
pred <- terra::predict(predictors,mod,type="response")
plot(pred)
points(xy[spData$occ==1,])
### make binary maps
#arbitratry threshold
pred.bin.arbitrary <- ecospat.binary.model(pred,0.3)
names(pred.bin.arbitrary) <- "me.arbitrary"
# use MPA to convert suitability to binary map
mpa.cutoff <- ecospat.mpa(pred,xy[spData$occ==1,])
pred.bin.mpa <- ecospat.binary.model(pred,mpa.cutoff)
names(pred.bin.mpa) <- "me.mpa"
mpa.ocp <- ecospat.occupied.patch(pred.bin.mpa,xy[spData$occ==1,])
arbitrary.ocp <- ecospat.occupied.patch(pred.bin.arbitrary,xy[spData$occ==1,])
par(mfrow=c(1,2))
plot(mpa.ocp) ## occupied patches: green area
points(xy[spData$occ==1,],col="red",cex=0.5,pch=19)
plot(arbitrary.ocp)
points(xy[spData$occ==1,],col="red",cex=0.5,pch=19)
## with buffer:
mpa.ocp <- ecospat.occupied.patch(pred.bin.mpa,xy[spData$occ==1,], buffer=5000)
arbitrary.ocp <- ecospat.occupied.patch(pred.bin.arbitrary,xy[spData$occ==1,], buffer=5000)
plot(mpa.ocp) ## occupied patches: green area
points(xy[spData$occ==1,],col="red",cex=0.5,pch=19)
plot(arbitrary.ocp)
points(xy[spData$occ==1,],col="red",cex=0.5,pch=19)
# }
Run the code above in your browser using DataLab