# NOT RUN {
# }
# NOT RUN {
################################################
##
## Illustrates the analysis of recoveries of
## ringed data
data(teal)
head(teal)
## compute the sequence of dates at which the
## probability density function (pdf) of recoveries is to be estimated
vv <- seq(min(teal$date), max(teal$date), length=50)
head(vv)
## The package "maps" should be installed for the example below
library(maps)
re <- lapply(1:length(vv), function(i) {
## Estimate the pdf. We choose a smoothing parameter of
## 2 degrees of lat-long for X and Y coordinates,
## and of 2 months for the time
uu <- kernelkcbase(teal, c(2.5,2.5,2*30*24*3600), tcalc =
vv[i], grid=100, extent=0.1)
## now, we show the result
## potentially, we could type
##
## jpeg(paste("prdefu", i, ".jpg", sep=""))
##
## to store the figures in a file, and then to build a
## movie with the resulting files:
##
image(uu, main=vv[i])
## highlight the area on which there is a probability
## equal to 0.95 to recover a bird
hh <- getvolumeUDs(uu)
contour(hh, levels=95, col="red",
drawlabels=FALSE, add=TRUE, lwd=2)
## The map:
map(xlim=c(-20,70), ylim=c(30,80), add=TRUE)
## and if we had typed jpeg(...) before, we have to type
## dev.off()
## to close the device. When we have finished this loop
## We could combine the resulting files with imagemagick
## (windows) or mencoder (linux)
})
################################################
##
## Illustrates how to explore the UD in time and
## space with the bear data
data(bear)
## compute the sequence of dates at which the UD is to be
## estimated
vv <- seq(min(bear[[1]]$date), max(bear[[1]]$date), length=50)
head(vv)
## estimates the UD at each time point
re <- lapply(1:length(vv), function(i) {
## estimate the UD. We choose a smoothing parameter of
## 1000 meters for X and Y coordinates, and of 72 hours
## for the time (after a visual exploration)
uu <- kernelkc(bear, h = c(1000,1000,72*3600),
tcalc= vv[i])
## now, we show the result
## potentially, we could type
##
## jpeg(paste("UD", i, ".jpg", sep=""))
##
## to store the figures in a file, and then to build a
## movie with the resulting files:
##
image(uu[[1]], main=vv[i])
## highlight the 95 percent home range
hh <- getvolumeUDk(uu)
contour(hh[[1]], levels=95, col="red",
drawlabels=FALSE, add=TRUE)
## and if we had typed jpeg(...) before, we have to type
## dev.off()
## to close the device. When we have finished this loop
## We could combine the resulting files with imagemagick
## (windows) or mencoder (linux)
})
## Or, just show the home range:
re <- lapply(1:length(vv), function(i) {
uu <- kernelkc(bear, h = c(1000,1000,72*3600),
tcalc= vv[i])
pc <- getverticeshrk(uu, lev=95)
plot(pc, xlim=c(510000, 530000),
ylim=c(6810000, 6825000), main=vv[i])
})
##################################################
##
## Example with several wild boars (linear time)
## load wild boar data
data(puechcirc)
## keep only the first two circuits:
puech <- puechcirc[1:2]
## Now load te map of the elevation
data(puechabon)
elevation <- getkasc(puechabon$kasc, 1)
## compute the time point at which the UD is to be estimated
vv <- seq(min(puechcirc[[2]]$date), max(puechcirc[[2]]$date),
length=50)
## The estimate the UD
re <- lapply(1:length(vv),
function(i) {
## We choose a smoothing parameter of 300 meters for
## the x and y coordinates and of one hour for the time
## (but try to play with these smoothing parameters)
uu <- kernelkc(puechcirc, h=c(300,300,3600),
tcalc = vv[i], same4all=TRUE,
extent=0.1)
## show the elevation
image(elevation, main=vv[i],
xlim=c(698000,704000),
ylim=c(3156000,3160000))
## and the UD, with contour lines
colo <- c("red","blue")
lapply(1:length(uu), function(i) {
contour(uu[[i]], col=colo[i], add=TRUE)
})
## the blue contour lines show the UD of the mother and
## the red ones correspond to her son. Adult wild boars
## are known to be more "shy" that the youger ones.
## Here, the low elevation corresponds to crop area
## (vineyards). The young boar is the first and the
## last in the crops
})
##################################################
##
## Example with the bear, to illustrate (circular time)
data(bear)
## We consider a time cycle of 24 hours.
## the following vector contains the time points on the
## time circle at which the UD is to be estimated (note that
## the time is given in seconds)
vv <- seq(0, 24*3600-1, length=40)
## for each time point:
re <- lapply(1:length(vv),
function(i) {
## Estimation of the UD for the bear. We choose
## a smoothing parameter of 1000 meters for the spatial
## coordinates and a smoothing parameter equal to 0.2
## for the time. We set the beginning of the time
## cycle at midnight (no particular reason, just to
## illustrate the function). So we pass, as t0, any
## object of class POSIXct corresponding t a date at
## this hour, for example the 12/25/2012 at 00H00
t0 <- as.POSIXct("2012-12-25 00:00")
uu <- kernelkc(bear, h=c(1000,1000,0.2), cycle=24*3600,
tcalc=vv[i], t0=t0, circular=TRUE)
## shows the results
## first compute the hour for the title
hour <- paste(floor(vv[i]/3600), "hours",
floor((vv[i]%%3600)/60), "min")
## compute the 95% home range
pc <- getverticeshrk(uu, lev=95)
plot(pc, xlim=c(510000, 530000),
ylim=c(6810000, 6825000), main=hour)
## compute the 50% home range
pc <- getverticeshrk(uu, lev=50)
plot(pc, add=TRUE, colpol="blue")
})
## Now, each home range computed at a given time point corresponds to
## the area used by the animal at this time period. We may for example
## try to identify the main difference in habitat composition of the
## home-range between different time, to identify differences in
## habitat use between different time of the day. We do not do it here
## (lack of example data)
##################################################
##
## Example of the use of the function kernelkcbase and
## related functions
## load the data
data(puechabon)
locs <- puechabon$locs
## keeps only the wild boar Chou
locs <- locs[locs$Name=="Jean",]
## compute the number of days since the beginning
## of the monitoring
dd <- cumsum(c(0, diff(strptime(locs$Date, "%y%m%d"))))
dd
## compute xyt. Note that t is here the number of
## days since the beginning of the monitoring (it
## is not an object of class POSIXt, but it may be)
xyt <- data.frame(locs[,c("X", "Y")], dd)
## Now compute the time points at which the UD is to be estimated:
vv <- 1:61
## and finally, show the UD changed with time:
re <- lapply(1:length(vv),
function(i) {
ud <- kernelkcbase(xyt, h=c(300,300,20),
tcalc=vv[i], grid=100)
image(ud, main=vv[i])
contour(getvolumeUDs(ud), level=95,
col="red", lwd=2, add=TRUE)
## Just to slow down the process
Sys.sleep(0.2)
})
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab