# \donttest{
library(ade4)
library(raster)
data(ecospat.testNiche)
spp <- ecospat.testNiche
xy.sp1 <- subset(spp, species=="sp1")[2:3] #Bromus_erectus
xy.sp2 <- subset(spp, species=="sp4")[2:3] #Pritzelago_alpina
load(system.file("extdata", "ecospat.testEnvRaster.Rdata",
package="ecospat"))
env.sp1 <- extract(env, xy.sp1)
env.sp2 <- extract(env, xy.sp2)
env.bkg <- na.exclude(values(env))
#####################
## PCA-ENVIRONMENT ##
#####################
pca.cal <- 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 <- suprow(pca.cal,env.sp1)$lisup #scores for sp1
scores.sp2 <- suprow(pca.cal,env.sp2)$lisup #scores for sp2
# calculation of occurence density (niche z)
z1 <- ecospat.grid.clim.dyn(scores.bkg, scores.bkg,
scores.sp1, R = 100)
z2 <- ecospat.grid.clim.dyn(scores.bkg, scores.bkg,
scores.sp2, R = 100)
plot(z1$z.uncor)
points(scores.sp1, pch = 21, bg = "green")
plot(z2$z.uncor)
points(scores.sp2, pch = 21, bg = "red")
ecospat.plot.niche.dyn(z1, z2)
points(scores.sp1, pch = 21, bg = "green")
points(scores.sp2, pch = 21, bg = "red")
ecospat.niche.overlap(z1,z2 ,cor = TRUE)
##############################
## dynamic indices in space ##
##############################
geozS <- ecospat.niche.dynIndexProjGeo(z1, z2, env)
plot(geozS, col = c("grey", "green", "red", "blue"),
legend = FALSE)
points(xy.sp1, bg = "green", pch = 21)
points(xy.sp2, bg = "red", pch = 21)
# }
Run the code above in your browser using DataLab