if (FALSE) {
#################################
#################################
#################################
## Practical use of engen2008II
data(puechabonsp)
map <- puechabonsp$map
## Removes the aspect (no factor allowed in the function)
slot(map,"data")$Aspect <- NULL
## engen2008II:
avail <- slot(map, "data")
use <- join(puechabonsp$relocs, map)
id <- slot(puechabonsp$relocs, "data")$Name
## This function can be very long:
engen2008II(use, avail, id, nsimra=10)
## Practical use of engen2008I
data(lynxjura)
ma <- lynxjura$map
lo <- lynxjura$locs
av <- slot(ma, "data")
us <- join(lo, ma)
us <- us[!is.na(us[,1]),]
## Idem, be patient here:
engen2008I(us, av, nsimra=10)
#################################
#################################
#################################
##
## For a deeper discussion on
## this method... a simulation:
#################################
##
## First, simulation of a dataset
## copy and paste this part into R,
## but skip the reading of the
## comments if you are not interested
## into this simulation
## simulate the available points
suppressWarnings(RNGversion("3.5.0"))
set.seed(235)
av <- cbind(rnorm(1000, mean=0, sd=3), rnorm(1000, mean=0, sd=0.5))
tt <- cbind(c(cos(-pi/4),sin(-pi/4)),c(cos(pi/4), sin(pi/4)))
av <- as.data.frame(as.matrix(av)%*%tt)
## simulate the used points: we simulate a selection on the first
## principal component of the PCA of the data.frame describing the
## availability. In other words, we simulate the case where the
## habitat selection occurs on the "common part" of the two habitat
## variable (no preference for one particular variable).
us <- do.call("rbind", lapply(1:5, function(i) {
us1 <- cbind(rnorm(30, mean=rnorm(1, -4, 1), sd=0.5),
rnorm(30, mean=rnorm(1, 0, 0.5), sd=0.2))
return(us1%*%tt)
}))
colnames(us) <- colnames(av) <- c("var1", "var2")
id <- gl(5,30)
#################################
##
## Study of the habitat selection on these data
## The data are:
## - us: a matrix containing the used sites for two
## habitat variables
## - av: a matrix containing the available sites for two
## habitat variables
## - id: a vector containing the id of 5 animals
## First illustrate the use and availability of the two variables:
plot(av, xlab="Habitat variable 1", ylab="Habitat variable 2",
col="grey", pch=16)
lius <- split(as.data.frame(us), id)
junk <- lapply(1:5, function(i) points(lius[[i]], pch=16, col=i))
## -----> ***It is very clear that there is a selection***:
## the animals select the low values of both habitat variables.
## (this is what we actually simulated)
## Now perform the method of Engen et al. (2008):
engen2008II(us, av, id)
## Surprisingly, the method seems to fail to identify the clear
## habitat selection identified graphically...
##
## In fact, it does not fail:
## this method identifies the part of habitat selection that is clearly
## attributable to a given variable. Here the animals select the
## the common factor expressed in the two variables, and it is impossible
## to identify whether the selection is due only to the variable 1 or to
## the variable 2: it is caused by both variable simultaneously.
## Once the selection on the variable 2 (including the common part)
## has been removed, there is no longer appearant selection on
## variable 1. Once the selection caused by the variable 1
## (including the common part) has been removed, there is no
## longer selection on variable 2...
##
## For this reason, Engen et al. recommended to use this method
## concurrently with other factor analyses of the habitat selection
## such as madifa, kselect, niche (in ade4 package), etc.
##
## Note also the strong correlation between the value of two random
## points used by a given animal. This indicates a strong variability
## among animals...
}
Run the code above in your browser using DataLab