# NOT RUN {
# }
# NOT RUN {
#########################################################
#########################################################
#########################################################
###
### Example of a typical case study
### with the brownian bridge approach
###
## Load the data
data(puechcirc)
x <- puechcirc[1]
## Field studies have shown that the mean standard deviation (relocations
## as a sample of the actual position of the animal) is equal to 58
## meters on these data (Maillard, 1996, p. 63). Therefore
sig2 <- 58
## Find the maximum likelihood estimation of the parameter sig1
## First, try to find it between 10 and 100 meters
liker(x, sig2 = 58, rangesig1 = c(10, 100))
## Wow! we expected a too large standard deviation! Try again between
## 1 and 10 meters:
liker(x, sig2 = 58, rangesig1 = c(1, 10))
## So that sig1 = 6.23
## Now, estimate the brownian bridge
tata <- kernelbb(x, sig1 = 6.23, sig2 = 58, grid = 50)
image(tata, addpoints=FALSE)
## OK, now look at the home range
image(tata[[1]]$UD)
contour(getvolumeUD(tata)[[1]]$UD, level=95,
add=TRUE, col="red", lwd=2)
#########################################################
#########################################################
#########################################################
###
### Comparison of the brownian bridge approach
### with the classical approach
###
## Take an illustrative example: we simulate a trajectory
set.seed(2098)
pts1 <- data.frame(x = rnorm(25, mean = 4.5, sd = 0.05),
y = rnorm(25, mean = 4.5, sd = 0.05))
pts1b <- data.frame(x = rnorm(25, mean = 4.5, sd = 0.05),
y = rnorm(25, mean = 4.5, sd = 0.05))
pts2 <- data.frame(x = rnorm(25, mean = 4, sd = 0.05),
y = rnorm(25, mean = 4, sd = 0.05))
pts3 <- data.frame(x = rnorm(25, mean = 5, sd = 0.05),
y = rnorm(25, mean = 4, sd = 0.05))
pts3b <- data.frame(x = rnorm(25, mean = 5, sd = 0.05),
y = rnorm(25, mean = 4, sd = 0.05))
pts2b <- data.frame(x = rnorm(25, mean = 4, sd = 0.05),
y = rnorm(25, mean = 4, sd = 0.05))
pts <- do.call("rbind", lapply(1:25, function(i) {
rbind(pts1[i,], pts1b[i,], pts2[i,], pts3[i,],
pts3b[i,], pts2b[i,])
}))
dat <- 1:150
class(dat) <- c("POSIXct","POSIXt")
x <- as.ltraj(pts, date=dat, id = rep("A", 150))
## See the trajectory:
plot(x)
## Now, we suppose that there is a precision of 0.05
## on the relocations
sig2 <- 0.05
## and that sig1=0.1
sig1 <- 0.1
## Now fits the brownian bridge home range
(kbb <- kernelbb(x, sig1 = sig1,
sig2 = sig2))
## Now fits the classical kernel home range
(kud <- kernelUD(pts))
###### The results
opar <- par(mfrow=c(2,2), mar=c(0.1,0.1,2,0.1))
plot(pts, pch=16, axes=FALSE, main="The relocation pattern", asp=1)
box()
plot(x, axes=FALSE, main="The trajectory")
box()
image(kud[[1]]$UD, axes=FALSE, main="Classical kernel home range")
contour(getvolumeUD(kud)[[1]]$UD, lev=95, col="red", add=TRUE)
box()
image(kbb[[1]]$UD, axes=FALSE, main="Brownian bridge home range")
contour(getvolumeUD(kbb)[[1]]$UD, lev=95, col="red", add=TRUE)
box()
par(opar)
###############################################
###############################################
###############################################
###
### Image of a brownian bridge.
### Fit with two relocations
###
xx <- c(0,1)
yy <- c(0,1)
date <- c(0,1)
class(date) <- c("POSIXt", "POSIXct")
tr <- as.ltraj(data.frame(x = xx,y = yy), date, id="a")
## Use of different smoothing parameters
sig1 <- c(0.05, 0.1, 0.2, 0.4, 0.6)
sig2 <- c(0.05, 0.1, 0.2, 0.5, 0.7)
y <- list()
for (i in 1:5) {
for (j in 1:5) {
k <- paste("s1=", sig1[i], ", s2=", sig2[j], sep = "")
y[[k]]<-kernelbb(tr, sig1[i], sig2[j])[[1]]$UD
}
}
## Displays the results
opar <- par(mar = c(0,0,2,0), mfrow = c(5,5))
foo <- function(x)
{
image(y[[x]], main = names(y)[x], axes = F)
points(tr[[1]][,c("x","y")], pch = 16, col = "red")
}
lapply(1:length(y), foo)
par(opar)
# }
Run the code above in your browser using DataLab