Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid too small for kernelUD /getverticeshr/adehabitatHR home range estimation

Tags:

r

adehabitathr

The documentation for adehabitat HR recommends the following code for calculating a 95% kernel for a home range after creating the UD object:

 ## Calculation of the 95 percent home range
    ver <- getverticeshr(ud, 95)

For some of my data, the following error appears:

Error in getverticeshr.estUD(x[[i]], percent, ida = names(x)[i], unin,  : 
  The grid is too small to allow the estimation of home-range.
You should rerun kernelUD with a larger extent parameter

On a Nabble forum people recommending changing the "grid" and "extent" inputs, but I wasn't able to get any better results after using numerous combinations of these 2 parameters. Any suggestions?

like image 272
Perry Helion Avatar asked Jan 16 '17 19:01

Perry Helion


1 Answers

This a common issue I've found in some forums. But the answer is simple and is exactly in the error message. "You need to extent your grid". This is happening because when you apply getverticeshr(ud, 95) part of the polygons is out of the grid, so it is not possible to get an area. For example, in the below code, KDE is estimated for two hypothetical animals. I use random points from 0 to 100, so I have defined a grid 100x100 (Domain).

#"""
# Language: R script
# This is a temporary script file.
#"""

# 1. Packages
library(adehabitatHR)         # Package for spatal analysis

# 2. Empty Dataframe
points <- data.frame(ID = double())
XY_cor <- data.frame(X = double(),
                     Y = double())
# 3. Assigning values (this will be our spatial coordinates)
set.seed(17)
for(i in c(1:100)){
    if(i >= 50){points[i, 1] <- 1}
    else {points[i, 1] <- 2}
    XY_cor[i, 1] <- runif(1, 0, 100)
    XY_cor[i, 2] <- runif(1, 0, 100)}

# 4. Transform to SpatialDataframe
coordinates(points) <- XY_cor[, c("X", "Y")]
class(points)

# 5. Domain
x <- seq(0, 100, by=1.) # resolution is the pixel size you desire 
y <- seq(0, 100, by=1.)
xy <- expand.grid(x=x,y=y)
coordinates(xy) <- ~x+y
gridded(xy) <- TRUE
class(xy)

# 6. Kernel Density
kud_points <- kernelUD(points, h = "href", grid = xy)
image(kud_points)

# 7. Get the Volum
vud_points <- getvolumeUD(kud_points)

# 8. Get contour
levels <- c(50, 75, 95)
list <- vector(mode="list", length = 2)

list[[1]] <- as.image.SpatialGridDataFrame(vud_points[[1]])
list[[2]] <- as.image.SpatialGridDataFrame(vud_points[[2]])

# 9. Plot
par(mfrow = c(2, 1))
image(vud_points[[1]])
contour(list[[1]], add=TRUE, levels=levels)
image(vud_points[[2]])
contour(list[[2]], add=TRUE, levels=levels)

enter image description here enter image description here

The plot shows that the contour to 50% is inside the grid, but 75% contour is cut, this means part of this one is out.

If you try to estimate vertices of KDE to 50% you will obtain a fine result:

# 10. Get vertices (It will be fine)
vkde_points <- getverticeshr(kud_points, percent = 50,
                                 unin = 'm', unout='m2')
plot(vkde_points)

But if you try with 75% level you will obtain the classical error: Error in getverticeshr.estUD(x[[i]], percent, ida = names(x)[i], unin, : The grid is too small to allow the estimation of home-range. You should rerun kernelUD with a larger extent parameter

# 10. Get vertices (Will be an Error)
vkde_points <- getverticeshr(kud_points, percent = 75,
                                 unin = 'm', unout='m2')
plot(vkde_points)

Now, you can see clearly what is happening, R can't estimate the vertices to 75% because they are outside of the grid, so you need to increase the domain (grid)! Here I will increase the domain in 50 (see # 5. Domain)

# 5. Domain                 HERE GRID IS INCREASED 50 AT X AND Y!!
x <- seq(-50, 150, by=1.) # resolution is the pixel size you desire 
y <- seq(-50, 150, by=1.)
xy <- expand.grid(x=x,y=y)
coordinates(xy) <- ~x+y
gridded(xy) <- TRUE
class(xy)

# 6. Kernel Density
kud_points <- kernelUD(points, h = "href", grid = xy)
image(kud_points)

# 7. Get the Volum
vud_points <- getvolumeUD(kud_points)

# 8. Get contour
levels <- c(50, 75, 95)
list <- vector(mode="list", length = 2)

list[[1]] <- as.image.SpatialGridDataFrame(vud_points[[1]])
list[[2]] <- as.image.SpatialGridDataFrame(vud_points[[2]])

# 9. Plot
par(mfrow = c(2, 1))
image(vud_points[[1]])
contour(list[[1]], add=TRUE, levels=levels)
image(vud_points[[2]])
contour(list[[2]], add=TRUE, levels=levels)

enter image description here enter image description here

You can see all the contours are inside the grid (domain). So, now you will be able to estimate the vertices.

# 10. Get vertices
vkde_points <- getverticeshr(kud_points, percent = 75,
                                 unin = 'm', unout='m2')
plot(vkde_points)
like image 75
Irbin B. Avatar answered Nov 14 '22 13:11

Irbin B.