# \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"
### rangesize calculations
if(require(alphahull,quietly=TRUE)){
rangesize2 <- ecospat.rangesize(c(pred.bin.mpa,pred.bin.arbitrary),
xy=xy[spData$occ==1,],
AOO.circles = TRUE,
lonlat =FALSE)
rangesize2$RangeSize
names(rangesize2$RangeObjects)
par(mfrow=c(1,3))
plot(ecospat.binary.model(pred,0),legend=FALSE, main="IUCN criteria")
### IUCN criteria & derivates
# plot AOO
plot(rangesize2$RangeObjects$AOO,add=TRUE, col="red",legend=FALSE)
# plot EOO
plot(rangesize2$RangeObjects$EOO@polygons,add=TRUE, border="red", lwd=2)
# plot circles around occurrences
plot(rangesize2$RangeObjects$AOO.circle@polygons,add=TRUE,border="blue")
for(i in 1:2){
## plot the occupied patches of the model
plot(rangesize2$RangeObjects$models.ocp[[i]],col=c("grey","blue","darkgreen"),
main=names(rangesize2$RangeObjects$models.ocp[[i]]),legend=FALSE)
points(xy[spData$occ==1,],col="red",cex=0.5,pch=19)
## plot EOO around model
plot(rangesize2$RangeObjects$eoo.around.model[[i]]@polygons,add=TRUE,border="blue",lwd=2)
## plot the modeled area within EOO
#plot(rangesize$RangeObjects$model.within.eoo[[i]],col=c("grey","blue","darkgreen"))
#points(occ,col="red",cex=0.5,pch=19)
#plot(rangesize$RangeObjects$EOO@polygons,add=TRUE, border="red", lwd=2)
}
par(mfrow=c(1,1))
### Alpha-hulls are not included in the function yet because of Licence limitations.
### However, alpha-hulls can easily be included manually (see also the help file of
### the alpha hull package):
alpha = 2 # alpha value of 2 recommended by IUCN
del<-alphahull::delvor(xy[spData$occ==1,])
dv<-del$mesh
mn <- mean(sqrt(abs(del$mesh[,3]-del$mesh[,5])^2+abs(del$mesh[,4]-del$mesh[,6])^2))*alpha
alpha.hull<-alphahull::ahull(del,alpha=mn)
#Size of alpha-hulls
#areaahull(alpha.hull) #works but uses a deprecated function in alphahull 2.1
#plot alphahulls
plot(rangesize2$RangeObjects$models.ocp[[1]],col=c("grey","blue","darkgreen"),
main=names(rangesize2$RangeObjects$models.ocp[[1]]),legend=FALSE)
plot(alpha.hull,add=TRUE,lwd=1)
}
# }
Run the code above in your browser using DataLab