Search code examples
rr-spadehabitathr

Computing HR using Kernel Density. Grid issues?


My dataset includes animal locations and id. What I am trying to do is that I am trying to compute Home Range using kernel density function. As my dataset was huge, I tried it splitting the dataset into two.

> library(sp)
> library(adehabitatHR)
> head(temp)
   id        x       y
92 10 480147.6 3112738
93 10 480081.6 3112663
94 10 479992.6 3112667
95 10 479972.4 3112759
96 10 479931.7 3112758
97 10 479970.7 3112730

Each dataset has 99586 observations which include 190 unique IDs. As a result, I am unable to produce a reproducible dataset.

When I try to use the kernelUD function, I have no problems computing. When I try to get the 95% of HR, it gives me error.

> kernel_temp<- kernelUD(temp)
> kernel_95 <- getverticeshr(kernel_temp, percent = 95)
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

So I search about this problem and I find out a solution. I pass the grid function now with the given grid for the points and I get another error for creating the grid coordinates.

> x <- seq(min(temp$x),max(temp$x),by=1.)
> y <- seq(min(temp$y),max(temp$y),by=1.)
> xy <- expand.grid(x=x,y=y)
> gc()
> coordinates(xy) <- ~x+y
Error: cannot allocate vector of size 6.7 Gb

I have a windows system with 32gb ram, I have been checking my processes and I see that I have RAM remaining but R is unable to allot.

Moving ahead I passed a random grid value just to see if it worked, but still the same error.

> kernel_temp<- kernelUD(temp, grid = 1000)
> kernel_95 <- getverticeshr(kernel_temp, percent = 95)
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

When I expand the xy grid- I see my observations are observationsw

which is huge. I wanted to know if there was any easier way of computing the HR or passing the grid function without the grid being so huge?

Any help is greatly appriciated. :)

EDIT- I tried extent = 2 and having the same problem.

> kernel_temp<- kernelUD(temp, extent = 2)
> kernel_95 <- getverticeshr(kernel_temp, percent = 95)
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

Solution

  • After a few more consultations from friends and colleagues, I found the answer.

    When you have numerous locations, the best way to calculate HR with KDE is by playing around with the grid size and the extent. Lower the grid and increase the extent is the best answer for this.

    In this case, I was able to calculate HR with-

    kernelUD(locs_year,grid = 500, h="href", extent = 5)

    I tried with multiple methods grid=1000 but still was not able to. grid = 500, extent = 5 was the sweet spot.!

    Thank you for your help.! And not sure but someday, it this answer mind be useful to someone. :)