# \donttest{
library(ade4)
library(terra)
data("ecospat.testNiche")
spp <- ecospat.testNiche
xy.sp1<-subset(spp,species=="sp1")[2:3] #Bromus_erectus
env<-terra::rast(system.file("extdata","ecospat.testEnv.tif",package="ecospat"))
#plot(env)
env.sp1<-terra::extract(env,xy.sp1)[,-1]
env.bkg<-na.exclude(terra::values(env))
#################################### PCA-ENVIRONMENT ##################################
pca.cal <- ade4::dudi.pca(env.bkg, center = TRUE, scale = TRUE, scannf = FALSE, nf = 2)
# predict the scores on the axes
scores.bkg <- pca.cal$li #scores for background climate
scores.sp1 <- ade4::suprow(pca.cal,env.sp1)$lisup #scores for sp1
# calculation of occurence density (niche z)
z1 <- ecospat.grid.clim.dyn(scores.bkg, scores.bkg, scores.sp1,R=100)
plot(z1$z.uncor)
points(scores.sp1)
#################################### occurrence density in space ##################################
# sp1
geoz1<-ecospat.niche.zProjGeo(z1,zproj=NULL,env=env)
plot(geoz1,main="z1")
points(xy.sp1)
# }
Run the code above in your browser using DataLab