diff --git a/.Rbuildignore b/.Rbuildignore index 15f6641..8cb6dd8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,4 @@ .gitignore .Rhistory ^doc$ +^Meta$ diff --git a/.gitignore b/.gitignore index 18db509..54ad605 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *.rds archives/ +/doc/ +/Meta/ diff --git a/DESCRIPTION b/DESCRIPTION index 31374fe..c65c9fd 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,12 @@ Package: adehabitatHR -Version: 0.4.19 -Date: 2021-01-09 -Depends: R (>= 3.0.1), sp, methods, deldir, ade4, adehabitatMA, adehabitatLT -Suggests: maptools, tkrplot, MASS, rgeos +Version: 0.4.21 +Date: 2023-04-06 +Depends: R (>= 3.0.1), sp, methods, ade4, adehabitatMA, adehabitatLT +Suggests: tkrplot, MASS, sf, deldir Imports: graphics, grDevices, stats Title: Home Range Estimation Author: Clement Calenge, contributions from Scott Fortmann-Roe Maintainer: Clement Calenge Description: A collection of tools for the estimation of animals home range. +VignetteBuilder: utils License: GPL (>= 2) diff --git a/NAMESPACE b/NAMESPACE index a04eddf..6a5cf80 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ useDynLib(adehabitatHR, .registration=TRUE) -import(sp,adehabitatLT,methods,deldir,ade4,adehabitatMA) +import(sp,adehabitatLT,methods,ade4,adehabitatMA) importFrom("graphics", "box", "grid", "image", "lines", "par", "title") importFrom("grDevices", "chull", "contourLines", "grey", "n2mfrow") importFrom("stats", "na.omit", "quantile", "var") diff --git a/R/CharHull.r b/R/CharHull.r index 29655f3..fdc43c1 100755 --- a/R/CharHull.r +++ b/R/CharHull.r @@ -2,8 +2,8 @@ { xy <- as.data.frame(xy) names(xy) <- c("x","y") - tri <- deldir(xy[,1], xy[,2]) - tri <- triang.list(tri) + tri <- deldir::deldir(xy[,1], xy[,2]) + tri <- deldir::triang.list(tri) tri <- lapply(1:length(tri), function(i) { rbind(tri[[i]], tri[[i]][1,]) }) @@ -77,21 +77,16 @@ CharHull <- function(xy, unin = c("m", "km"), unout = c("ha", "m2", "km2"), resa <- .charhull(x) - pol <- as(resa, "SpatialPolygons") - lip <- list(pol[1]) - for (j in 2:nrow(resa)) { - poo <- rbind(pol[j], lip[[j-1]]) - pls <- slot(poo, "polygons") - pls1 <- lapply(pls, maptools::checkPolygonsHoles) - slot(poo, "polygons") <- pls1 - lip[[j]] <- rgeos::gUnionCascaded(poo, id = rep(j, - length(row.names(poo)))) + resasf <- sf::st_as_sf(resa) + lipsf <- list(sf::st_sf(data.frame(id=1, sf::st_geometry(resasf[1,])))) + for (j in 2:nrow(resasf)) { + lipsf[[j]] <- sf::st_sf(data.frame(id=j,sf::st_union(resasf[1:j,]))) } - are <- .arcpspdf(lip[[1]]) - for (j in 2:length(lip)) { - are[j] <- .arcpspdf(lip[[j]]) + lipsfg <- as(do.call(rbind, lipsf), "Spatial") + are <- .arcpspdf(lipsfg[1,]) + for (j in 2:length(lipsfg)) { + are[j] <- .arcpspdf(lipsfg[j,]) } - spP <- do.call("rbind", lip) if (unin == "m") { if (unout == "ha") are <- are/10000 @@ -104,8 +99,8 @@ CharHull <- function(xy, unin = c("m", "km"), unout = c("ha", "m2", "km2"), if (unout == "m2") are <- are * 1e+06 } - df <- data.frame(area = are, percent = resa[[2]]) - resa <- SpatialPolygonsDataFrame(spP, df) + df <- data.frame(area = are, percent = resasf[[2]]) + resa <- SpatialPolygonsDataFrame(as(lipsfg,"SpatialPolygons"), df) if (!is.na(pfs)) proj4string(resa) <- CRS(pfs) res[[i]] <- resa diff --git a/R/LoCoH.r b/R/LoCoH.r index 561efe2..0f47ec1 100755 --- a/R/LoCoH.r +++ b/R/LoCoH.r @@ -1,6 +1,4 @@ - ## k-Locoh - LoCoH.k <- function(xy, k=5, unin = c("m", "km"), unout = c("ha", "m2", "km2"), duplicates=c("random","remove"), amount = NULL) @@ -83,31 +81,26 @@ LoCoH.k <- function(xy, k=5, unin = c("m", "km"), oo <- oo[order(ar),] ar <- ar[order(ar)] + ## then, "incremental" union: - lip <- list(SpatialPolygons(list(Polygons(list(Polygon(rbind(pol[[1]], pol[[1]][1,]))), 1)))) - n <- k + lipsf <- lapply(1:length(pol), function(i) + sf::st_sf(data.frame(id=i,sf::st_sfc(sf::st_polygon(list(rbind(pol[[i]], pol[[i]][1,]))))))) dej <- unlist(oo[1,]) - + n <- k + lipsf2 <- list(lipsf[[1]]) for (i in 2:nrow(xy)) { - poo <- rbind(SpatialPolygons(list(Polygons(list(Polygon(rbind(pol[[i]],pol[[i]][1,]))), i))), lip[[i-1]]) - pls <- slot(poo, "polygons") - pls1 <- lapply(pls, maptools::checkPolygonsHoles) - slot(poo, "polygons") <- pls1 - lip[[i]] <- rgeos::gUnionCascaded(poo, id=rep(i, length(row.names(poo)))) + ## Union des polygones progressive + lipsf2[[i]] <- sf::st_sf(data.frame(id=i,sf::st_union(rbind(lipsf[[i]],lipsf2[[i-1]])))) dej <- c(dej, unlist(oo[i,!(unlist(oo[i,])%in%dej)])) n[i] <- length(dej) } + lipsfg <- as(do.call(rbind, lipsf2), "Spatial") ## Compute the area - are <- .arcpspdf(lip[[1]]) - for (i in 2:nrow(xy)) { - are[i] <- .arcpspdf(lip[[i]]) + are <- .arcpspdf(lipsfg[1,]) + for (j in 2:length(lipsfg)) { + are[j] <- .arcpspdf(lipsfg[j,]) } - - ## And the results, as a SpatialPolygonDataFrame object - spP <- do.call("rbind", lip) - - ## The data frame: if (unin == "m") { if (unout == "ha") are <- are/10000 @@ -122,7 +115,8 @@ LoCoH.k <- function(xy, k=5, unin = c("m", "km"), } df <- data.frame(area=are, percent=100*n/nrow(xy)) - res <- SpatialPolygonsDataFrame(spP, df) + res <- SpatialPolygonsDataFrame(lipsfg, df) + if (!is.na(pfs)) proj4string(res) <- CRS(pfs) return(res) @@ -261,7 +255,6 @@ MCHu.rast <- function(x, spdf, percent=100) ### R LoCoH - LoCoH.r <- function(xy, r, unin = c("m", "km"), unout = c("ha", "m2", "km2"), duplicates=c("random","remove"), amount = NULL) @@ -358,33 +351,38 @@ LoCoH.r <- function(xy, r, unin = c("m", "km"), if (max==0) stop("the distance is too small: there were only isolated points\nPlease increase the value of r") + + ## then, "incremental" union: - lip <- list(SpatialPolygons(list(Polygons(list(Polygon(rbind(pol[[1]], pol[[1]][1,]))), 1)))) + lipsf <- lapply(1:length(pol), function(i) { + if (nrow(pol[[i]])>2) { + return(sf::st_sf(data.frame(id=i,sf::st_sfc(sf::st_polygon(list(rbind(pol[[i]], pol[[i]][1,]))))))) + } else { + return(NULL) + } + }) dej <- oo[[1]] n <- num[1] + for (i in 2:nrow(xy)) { - if (nrow(pol[[i]])>2) { - poo <- rbind(SpatialPolygons(list(Polygons(list(Polygon(rbind(pol[[i]],pol[[i]][1,]))), i))), lip[[i-1]]) + if (!is.null(lipsf[[i]])) { + poo <- rbind(lipsf[[i]], lipsf[[i-1]]) } else { - poo <- lip[[i-1]] + poo <- lipsf[[i-1]] } - pls <- slot(poo, "polygons") - pls1 <- lapply(pls, maptools::checkPolygonsHoles) - slot(poo, "polygons") <- pls1 - - lip[[i]] <- rgeos::gUnionCascaded(poo, id=rep(i, length(row.names(poo)))) + lipsf[[i]] <- sf::st_sf(data.frame(id=i,sf::st_geometry(sf::st_union(poo)))) dej <- c(dej, oo[[i]][!(oo[[i]]%in%dej)]) n[i] <- length(dej) } ## Compute the area - are <- .arcpspdf(lip[[1]]) + are <- .arcpspdf(as(lipsf[[1]], "Spatial")) for (i in 2:nrow(xy)) { - are[i] <- .arcpspdf(lip[[i]]) + are[i] <- .arcpspdf(as(lipsf[[i]], "Spatial")) } ## And the results, as a SpatialPolygonDataFrame object - spP <- do.call("rbind", lip) + spP <- as(do.call("rbind", lipsf),"Spatial") ## The data frame: n[n>max] <- max @@ -491,7 +489,6 @@ LoCoH.r.area <- function(xy, rrange, percent=100, unin = c("m", "km"), ### A LoCoH - LoCoH.a <- function(xy, a, unin = c("m", "km"), unout = c("ha", "m2", "km2"), duplicates=c("random","remove"), amount = NULL) @@ -586,35 +583,37 @@ LoCoH.a <- function(xy, a, unin = c("m", "km"), num <- num[ind] ## then, "incremental" union: - lip <- list(SpatialPolygons(list(Polygons(list(Polygon(rbind(pol[[1]], pol[[1]][1,]))), 1)))) + lipsf <- lapply(1:length(pol), function(i) { + if (nrow(pol[[i]])>2) { + return(sf::st_sf(data.frame(id=i,sf::st_sfc(sf::st_polygon(list(rbind(pol[[i]], pol[[i]][1,]))))))) + } else { + return(NULL) + } + }) dej <- oo[[1]] n <- num[1] + for (i in 2:nrow(xy)) { - if (nrow(pol[[i]])>3) { - poo <- rbind(SpatialPolygons(list(Polygons(list(Polygon(rbind(pol[[i]],pol[[i]][1,]))), i))), lip[[i-1]]) + if (!is.null(lipsf[[i]])) { + poo <- rbind(lipsf[[i]], lipsf[[i-1]]) } else { - poo <- lip[[i-1]] + poo <- lipsf[[i-1]] } - pls <- slot(poo, "polygons") - pls1 <- lapply(pls, maptools::checkPolygonsHoles) - slot(poo, "polygons") <- pls1 - - lip[[i]] <- rgeos::gUnionCascaded(poo, id=rep(i, length(row.names(poo)))) + lipsf[[i]] <- sf::st_sf(data.frame(id=i,sf::st_geometry(sf::st_union(poo)))) dej <- c(dej, oo[[i]][!(oo[[i]]%in%dej)]) n[i] <- length(dej) } ## Compute the area - are <- .arcpspdf(lip[[1]]) + are <- .arcpspdf(as(lipsf[[1]], "Spatial")) for (i in 2:nrow(xy)) { - are[i] <- .arcpspdf(lip[[i]]) + are[i] <- .arcpspdf(as(lipsf[[i]], "Spatial")) } ## And the results, as a SpatialPolygonDataFrame object - spP <- do.call("rbind", lip) + spP <- as(do.call("rbind", lipsf),"Spatial") ## The data frame: - df <- data.frame(area=are, percent=100*n/nrow(xy)) if (unin == "m") { if (unout == "ha") are <- are/10000 @@ -629,6 +628,7 @@ LoCoH.a <- function(xy, a, unin = c("m", "km"), } + df <- data.frame(area=are, percent=100*n/nrow(xy)) res <- SpatialPolygonsDataFrame(spP, df) if (!is.na(pfs)) proj4string(res) <- CRS(pfs) diff --git a/inst/CITATION b/inst/CITATION deleted file mode 100755 index ebb0be9..0000000 --- a/inst/CITATION +++ /dev/null @@ -1,15 +0,0 @@ -citHeader("To cite the adehabitatHR package in publications use:") - -citEntry( -entry="Article", -title = "The package adehabitat for the R software: - tool for the analysis of space and habitat use by animals", -journal = "Ecological Modelling", -volume = "197", -pages = {516--519}, -year = "2006", -author = "C. Calenge", -textVersion = "Calenge, C. (2006) The package adehabitat for the R -software: a tool for the analysis of space and habitat -use by animals. Ecological Modelling, 197, 516-519" -) diff --git a/man/LoCoH.Rd b/man/LoCoH.Rd index 1784729..af2cd7b 100755 --- a/man/LoCoH.Rd +++ b/man/LoCoH.Rd @@ -98,7 +98,7 @@ LoCoH.a.area(xy, arange, percent=100, unin = c("m", "km"), } \note{ - These functions rely on the packages rgeos, gpclib, and maptools. + These functions rely on the package sf. The LoCoH family of methods for locating Utilization Distributions consists of three algorithms: Fixed k LoCoH, Fixed r LoCoH, and diff --git a/man/kernelUD.Rd b/man/kernelUD.Rd index 3637d09..37976af 100755 --- a/man/kernelUD.Rd +++ b/man/kernelUD.Rd @@ -207,7 +207,7 @@ estUDm2spixdf(x) Silverman, B.W. (1986) \emph{Density estimation for statistics and data - analysis}. London: Chapman \& Hall. + analysis}. London: Chapman and Hall. Worton, B.J. (1989) Kernel methods for estimating the utilization distribution in home-range studies. \emph{Ecology}, \bold{70}, 164--168. diff --git a/src/tests.c b/src/tests.c index 6a5d8ea..37d2cad 100755 --- a/src/tests.c +++ b/src/tests.c @@ -893,7 +893,7 @@ void prodmatAAtB (double **a, double **b) void prodmatAtBrandomC (double **a, double **b, double **c, int*permut) /*-------------------------------------------------- * Produit matriciel AtB - * les lignes de B sont permutÚes par la permutation permut + * les lignes de B sont permutes par la permutation permut --------------------------------------------------*/ { int j, k, i, i0, lig, col, col2; @@ -1353,7 +1353,7 @@ void CVmise(int *nloc, double *xlo, double *ylo, int i, nlo, nh, ndist; double *xl, *yl, h, *dists; - /* Allocation de mémoire */ + /* Allocation de memoire */ nlo = *nloc; nh = *nhteste; @@ -2691,7 +2691,7 @@ SEXP filtreLmin(SEXP df, double Lmin, SEXP PA2, SEXP fll) int nrow, i, k, nfl, fl; double sx, sy, ggg; - /* récup des vecteurs */ + /* recup des vecteurs */ PROTECT(x = coerceVector(VECTOR_ELT(df,0), REALSXP)); PROTECT(y = coerceVector(VECTOR_ELT(df,1), REALSXP)); PROTECT(date = coerceVector(VECTOR_ELT(df,2), REALSXP)); @@ -2716,13 +2716,13 @@ SEXP filtreLmin(SEXP df, double Lmin, SEXP PA2, SEXP fll) } } - /* allocation mémoire */ + /* allocation memoire */ PROTECT(xn = allocVector(REALSXP, k)); PROTECT(yn = allocVector(REALSXP, k)); PROTECT(daten = allocVector(REALSXP, k)); PROTECT(PAn = allocVector(REALSXP, k)); - /* préparation de la boucle */ + /* preparation de la boucle */ REAL(xn)[0] = REAL(x)[0]; REAL(yn)[0] = REAL(y)[0]; REAL(daten)[0] = REAL(date)[0]; @@ -2739,8 +2739,8 @@ SEXP filtreLmin(SEXP df, double Lmin, SEXP PA2, SEXP fll) for (i=1; i< nrow; i++) { - /* si la distance entre localisations successives est inférieure à Lmin, on - se contente d'en calculer la moyenne (que l'on stockera à la première date) + /* si la distance entre localisations successives est inferieure a Lmin, on + se contente d'en calculer la moyenne (que l'on stockera a la premiere date) */ ggg = 1; if (length(PA) > 1) { @@ -2753,8 +2753,8 @@ SEXP filtreLmin(SEXP df, double Lmin, SEXP PA2, SEXP fll) sy = sy + REAL(y)[i]; } else { - /* Si la nouvelle localisation est la première éloignée après un clusters de Lmin, - On commence par stocker la précédente (moyenne des positions) + /* Si la nouvelle localisation est la premiere eloignee apres un clusters de Lmin, + On commence par stocker la precedente (moyenne des positions) */ if (nfl > 1) { REAL(xn)[k] = sx/((double) nfl); @@ -2774,13 +2774,13 @@ SEXP filtreLmin(SEXP df, double Lmin, SEXP PA2, SEXP fll) REAL(PAn)[k] = 1; } - /* et au cas où, on garde cette loc en mémoire */ + /* et au cas ou, on garde cette loc en memoire */ sx = REAL(x)[i]; sy = REAL(y)[i]; } } - /* On renvoie alors les résultats dans un data.frame */ + /* On renvoie alors les resultats dans un data.frame */ PROTECT(df2 = allocVector(VECSXP, 4)); SET_VECTOR_ELT(df2, 0, xn); SET_VECTOR_ELT(df2, 1, yn); @@ -2962,7 +2962,7 @@ SEXP fillsegments(SEXP df2, SEXP Tmaxr, SEXP taur, SEXP hminr, SEXP D, SEXP Lmin } -/* On calcule maintenant, sur la base d'une grille passée, l'estimation kernel */ +/* On calcule maintenant, sur la base d'une grille passee, l'estimation kernel */ SEXP mkde(SEXP xyh, SEXP grid) { diff --git a/vignettes/adehabitatHR.R b/vignettes/adehabitatHR.R deleted file mode 100644 index 6355e1f..0000000 --- a/vignettes/adehabitatHR.R +++ /dev/null @@ -1,2074 +0,0 @@ -### R code from vignette source 'adehabitatHR.Rnw' - -################################################### -### code chunk number 1: adehabitatHR.Rnw:28-35 -################################################### -owidth <- getOption("width") -options("width"=80) -ow <- getOption("warn") -options("warn"=-1) -.PngNo <- 0 -wi <- 600 -pt <- 25 - - -################################################### -### code chunk number 2: afig (eval = FALSE) -################################################### -## .PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", -## .PngNo, ".png", sep="") -## png(file=file, width = wi, height = wi, pointsize = pt) - - -################################################### -### code chunk number 3: zfig (eval = FALSE) -################################################### -## dev.null <- dev.off() -## cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 4: zfigg (eval = FALSE) -################################################### -## dev.null <- dev.off() -## cat("\\includegraphics[height=14cm,width=14cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 5: adehabitatHR.Rnw:103-104 -################################################### -library(adehabitatHR) - - -################################################### -### code chunk number 6: adehabitatHR.Rnw:107-109 -################################################### -suppressWarnings(RNGversion("3.5.0")) -set.seed(13431) - - -################################################### -### code chunk number 7: adehabitatHR.Rnw:172-174 -################################################### -xy <- matrix(runif(60), ncol=2) -head(xy) - - -################################################### -### code chunk number 8: adehabitatHR.Rnw:180-181 -################################################### -xysp <- SpatialPoints(xy) - - -################################################### -### code chunk number 9: adehabitatHR.Rnw:189-191 -################################################### -clu <- clusthr(xysp) -class(clu) - - -################################################### -### code chunk number 10: fig1 (eval = FALSE) -################################################### -## plot(clu) - - -################################################### -### code chunk number 11: adehabitatHR.Rnw:200-201 (eval = FALSE) -################################################### -## plot(clu) - - -################################################### -### code chunk number 12: adehabitatHR.Rnw:205-208 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(clu) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 13: adehabitatHR.Rnw:215-216 -################################################### -xy2 <- matrix(runif(60), ncol=2) - - -################################################### -### code chunk number 14: adehabitatHR.Rnw:221-222 -################################################### -xyt <- rbind(xy, xy2) - - -################################################### -### code chunk number 15: adehabitatHR.Rnw:228-229 -################################################### -id <- gl(2,30) - - -################################################### -### code chunk number 16: adehabitatHR.Rnw:235-238 -################################################### -idsp <- data.frame(id) -coordinates(idsp) <- xyt -class(idsp) - - -################################################### -### code chunk number 17: adehabitatHR.Rnw:243-246 -################################################### -clu2 <- clusthr(idsp) -class(clu2) -clu2 - - -################################################### -### code chunk number 18: adehabitatHR.Rnw:253-256 -################################################### -length(clu2) -class(clu2[[1]]) -class(clu2[[2]]) - - -################################################### -### code chunk number 19: fig2 (eval = FALSE) -################################################### -## plot(clu2) - - -################################################### -### code chunk number 20: adehabitatHR.Rnw:268-269 (eval = FALSE) -################################################### -## plot(clu2) - - -################################################### -### code chunk number 21: adehabitatHR.Rnw:273-276 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(clu2) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 22: adehabitatHR.Rnw:295-297 -################################################### -data(puechabonsp) -names(puechabonsp) - - -################################################### -### code chunk number 23: adehabitatHR.Rnw:305-306 -################################################### -head(as.data.frame(puechabonsp$relocs)) - - -################################################### -### code chunk number 24: fig3 (eval = FALSE) -################################################### -## ## Map of the elevation -## image(puechabonsp$map, col=grey(c(1:10)/10)) -## ## map of the relocations -## plot(puechabonsp$relocs, add=TRUE, -## col=as.data.frame(puechabonsp$relocs)[,1]) - - -################################################### -### code chunk number 25: adehabitatHR.Rnw:325-326 (eval = FALSE) -################################################### -## ## Map of the elevation -## image(puechabonsp$map, col=grey(c(1:10)/10)) -## ## map of the relocations -## plot(puechabonsp$relocs, add=TRUE, -## col=as.data.frame(puechabonsp$relocs)[,1]) - - -################################################### -### code chunk number 26: adehabitatHR.Rnw:330-333 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -## Map of the elevation -image(puechabonsp$map, col=grey(c(1:10)/10)) -## map of the relocations -plot(puechabonsp$relocs, add=TRUE, - col=as.data.frame(puechabonsp$relocs)[,1]) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 27: adehabitatHR.Rnw:367-369 -################################################### -data(puechabonsp) -cp <- mcp(puechabonsp$relocs[,1], percent=95) - - -################################################### -### code chunk number 28: adehabitatHR.Rnw:375-376 -################################################### -class(cp) - - -################################################### -### code chunk number 29: fig4 (eval = FALSE) -################################################### -## plot(cp) -## plot(puechabonsp$relocs, add=TRUE) - - -################################################### -### code chunk number 30: adehabitatHR.Rnw:389-390 (eval = FALSE) -################################################### -## plot(cp) -## plot(puechabonsp$relocs, add=TRUE) - - -################################################### -### code chunk number 31: adehabitatHR.Rnw:394-397 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(cp) -plot(puechabonsp$relocs, add=TRUE) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 32: adehabitatHR.Rnw:406-407 -################################################### -library(maptools) - - -################################################### -### code chunk number 33: adehabitatHR.Rnw:410-411 (eval = FALSE) -################################################### -## writePolyShape(cp, "homerange") - - -################################################### -### code chunk number 34: adehabitatHR.Rnw:425-426 -################################################### -head(as.data.frame(puechabonsp$map)) - - -################################################### -### code chunk number 35: adehabitatHR.Rnw:435-438 -################################################### -enc <- over(puechabonsp$map, as(cp[2,],"SpatialPolygons"), fn=function(x) return(1)) -enc <- as.data.frame(enc) -head(enc) - - -################################################### -### code chunk number 36: adehabitatHR.Rnw:447-449 -################################################### -coordinates(enc) <- coordinates(puechabonsp$map) -gridded(enc) <- TRUE - - -################################################### -### code chunk number 37: fig5 (eval = FALSE) -################################################### -## image(puechabonsp$map) -## image(enc, add=TRUE, col="black", useRasterImage=FALSE) - - -################################################### -### code chunk number 38: adehabitatHR.Rnw:459-460 (eval = FALSE) -################################################### -## image(puechabonsp$map) -## image(enc, add=TRUE, col="black", useRasterImage=FALSE) - - -################################################### -### code chunk number 39: adehabitatHR.Rnw:464-467 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -image(puechabonsp$map) -image(enc, add=TRUE, col="black", useRasterImage=FALSE) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 40: adehabitatHR.Rnw:475-476 -################################################### -cprast <- hr.rast(cp, puechabonsp$map) - - -################################################### -### code chunk number 41: sldkslsd (eval = FALSE) -################################################### -## par(mar=c(0,0,0,0)) -## par(mfrow=c(2,2)) -## for (i in 1:4) { -## image(cprast[,i], useRasterImage=FALSE) -## box() -## } - - -################################################### -### code chunk number 42: adehabitatHR.Rnw:491-492 (eval = FALSE) -################################################### -## par(mar=c(0,0,0,0)) -## par(mfrow=c(2,2)) -## for (i in 1:4) { -## image(cprast[,i], useRasterImage=FALSE) -## box() -## } - - -################################################### -### code chunk number 43: adehabitatHR.Rnw:496-499 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -par(mar=c(0,0,0,0)) -par(mfrow=c(2,2)) -for (i in 1:4) { - image(cprast[,i], useRasterImage=FALSE) - box() -} -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 44: adehabitatHR.Rnw:510-511 -################################################### -as.data.frame(cp) - - -################################################### -### code chunk number 45: fig6 (eval = FALSE) -################################################### -## hrs <- mcp.area(puechabonsp$relocs[,1], percent=seq(50, 100, by = 5)) - - -################################################### -### code chunk number 46: adehabitatHR.Rnw:532-533 (eval = FALSE) -################################################### -## hrs <- mcp.area(puechabonsp$relocs[,1], percent=seq(50, 100, by = 5)) - - -################################################### -### code chunk number 47: adehabitatHR.Rnw:537-540 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -hrs <- mcp.area(puechabonsp$relocs[,1], percent=seq(50, 100, by = 5)) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 48: adehabitatHR.Rnw:557-558 -################################################### -hrs - - -################################################### -### code chunk number 49: fig7 (eval = FALSE) -################################################### -## xy1 <- matrix(rnorm(200), ncol=2) -## xy2 <- matrix(rnorm(200, mean=3), ncol=2) -## xy <- rbind(xy1,xy2) -## xy <- SpatialPoints(xy) -## kud <- kernelUD(xy) -## par(mfrow=c(1,2)) -## plot(xy) -## title("Input: Relocations") -## par(mar=c(0,0,2,0)) -## xxyz <- as.image.SpatialGridDataFrame(kud) -## persp(xxyz, theta=30, phi=45, box=FALSE, shade=0.5, border=NA, ltheta=300) -## title("Output: the UD") - - -################################################### -### code chunk number 50: adehabitatHR.Rnw:608-614 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = 2*wi, height = wi, pointsize = pt) -xy1 <- matrix(rnorm(200), ncol=2) -xy2 <- matrix(rnorm(200, mean=3), ncol=2) -xy <- rbind(xy1,xy2) -xy <- SpatialPoints(xy) -kud <- kernelUD(xy) -par(mfrow=c(1,2)) -plot(xy) -title("Input: Relocations") -par(mar=c(0,0,2,0)) -xxyz <- as.image.SpatialGridDataFrame(kud) -persp(xxyz, theta=30, phi=45, box=FALSE, shade=0.5, border=NA, ltheta=300) -title("Output: the UD") -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=14cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 51: kdksks (eval = FALSE) -################################################### -## par(mfrow=c(2,2)) -## par(mar=c(0,0,2,0)) -## image(kernelUD(xy, h=0.2)) -## title("h = 0.2") -## par(mar=c(0,0,2,0)) -## image(kernelUD(xy, h=0.5)) -## title("h = 0.5") -## par(mar=c(0,0,2,0)) -## image(kernelUD(xy, h=1)) -## title("h = 1") -## par(mar=c(0,0,2,0)) -## image(kernelUD(xy, h=2)) -## title("h = 2") - - -################################################### -### code chunk number 52: adehabitatHR.Rnw:699-702 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -par(mfrow=c(2,2)) -par(mar=c(0,0,2,0)) -image(kernelUD(xy, h=0.2)) -title("h = 0.2") -par(mar=c(0,0,2,0)) -image(kernelUD(xy, h=0.5)) -title("h = 0.5") -par(mar=c(0,0,2,0)) -image(kernelUD(xy, h=1)) -title("h = 1") -par(mar=c(0,0,2,0)) -image(kernelUD(xy, h=2)) -title("h = 2") -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 53: adehabitatHR.Rnw:769-772 -################################################### -data(puechabonsp) -kud <- kernelUD(puechabonsp$relocs[,1], h="href") -kud - - -################################################### -### code chunk number 54: fig8 (eval = FALSE) -################################################### -## image(kud) - - -################################################### -### code chunk number 55: adehabitatHR.Rnw:784-785 (eval = FALSE) -################################################### -## image(kud) - - -################################################### -### code chunk number 56: adehabitatHR.Rnw:790-793 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -image(kud) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 57: adehabitatHR.Rnw:801-802 -################################################### -kud[[1]]@h - - -################################################### -### code chunk number 58: fig9 (eval = FALSE) -################################################### -## kudl <- kernelUD(puechabonsp$relocs[,1], h="LSCV") -## image(kudl) - - -################################################### -### code chunk number 59: adehabitatHR.Rnw:822-823 (eval = FALSE) -################################################### -## kudl <- kernelUD(puechabonsp$relocs[,1], h="LSCV") -## image(kudl) - - -################################################### -### code chunk number 60: adehabitatHR.Rnw:828-831 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -kudl <- kernelUD(puechabonsp$relocs[,1], h="LSCV") -image(kudl) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 61: fig10 (eval = FALSE) -################################################### -## plotLSCV(kudl) - - -################################################### -### code chunk number 62: adehabitatHR.Rnw:848-849 (eval = FALSE) -################################################### -## plotLSCV(kudl) - - -################################################### -### code chunk number 63: adehabitatHR.Rnw:854-857 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plotLSCV(kudl) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 64: kskdkkds (eval = FALSE) -################################################### -## ## The relocations of "Brock" -## locs <- puechabonsp$relocs -## firs <- locs[as.data.frame(locs)[,1]=="Brock",] -## -## ## Graphical parameters -## par(mar=c(0,0,2,0)) -## par(mfrow=c(2,2)) -## -## ## Estimation of the UD with grid=20 and extent=0.2 -## image(kernelUD(firs, grid=20, extent=0.2)) -## title(main="grid=20, extent=0.2") -## -## ## Estimation of the UD with grid=20 and extent=0.2 -## image(kernelUD(firs, grid=80, extent=0.2)) -## title(main="grid=80, extent=0.2") -## -## ## Estimation of the UD with grid=20 and extent=0.2 -## image(kernelUD(firs, grid=20, extent=3)) -## title(main="grid=20, extent=3") -## -## ## Estimation of the UD with grid=20 and extent=0.2 -## image(kernelUD(firs, grid=80, extent=3)) -## title(main="grid=80, extent=3") - - -################################################### -### code chunk number 65: adehabitatHR.Rnw:947-948 (eval = FALSE) -################################################### -## ## The relocations of "Brock" -## locs <- puechabonsp$relocs -## firs <- locs[as.data.frame(locs)[,1]=="Brock",] -## -## ## Graphical parameters -## par(mar=c(0,0,2,0)) -## par(mfrow=c(2,2)) -## -## ## Estimation of the UD with grid=20 and extent=0.2 -## image(kernelUD(firs, grid=20, extent=0.2)) -## title(main="grid=20, extent=0.2") -## -## ## Estimation of the UD with grid=20 and extent=0.2 -## image(kernelUD(firs, grid=80, extent=0.2)) -## title(main="grid=80, extent=0.2") -## -## ## Estimation of the UD with grid=20 and extent=0.2 -## image(kernelUD(firs, grid=20, extent=3)) -## title(main="grid=20, extent=3") -## -## ## Estimation of the UD with grid=20 and extent=0.2 -## image(kernelUD(firs, grid=80, extent=3)) -## title(main="grid=80, extent=3") - - -################################################### -### code chunk number 66: adehabitatHR.Rnw:952-955 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -## The relocations of "Brock" -locs <- puechabonsp$relocs -firs <- locs[as.data.frame(locs)[,1]=="Brock",] - -## Graphical parameters -par(mar=c(0,0,2,0)) -par(mfrow=c(2,2)) - -## Estimation of the UD with grid=20 and extent=0.2 -image(kernelUD(firs, grid=20, extent=0.2)) -title(main="grid=20, extent=0.2") - -## Estimation of the UD with grid=20 and extent=0.2 -image(kernelUD(firs, grid=80, extent=0.2)) -title(main="grid=80, extent=0.2") - -## Estimation of the UD with grid=20 and extent=0.2 -image(kernelUD(firs, grid=20, extent=3)) -title(main="grid=20, extent=3") - -## Estimation of the UD with grid=20 and extent=0.2 -image(kernelUD(firs, grid=80, extent=3)) -title(main="grid=80, extent=3") -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 67: kskkssqq (eval = FALSE) -################################################### -## kus <- kernelUD(puechabonsp$relocs[,1], same4all=TRUE) -## image(kus) - - -################################################### -### code chunk number 68: adehabitatHR.Rnw:969-970 (eval = FALSE) -################################################### -## kus <- kernelUD(puechabonsp$relocs[,1], same4all=TRUE) -## image(kus) - - -################################################### -### code chunk number 69: adehabitatHR.Rnw:974-977 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -kus <- kernelUD(puechabonsp$relocs[,1], same4all=TRUE) -image(kus) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 70: adehabitatHR.Rnw:984-986 -################################################### -ii <- estUDm2spixdf(kus) -class(ii) - - -################################################### -### code chunk number 71: adehabitatHR.Rnw:1006-1007 -################################################### -kudm <- kernelUD(puechabonsp$relocs[,1], grid=puechabonsp$map) - - -################################################### -### code chunk number 72: adehabitatHR.Rnw:1034-1036 -################################################### -homerange <- getverticeshr(kudl) -class(homerange) - - -################################################### -### code chunk number 73: fig11 (eval = FALSE) -################################################### -## plot(homerange, col=1:4) - - -################################################### -### code chunk number 74: adehabitatHR.Rnw:1051-1052 (eval = FALSE) -################################################### -## plot(homerange, col=1:4) - - -################################################### -### code chunk number 75: adehabitatHR.Rnw:1056-1059 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(homerange, col=1:4) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 76: adehabitatHR.Rnw:1076-1078 -################################################### -vud <- getvolumeUD(kudl) -vud - - -################################################### -### code chunk number 77: fig12 (eval = FALSE) -################################################### -## -## ## Set up graphical parameters -## par(mfrow=c(2,1)) -## par(mar=c(0,0,2,0)) -## -## ## The output of kernelUD for the first animal -## image(kudl[[1]]) -## title("Output of kernelUD") -## -## ## Convert into a suitable data structure for -## ## the use of contour -## xyz <- as.image.SpatialGridDataFrame(kudl[[1]]) -## contour(xyz, add=TRUE) -## -## -## ## and similarly for the output of getvolumeUD -## par(mar=c(0,0,2,0)) -## image(vud[[1]]) -## title("Output of getvolumeUD") -## xyzv <- as.image.SpatialGridDataFrame(vud[[1]]) -## contour(xyzv, add=TRUE) - - -################################################### -### code chunk number 78: adehabitatHR.Rnw:1109-1110 (eval = FALSE) -################################################### -## -## ## Set up graphical parameters -## par(mfrow=c(2,1)) -## par(mar=c(0,0,2,0)) -## -## ## The output of kernelUD for the first animal -## image(kudl[[1]]) -## title("Output of kernelUD") -## -## ## Convert into a suitable data structure for -## ## the use of contour -## xyz <- as.image.SpatialGridDataFrame(kudl[[1]]) -## contour(xyz, add=TRUE) -## -## -## ## and similarly for the output of getvolumeUD -## par(mar=c(0,0,2,0)) -## image(vud[[1]]) -## title("Output of getvolumeUD") -## xyzv <- as.image.SpatialGridDataFrame(vud[[1]]) -## contour(xyzv, add=TRUE) - - -################################################### -### code chunk number 79: adehabitatHR.Rnw:1114-1117 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) - -## Set up graphical parameters -par(mfrow=c(2,1)) -par(mar=c(0,0,2,0)) - -## The output of kernelUD for the first animal -image(kudl[[1]]) -title("Output of kernelUD") - -## Convert into a suitable data structure for -## the use of contour -xyz <- as.image.SpatialGridDataFrame(kudl[[1]]) -contour(xyz, add=TRUE) - - -## and similarly for the output of getvolumeUD -par(mar=c(0,0,2,0)) -image(vud[[1]]) -title("Output of getvolumeUD") -xyzv <- as.image.SpatialGridDataFrame(vud[[1]]) -contour(xyzv, add=TRUE) -dev.null <- dev.off() -cat("\\includegraphics[height=14cm,width=14cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 80: kdkdkdk (eval = FALSE) -################################################### -## ## store the volume under the UD (as computed by getvolumeUD) -## ## of the first animal in fud -## fud <- vud[[1]] -## -## ## store the value of the volume under UD in a vector hr95 -## hr95 <- as.data.frame(fud)[,1] -## -## ## if hr95 is <= 95 then the pixel belongs to the home range -## ## (takes the value 1, 0 otherwise) -## hr95 <- as.numeric(hr95 <= 95) -## -## ## Converts into a data frame -## hr95 <- data.frame(hr95) -## -## ## Converts to a SpatialPixelsDataFrame -## coordinates(hr95) <- coordinates(vud[[1]]) -## gridded(hr95) <- TRUE -## -## ## display the results -## image(hr95) - - -################################################### -### code chunk number 81: adehabitatHR.Rnw:1151-1152 (eval = FALSE) -################################################### -## ## store the volume under the UD (as computed by getvolumeUD) -## ## of the first animal in fud -## fud <- vud[[1]] -## -## ## store the value of the volume under UD in a vector hr95 -## hr95 <- as.data.frame(fud)[,1] -## -## ## if hr95 is <= 95 then the pixel belongs to the home range -## ## (takes the value 1, 0 otherwise) -## hr95 <- as.numeric(hr95 <= 95) -## -## ## Converts into a data frame -## hr95 <- data.frame(hr95) -## -## ## Converts to a SpatialPixelsDataFrame -## coordinates(hr95) <- coordinates(vud[[1]]) -## gridded(hr95) <- TRUE -## -## ## display the results -## image(hr95) - - -################################################### -### code chunk number 82: adehabitatHR.Rnw:1156-1159 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -## store the volume under the UD (as computed by getvolumeUD) -## of the first animal in fud -fud <- vud[[1]] - -## store the value of the volume under UD in a vector hr95 -hr95 <- as.data.frame(fud)[,1] - -## if hr95 is <= 95 then the pixel belongs to the home range -## (takes the value 1, 0 otherwise) -hr95 <- as.numeric(hr95 <= 95) - -## Converts into a data frame -hr95 <- data.frame(hr95) - -## Converts to a SpatialPixelsDataFrame -coordinates(hr95) <- coordinates(vud[[1]]) -gridded(hr95) <- TRUE - -## display the results -image(hr95) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 83: adehabitatHR.Rnw:1172-1173 -################################################### -as.data.frame(homerange) - - -################################################### -### code chunk number 84: adehabitatHR.Rnw:1185-1187 -################################################### -ii <- kernel.area(kudl, percent=seq(50, 95, by=5)) -ii - - -################################################### -### code chunk number 85: figggf (eval = FALSE) -################################################### -## par(mar=c(0,0,0,0)) -## plot(c(0,1),asp=1, ty="n") -## bound <- structure(list(x = c(1.11651014886660, 1.31884344750132, 1.49071796999748, -## 1.56686491034388, 1.65171435815844, 1.627782462621, 1.59079680588132, -## 1.63648497008916), y = c(0.819277593991856, 0.797467606139553, -## 0.740761637723568, 0.609901710609753, 0.417973817509493, 0.263122903758146, -## 0.106090991221569, -0.00732094561040263)), .Names = c("x", "y" -## )) -## pts <- structure(list(x = c(1.14479329813812, 1.20135959668116, 1.18395458174484, -## 1.30143843256500, 1.29056029822980, 1.28620904449572, 1.31449219376724, -## 1.46896170132708, 1.39063913411364, 1.50377173119972, 1.627782462621, -## 1.57121616407796, 1.37758537291140, 1.21006210414932, 1.32537032810244, -## 1.519001119269, 1.46678607446004, 1.32754595496948, 1.17960332801076, -## 1.12303702946772, 1.19700834294708, 1.57121616407796, 1.57774304467908, -## 1.30578968629908, 1.60167494021652, 1.62995808948804, 1.5625136566098, -## 1.46896170132708, 1.43632729832148, 1.31449219376724), y = c(0.784381613428172, -## 0.732037642582647, 0.605539713039293, 0.559738738549458, 0.67315067538143, -## 0.749485632864488, 0.76257162557587, 0.714589652300805, 0.633892697247286, -## 0.330733866100284, 0.417973817509493, 0.527023756771005, 0.548833744623307, -## 0.378715839375349, 0.156253963281865, 0.287113890395679, 0.199873938986470, -## 0.354724852737816, 0.39180183208673, 0.311104877033211, 0.20423593655693, -## 0.106090991221569, 0.212959931697851, 0.780019615857712, 0.367810845449197, -## 0.424516813865184, 0.518299761630084, 0.601177715468833, 0.712408653515574, -## 0.703684658374653)), .Names = c("x", "y")) -## lines(bound) -## bound <- do.call("cbind",bound) -## Slo1 <- Line(bound) -## Sli1 <- Lines(list(Slo1), ID="frontier1") -## barrier <- SpatialLines(list(Sli1)) -## -## points(pts, pch=16) -## pts <- as.data.frame(pts) -## coordinates(pts) <- c("x","y") -## ii <- adehabitatHR:::.boundaryk(pts, barrier, 0.04) -## points(ii, pch=3) - - -################################################### -### code chunk number 86: adehabitatHR.Rnw:1250-1253 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -par(mar=c(0,0,0,0)) -plot(c(0,1),asp=1, ty="n") -bound <- structure(list(x = c(1.11651014886660, 1.31884344750132, 1.49071796999748, -1.56686491034388, 1.65171435815844, 1.627782462621, 1.59079680588132, -1.63648497008916), y = c(0.819277593991856, 0.797467606139553, -0.740761637723568, 0.609901710609753, 0.417973817509493, 0.263122903758146, -0.106090991221569, -0.00732094561040263)), .Names = c("x", "y" -)) -pts <- structure(list(x = c(1.14479329813812, 1.20135959668116, 1.18395458174484, -1.30143843256500, 1.29056029822980, 1.28620904449572, 1.31449219376724, -1.46896170132708, 1.39063913411364, 1.50377173119972, 1.627782462621, -1.57121616407796, 1.37758537291140, 1.21006210414932, 1.32537032810244, -1.519001119269, 1.46678607446004, 1.32754595496948, 1.17960332801076, -1.12303702946772, 1.19700834294708, 1.57121616407796, 1.57774304467908, -1.30578968629908, 1.60167494021652, 1.62995808948804, 1.5625136566098, -1.46896170132708, 1.43632729832148, 1.31449219376724), y = c(0.784381613428172, -0.732037642582647, 0.605539713039293, 0.559738738549458, 0.67315067538143, -0.749485632864488, 0.76257162557587, 0.714589652300805, 0.633892697247286, -0.330733866100284, 0.417973817509493, 0.527023756771005, 0.548833744623307, -0.378715839375349, 0.156253963281865, 0.287113890395679, 0.199873938986470, -0.354724852737816, 0.39180183208673, 0.311104877033211, 0.20423593655693, -0.106090991221569, 0.212959931697851, 0.780019615857712, 0.367810845449197, -0.424516813865184, 0.518299761630084, 0.601177715468833, 0.712408653515574, -0.703684658374653)), .Names = c("x", "y")) -lines(bound) -bound <- do.call("cbind",bound) -Slo1 <- Line(bound) -Sli1 <- Lines(list(Slo1), ID="frontier1") -barrier <- SpatialLines(list(Sli1)) - -points(pts, pch=16) -pts <- as.data.frame(pts) -coordinates(pts) <- c("x","y") -ii <- adehabitatHR:::.boundaryk(pts, barrier, 0.04) -points(ii, pch=3) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 87: mapelev (eval = FALSE) -################################################### -## image(puechabonsp$map) - - -################################################### -### code chunk number 88: adehabitatHR.Rnw:1296-1297 (eval = FALSE) -################################################### -## image(puechabonsp$map) - - -################################################### -### code chunk number 89: adehabitatHR.Rnw:1301-1304 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -image(puechabonsp$map) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 90: figboundary (eval = FALSE) -################################################### -## bound <- structure(list(x = c(701751.385381925, 701019.24105475, -## 700739.303517889, -## 700071.760160759, 699522.651915378, -## 698887.40904327, 698510.570051342, -## 698262.932999504, 697843.026694212, -## 698058.363261028), -## y = c(3161824.03387414, -## 3161824.03387414, 3161446.96718494, -## 3161770.16720425, 3161479.28718687, -## 3161231.50050539, 3161037.5804938, -## 3160294.22044937, 3159389.26039528, -## 3157482.3802813)), .Names = c("x", "y")) -## image(puechabonsp$map) -## lines(bound, lwd=3) - - -################################################### -### code chunk number 91: adehabitatHR.Rnw:1333-1334 (eval = FALSE) -################################################### -## bound <- structure(list(x = c(701751.385381925, 701019.24105475, -## 700739.303517889, -## 700071.760160759, 699522.651915378, -## 698887.40904327, 698510.570051342, -## 698262.932999504, 697843.026694212, -## 698058.363261028), -## y = c(3161824.03387414, -## 3161824.03387414, 3161446.96718494, -## 3161770.16720425, 3161479.28718687, -## 3161231.50050539, 3161037.5804938, -## 3160294.22044937, 3159389.26039528, -## 3157482.3802813)), .Names = c("x", "y")) -## image(puechabonsp$map) -## lines(bound, lwd=3) - - -################################################### -### code chunk number 92: adehabitatHR.Rnw:1338-1341 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -bound <- structure(list(x = c(701751.385381925, 701019.24105475, - 700739.303517889, - 700071.760160759, 699522.651915378, - 698887.40904327, 698510.570051342, - 698262.932999504, 697843.026694212, - 698058.363261028), - y = c(3161824.03387414, - 3161824.03387414, 3161446.96718494, - 3161770.16720425, 3161479.28718687, - 3161231.50050539, 3161037.5804938, - 3160294.22044937, 3159389.26039528, - 3157482.3802813)), .Names = c("x", "y")) -image(puechabonsp$map) -lines(bound, lwd=3) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 93: adehabitatHR.Rnw:1348-1353 -################################################### -## We convert bound to SpatialLines: -bound <- do.call("cbind",bound) -Slo1 <- Line(bound) -Sli1 <- Lines(list(Slo1), ID="frontier1") -barrier <- SpatialLines(list(Sli1)) - - -################################################### -### code chunk number 94: imagekudbound (eval = FALSE) -################################################### -## kud <- kernelUD(puechabonsp$relocs[,1], h=100, grid=100, boundary=barrier) -## image(kud) - - -################################################### -### code chunk number 95: adehabitatHR.Rnw:1364-1365 (eval = FALSE) -################################################### -## kud <- kernelUD(puechabonsp$relocs[,1], h=100, grid=100, boundary=barrier) -## image(kud) - - -################################################### -### code chunk number 96: adehabitatHR.Rnw:1369-1372 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -kud <- kernelUD(puechabonsp$relocs[,1], h=100, grid=100, boundary=barrier) -image(kud) -dev.null <- dev.off() -cat("\\includegraphics[height=14cm,width=14cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 97: brownbrid (eval = FALSE) -################################################### -## par(mar=c(0,0,0,0)) -## 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") -## kba <- kernelbb(tr, 0.6, 0.2, extent=0.8, grid=50) -## kba <- as(kba, "SpatialPixelsDataFrame") -## fullgrid(kba) <- TRUE -## uu <- slot(kba, "data")[,1] -## uu <- matrix(uu, nrow=50) -## persp(uu, theta = 135, phi = 30, scale = FALSE, -## ltheta = -120, shade = 0.75, border = NA, box = FALSE) - - -################################################### -### code chunk number 98: adehabitatHR.Rnw:1413-1416 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -par(mar=c(0,0,0,0)) -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") -kba <- kernelbb(tr, 0.6, 0.2, extent=0.8, grid=50) -kba <- as(kba, "SpatialPixelsDataFrame") -fullgrid(kba) <- TRUE -uu <- slot(kba, "data")[,1] -uu <- matrix(uu, nrow=50) -persp(uu, theta = 135, phi = 30, scale = FALSE, - ltheta = -120, shade = 0.75, border = NA, box = FALSE) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 99: adehabitatHR.Rnw:1426-1427 -################################################### -pt <- 16 - - -################################################### -### code chunk number 100: tutorkbb (eval = FALSE) -################################################### -## suppressWarnings(RNGversion("3.5.0")) -## 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)) -## ## 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, grid=60) -## ## Now fits the classical kernel home range -## coordinates(pts) <- c("x","y") -## kud <- kernelUD(pts) -## ###### The results -## opar <- par(mfrow=c(2,2), mar=c(0.1,0.1,2,0.1)) -## plot(pts, pch=16) -## title(main="The relocation pattern") -## box() -## plot(x, axes=FALSE, main="The trajectory") -## box() -## image(kud) -## title(main="Classical kernel home range") -## plot(getverticeshr(kud, 95), add=TRUE) -## box() -## image(kbb) -## title(main="Brownian bridge kernel home range") -## plot(getverticeshr(kbb, 95), add=TRUE) -## box() - - -################################################### -### code chunk number 101: adehabitatHR.Rnw:1482-1485 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -suppressWarnings(RNGversion("3.5.0")) -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)) -## 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, grid=60) -## Now fits the classical kernel home range -coordinates(pts) <- c("x","y") -kud <- kernelUD(pts) -###### The results -opar <- par(mfrow=c(2,2), mar=c(0.1,0.1,2,0.1)) -plot(pts, pch=16) -title(main="The relocation pattern") -box() -plot(x, axes=FALSE, main="The trajectory") -box() -image(kud) -title(main="Classical kernel home range") -plot(getverticeshr(kud, 95), add=TRUE) -box() -image(kbb) -title(main="Brownian bridge kernel home range") -plot(getverticeshr(kbb, 95), add=TRUE) -box() -dev.null <- dev.off() -cat("\\includegraphics[height=14cm,width=14cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 102: adehabitatHR.Rnw:1489-1490 -################################################### -pt <- 25 - - -################################################### -### code chunk number 103: adehabitatHR.Rnw:1532-1534 -################################################### -wi <- 800 -pt <- 18 - - -################################################### -### code chunk number 104: ploth (eval = FALSE) -################################################### -## 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]) -## } -## } -## -## ## Displays the results -## opar <- par(mar = c(0,0,2,0), mfrow = c(5,5)) -## foo <- function(x) -## { -## image(y[[x]]) -## title(main = names(y)[x]) -## points(tr[[1]][,c("x","y")], pch = 16) -## } -## tmp <- lapply(1:length(y), foo) -## - - -################################################### -### code chunk number 105: adehabitatHR.Rnw:1570-1573 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -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]) - } -} - -## Displays the results -opar <- par(mar = c(0,0,2,0), mfrow = c(5,5)) -foo <- function(x) -{ - image(y[[x]]) - title(main = names(y)[x]) - points(tr[[1]][,c("x","y")], pch = 16) -} -tmp <- lapply(1:length(y), foo) - -dev.null <- dev.off() -cat("\\includegraphics[height=14cm,width=14cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 106: adehabitatHR.Rnw:1578-1580 -################################################### -wi <- 600 -pt <- 25 - - -################################################### -### code chunk number 107: adehabitatHR.Rnw:1597-1600 -################################################### -data(puechcirc) -x <- puechcirc[1] -x - - -################################################### -### code chunk number 108: plotpuechcirc (eval = FALSE) -################################################### -## plot(x) - - -################################################### -### code chunk number 109: adehabitatHR.Rnw:1609-1610 (eval = FALSE) -################################################### -## plot(x) - - -################################################### -### code chunk number 110: adehabitatHR.Rnw:1614-1617 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(x) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 111: liker1 (eval = FALSE) -################################################### -## lik <- liker(x, sig2 = 58, rangesig1 = c(10, 100)) - - -################################################### -### code chunk number 112: adehabitatHR.Rnw:1634-1635 (eval = FALSE) -################################################### -## lik <- liker(x, sig2 = 58, rangesig1 = c(10, 100)) - - -################################################### -### code chunk number 113: adehabitatHR.Rnw:1639-1642 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -lik <- liker(x, sig2 = 58, rangesig1 = c(10, 100)) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 114: liker2 (eval = FALSE) -################################################### -## lik2 <- liker(x, sig2 = 58, rangesig1 = c(1, 10)) - - -################################################### -### code chunk number 115: adehabitatHR.Rnw:1653-1654 (eval = FALSE) -################################################### -## lik2 <- liker(x, sig2 = 58, rangesig1 = c(1, 10)) - - -################################################### -### code chunk number 116: adehabitatHR.Rnw:1658-1661 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -lik2 <- liker(x, sig2 = 58, rangesig1 = c(1, 10)) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 117: adehabitatHR.Rnw:1667-1668 -################################################### -lik2 - - -################################################### -### code chunk number 118: adehabitatHR.Rnw:1674-1676 -################################################### -tata <- kernelbb(x, sig1 = 6.23, sig2 = 58, grid = 50) -tata - - -################################################### -### code chunk number 119: UDkbb (eval = FALSE) -################################################### -## image(tata) -## plot(getverticeshr(tata, 95), add=TRUE, lwd=2) - - -################################################### -### code chunk number 120: adehabitatHR.Rnw:1688-1689 (eval = FALSE) -################################################### -## image(tata) -## plot(getverticeshr(tata, 95), add=TRUE, lwd=2) - - -################################################### -### code chunk number 121: adehabitatHR.Rnw:1693-1696 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -image(tata) -plot(getverticeshr(tata, 95), add=TRUE, lwd=2) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 122: figexe1 (eval = FALSE) -################################################### -## par(mar=c(0,0,0,0)) -## plot(c(0,1,2,3),c(0,1,0,1), pch=16, cex=4, xlim=c(-0.5, 3.5), -## ylim=c(-0.5, 1.5)) -## segments(0,0,1,1) -## segments(2,0,3,1) -## points(seq(2,3,length=8), seq(0,1,length=8), pch=16, cex=2) -## arrows(1,0.5, 2, 0.5, lwd=5) - - -################################################### -### code chunk number 123: adehabitatHR.Rnw:1723-1726 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -par(mar=c(0,0,0,0)) -plot(c(0,1,2,3),c(0,1,0,1), pch=16, cex=4, xlim=c(-0.5, 3.5), -ylim=c(-0.5, 1.5)) -segments(0,0,1,1) -segments(2,0,3,1) -points(seq(2,3,length=8), seq(0,1,length=8), pch=16, cex=2) -arrows(1,0.5, 2, 0.5, lwd=5) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 124: figillustrbb (eval = FALSE) -################################################### -## x1 <- c(0,0) -## x2 <- c(1,1) -## D <- 0.01 -## tt <- 0.1 -## foo <- function(x) -## { -## m <- c(tt,tt) -## xc <- x-m -## (1/(4*pi*D*(1-tt)))*exp(-(sum(xc*xc/D))/(4*pi*tt*(1-tt))) -## } -## xy <- as.matrix(expand.grid(seq(-0.1, 1.1, length=100), seq(-0.1, 1.1, length=100))) -## den <- sapply(1:nrow(xy), function(i) foo(xy[i,])) -## df <- data.frame(x=xy[,1], y=xy[,2], den=den) -## coordinates(df) <- c("x","y") -## gridded(df) <- TRUE -## -## par(mfrow=c(1,2), mar=c(0.1,0.1,0.1,0.1)) -## image(df) -## points(c(0,1), c(0,1), pch=16, cex=4) -## lines(c(0,1), c(0,1)) -## points(tt,tt, pch=16) -## box() -## tt <- 0.5 -## den <- sapply(1:nrow(xy), function(i) foo(xy[i,])) -## df <- data.frame(x=xy[,1], y=xy[,2], den=den) -## coordinates(df) <- c("x","y") -## gridded(df) <- TRUE -## image(df) -## points(c(0,1), c(0,1), pch=16, cex=4) -## lines(c(0,1), c(0,1)) -## points(tt,tt, pch=16) -## box() - - -################################################### -### code chunk number 125: adehabitatHR.Rnw:1821-1824 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -x1 <- c(0,0) -x2 <- c(1,1) -D <- 0.01 -tt <- 0.1 -foo <- function(x) -{ - m <- c(tt,tt) - xc <- x-m - (1/(4*pi*D*(1-tt)))*exp(-(sum(xc*xc/D))/(4*pi*tt*(1-tt))) -} -xy <- as.matrix(expand.grid(seq(-0.1, 1.1, length=100), seq(-0.1, 1.1, length=100))) -den <- sapply(1:nrow(xy), function(i) foo(xy[i,])) -df <- data.frame(x=xy[,1], y=xy[,2], den=den) -coordinates(df) <- c("x","y") -gridded(df) <- TRUE - -par(mfrow=c(1,2), mar=c(0.1,0.1,0.1,0.1)) -image(df) -points(c(0,1), c(0,1), pch=16, cex=4) -lines(c(0,1), c(0,1)) -points(tt,tt, pch=16) -box() -tt <- 0.5 -den <- sapply(1:nrow(xy), function(i) foo(xy[i,])) -df <- data.frame(x=xy[,1], y=xy[,2], den=den) -coordinates(df) <- c("x","y") -gridded(df) <- TRUE -image(df) -points(c(0,1), c(0,1), pch=16, cex=4) -lines(c(0,1), c(0,1)) -points(tt,tt, pch=16) -box() -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 126: adehabitatHR.Rnw:1890-1893 -################################################### -data(buffalo) -tr <- buffalo$traj -tr - - -################################################### -### code chunk number 127: trajbuff (eval = FALSE) -################################################### -## plot(tr, spixdf=buffalo$habitat) - - -################################################### -### code chunk number 128: adehabitatHR.Rnw:1904-1905 (eval = FALSE) -################################################### -## plot(tr, spixdf=buffalo$habitat) - - -################################################### -### code chunk number 129: adehabitatHR.Rnw:1909-1912 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(tr, spixdf=buffalo$habitat) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 130: adehabitatHR.Rnw:1926-1928 -################################################### -vv <- BRB.D(tr, Tmax=180*60, Lmin=50, habitat=buffalo$habitat, activity="act") -vv - - -################################################### -### code chunk number 131: adehabitatHR.Rnw:1943-1947 -################################################### -ud <- BRB(tr, D = vv, Tmax = 180*60, tau = 300, Lmin = 50, hmin=100, - habitat = buffalo$habitat, activity = "act", grid = 100, b=0, - same4all=FALSE, extent=0.01) -ud - - -################################################### -### code chunk number 132: imagebrb (eval = FALSE) -################################################### -## image(ud) - - -################################################### -### code chunk number 133: adehabitatHR.Rnw:1961-1962 (eval = FALSE) -################################################### -## image(ud) - - -################################################### -### code chunk number 134: adehabitatHR.Rnw:1966-1969 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -image(ud) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 135: figidrd (eval = FALSE) -################################################### -## id <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "ID", -## hmin=100, radius = 300, maxt = 2*3600, tau = 300, -## grid = 100, extent=0.1) -## rd <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "RD", -## hmin=100, radius = 300, maxt = 2*3600, tau = 300, -## grid = 100, extent=0.1) -## ud <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "UD", -## hmin=100, radius = 300, maxt = 2*3600, tau = 300, -## grid = 100, extent=0.1) -## -## -## par(mfrow = c(2,2), mar=c(0,0,2,0)) -## vid <- getvolumeUD(id) -## image(vid) -## contour(vid, add=TRUE, nlevels=1, levels=30, -## lwd=3, drawlabels=FALSE) -## title("ID") -## -## vrd <- getvolumeUD(rd) -## image(vrd) -## contour(vrd, add=TRUE, nlevels=1, levels=30, -## lwd=3, drawlabels=FALSE) -## title("RD") -## -## vud <- getvolumeUD(ud) -## image(vud) -## contour(vud, add=TRUE, nlevels=1, levels=95, -## lwd=3, drawlabels=FALSE) -## title("UD") - - -################################################### -### code chunk number 136: adehabitatHR.Rnw:2069-2070 (eval = FALSE) -################################################### -## id <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "ID", -## hmin=100, radius = 300, maxt = 2*3600, tau = 300, -## grid = 100, extent=0.1) -## rd <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "RD", -## hmin=100, radius = 300, maxt = 2*3600, tau = 300, -## grid = 100, extent=0.1) -## ud <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "UD", -## hmin=100, radius = 300, maxt = 2*3600, tau = 300, -## grid = 100, extent=0.1) -## -## -## par(mfrow = c(2,2), mar=c(0,0,2,0)) -## vid <- getvolumeUD(id) -## image(vid) -## contour(vid, add=TRUE, nlevels=1, levels=30, -## lwd=3, drawlabels=FALSE) -## title("ID") -## -## vrd <- getvolumeUD(rd) -## image(vrd) -## contour(vrd, add=TRUE, nlevels=1, levels=30, -## lwd=3, drawlabels=FALSE) -## title("RD") -## -## vud <- getvolumeUD(ud) -## image(vud) -## contour(vud, add=TRUE, nlevels=1, levels=95, -## lwd=3, drawlabels=FALSE) -## title("UD") - - -################################################### -### code chunk number 137: adehabitatHR.Rnw:2074-2077 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -id <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "ID", - hmin=100, radius = 300, maxt = 2*3600, tau = 300, - grid = 100, extent=0.1) -rd <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "RD", - hmin=100, radius = 300, maxt = 2*3600, tau = 300, - grid = 100, extent=0.1) -ud <- BRB(buffalo$traj, D = 7.36, Tmax = 3*3600, Lmin = 50, type = "UD", - hmin=100, radius = 300, maxt = 2*3600, tau = 300, - grid = 100, extent=0.1) - - -par(mfrow = c(2,2), mar=c(0,0,2,0)) -vid <- getvolumeUD(id) -image(vid) -contour(vid, add=TRUE, nlevels=1, levels=30, - lwd=3, drawlabels=FALSE) -title("ID") - -vrd <- getvolumeUD(rd) -image(vrd) -contour(vrd, add=TRUE, nlevels=1, levels=30, - lwd=3, drawlabels=FALSE) -title("RD") - -vud <- getvolumeUD(ud) -image(vud) -contour(vud, add=TRUE, nlevels=1, levels=95, - lwd=3, drawlabels=FALSE) -title("UD") -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 138: adehabitatHR.Rnw:2155-2157 -################################################### -data(bear) -bear - - -################################################### -### code chunk number 139: adehabitatHR.Rnw:2166-2169 -################################################### -uu <- kernelkc(bear, h = c(1000,1000,72*3600), - tcalc= as.POSIXct("2004-05-01"), grid=50) -uu - - -################################################### -### code chunk number 140: plotuu (eval = FALSE) -################################################### -## plot(bear, spixdf=uu) - - -################################################### -### code chunk number 141: adehabitatHR.Rnw:2180-2181 (eval = FALSE) -################################################### -## plot(bear, spixdf=uu) - - -################################################### -### code chunk number 142: adehabitatHR.Rnw:2185-2188 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(bear, spixdf=uu) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 143: adehabitatHR.Rnw:2196-2197 -################################################### -sum(slot(uu,"data")[,1])*(gridparameters(uu)[1,2]^2) - - -################################################### -### code chunk number 144: plotver (eval = FALSE) -################################################### -## ver <- getverticeshr(uu, percent=95, standardize=TRUE) -## image(uu) -## plot(ver, add=TRUE) - - -################################################### -### code chunk number 145: adehabitatHR.Rnw:2221-2222 (eval = FALSE) -################################################### -## ver <- getverticeshr(uu, percent=95, standardize=TRUE) -## image(uu) -## plot(ver, add=TRUE) - - -################################################### -### code chunk number 146: adehabitatHR.Rnw:2226-2229 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -ver <- getverticeshr(uu, percent=95, standardize=TRUE) -image(uu) -plot(ver, add=TRUE) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 147: adehabitatHR.Rnw:2241-2273 (eval = FALSE) -################################################### -## ## 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], grid=50) -## -## ## To save the result in a file, type -## jpeg(paste("UD", i, ".jpg", sep="")) -## -## -## ## draw the image -## image(uu, col=grey(seq(1,0,length=10))) -## title(main=vv[i]) -## -## ## highlight the 95 percent home range -## ## we set standardize = TRUE because we want to estimate -## ## the home range in space from a UD estimated in space and -## ## time -## plot(getverticeshr(uu, 95, standardize=TRUE), lwd=2, -## border="red", add=TRUE) -## -## ## close the device -## dev.off() -## }) - - -################################################### -### code chunk number 148: adehabitatHR.Rnw:2297-2298 -################################################### -t0 <- as.POSIXct("2012-12-25 00:00") - - -################################################### -### code chunk number 149: exwc (eval = FALSE) -################################################### -## exwc(0.2) - - -################################################### -### code chunk number 150: adehabitatHR.Rnw:2309-2310 (eval = FALSE) -################################################### -## exwc(0.2) - - -################################################### -### code chunk number 151: adehabitatHR.Rnw:2314-2317 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -exwc(0.2) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 152: imagekernelkc1 (eval = FALSE) -################################################### -## uu <- kernelkc(bear, h=c(1000,1000,0.2), cycle=24*3600, -## tcalc=3*3600, t0=t0, circular=TRUE) -## image(uu) - - -################################################### -### code chunk number 153: adehabitatHR.Rnw:2333-2334 (eval = FALSE) -################################################### -## uu <- kernelkc(bear, h=c(1000,1000,0.2), cycle=24*3600, -## tcalc=3*3600, t0=t0, circular=TRUE) -## image(uu) - - -################################################### -### code chunk number 154: adehabitatHR.Rnw:2338-2341 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -uu <- kernelkc(bear, h=c(1000,1000,0.2), cycle=24*3600, - tcalc=3*3600, t0=t0, circular=TRUE) -image(uu) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 155: adehabitatHR.Rnw:2403-2405 -################################################### -uu <- clusthr(puechabonsp$relocs[,1]) -class(uu) - - -################################################### -### code chunk number 156: kkkssssm (eval = FALSE) -################################################### -## plot(uu) - - -################################################### -### code chunk number 157: adehabitatHR.Rnw:2418-2419 (eval = FALSE) -################################################### -## plot(uu) - - -################################################### -### code chunk number 158: adehabitatHR.Rnw:2423-2426 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(uu) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 159: adehabitatHR.Rnw:2433-2434 -################################################### -as.data.frame(uu[[3]]) - - -################################################### -### code chunk number 160: ksqkskq (eval = FALSE) -################################################### -## plot(uu[[3]][26,]) - - -################################################### -### code chunk number 161: adehabitatHR.Rnw:2446-2447 (eval = FALSE) -################################################### -## plot(uu[[3]][26,]) - - -################################################### -### code chunk number 162: adehabitatHR.Rnw:2451-2454 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(uu[[3]][26,]) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 163: sldlsl (eval = FALSE) -################################################### -## uur <- MCHu.rast(uu, puechabonsp$map, percent=90) -## image(uur, 3) - - -################################################### -### code chunk number 164: adehabitatHR.Rnw:2471-2472 (eval = FALSE) -################################################### -## uur <- MCHu.rast(uu, puechabonsp$map, percent=90) -## image(uur, 3) - - -################################################### -### code chunk number 165: adehabitatHR.Rnw:2476-2479 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -uur <- MCHu.rast(uu, puechabonsp$map, percent=90) -image(uur, 3) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 166: adehabitatHR.Rnw:2490-2491 -################################################### -head(as.data.frame(uu[[1]])) - - -################################################### -### code chunk number 167: slqllqq (eval = FALSE) -################################################### -## ii <- MCHu2hrsize(uu, percent=seq(50, 100, by=5)) - - -################################################### -### code chunk number 168: adehabitatHR.Rnw:2505-2506 (eval = FALSE) -################################################### -## ii <- MCHu2hrsize(uu, percent=seq(50, 100, by=5)) - - -################################################### -### code chunk number 169: adehabitatHR.Rnw:2510-2513 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -ii <- MCHu2hrsize(uu, percent=seq(50, 100, by=5)) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - -################################################### -### code chunk number 170: adehabitatHR.Rnw:2572-2573 (eval = FALSE) -################################################### -## res <- LoCoH.k(puechabonsp$relocs[,1], 10) - - -################################################### -### code chunk number 171: adehabitatHR.Rnw:2583-2584 (eval = FALSE) -################################################### -## plot(res) - - -################################################### -### code chunk number 172: adehabitatHR.Rnw:2591-2593 (eval = FALSE) -################################################### -## LoCoH.k.area(puechabonsp$relocs[,1], krange=seq(4, 15, length=5), -## percent=100) - - -################################################### -### code chunk number 173: adehabitatHR.Rnw:2615-2617 -################################################### -res <- CharHull(puechabonsp$relocs[,1]) -class(res) - - -################################################### -### code chunk number 174: plotcharhul (eval = FALSE) -################################################### -## plot(res) - - -################################################### -### code chunk number 175: adehabitatHR.Rnw:2633-2634 (eval = FALSE) -################################################### -## plot(res) - - -################################################### -### code chunk number 176: adehabitatHR.Rnw:2638-2641 -################################################### -.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", - .PngNo, ".png", sep="") -png(file=file, width = wi, height = wi, pointsize = pt) -plot(res) -dev.null <- dev.off() -cat("\\includegraphics[height=7cm,width=7cm]{", file, "}\n\n", sep="") - - diff --git a/vignettes/adehabitatHR.Rnw b/vignettes/adehabitatHR.Rnw index 051435e..af957a8 100755 --- a/vignettes/adehabitatHR.Rnw +++ b/vignettes/adehabitatHR.Rnw @@ -17,7 +17,7 @@ the {\tt adehabitatHR} Package } Office national de la classe et de la faune sauvage\\ Saint Benoist -- 78610 Auffargis -- France.} -\date{Mar 2019} +\date{Apr 2023} \begin{document} @@ -257,9 +257,9 @@ class(clu2[[2]]) @ Although each \texttt{SpatialPolygonsDataFrame} of the list can be -easily handled by the functions of the package \texttt{sp} and -relatives (\texttt{maptools}, etc.), the package \texttt{adehabitatHR} also -contains functions allowing to deal with such lists. For example: +easily handled by the functions of the package \texttt{sp}, the +package \texttt{adehabitatHR} also contains functions allowing to deal +with such lists. For example: <>= plot(clu2) @@ -377,7 +377,7 @@ class(cp) @ Therefore the functions available in the package \texttt{sp} and -related packages (\texttt{maptools}, etc.) are available to deal with +related packages (\texttt{sf}, etc.) are available to deal with these objects. For example, the function \texttt{plot}: @@ -398,17 +398,17 @@ plot(puechabonsp$relocs, add=TRUE) @ \end{center} -Similarly, the function \texttt{writePolyShape} from the package -\texttt{maptools} can be used to export the object \texttt{cp} to a -shapefile, so that it can be read into a GIS: +Similarly, the function \texttt{st\_write} from the package \texttt{sf} +can be used to export the object \texttt{cp} to a shapefile (after +conversion to the class sf), so that it can be read into a GIS: <<>>= -library(maptools) +library(sf) @ <>= -writePolyShape(cp, "homerange") +st_write(st_as_sf(cp), "homerange.shp") @ The resulting shapefils can be read in any GIS. @@ -1039,7 +1039,7 @@ class(homerange) The resulting object is of the class \texttt{SpatialPolygonsDataFrame}. Therefore, as for the MCP (see previous section), the functions of the package \texttt{sp} and -\texttt{maptools} are available to deal with this object, or to export +\texttt{sf} are available to deal with this object, or to export it toward a GIS (see section 3.2 for examples). Therefore, to display the home range: @@ -2557,11 +2557,7 @@ functions \texttt{LoCoH.k}, \texttt{LoCoH.r} and \texttt{LoCoH.a}):\\ function \texttt{LoCoH.a};\\ \end{itemize} -All of these algorithms can take a significant amount of time.\\ - -\noindent \textit{Note}: these functions rely on the availability of -the packages rgeos and gpclib, which may not be available for all OS -(especially MacOS). +All of these algorithms can take a significant amount of time. \subsection{Example with the Fixed k LoCoH method} diff --git a/vignettes/adehabitatHR.pdf b/vignettes/adehabitatHR.pdf deleted file mode 100644 index 80cfc88..0000000 Binary files a/vignettes/adehabitatHR.pdf and /dev/null differ