0

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
  • did you try other values for `by` instead of 1? – rawr Oct 05 '20 at 07:50
  • I tried extent = 2 in the kernelUD function, but I got the same issue. I havent tried by =2 which I can now. But I assume that will change everything as (please correct me if I am wrong) the grid, when expanded, will call two values between grid points instead of 1. Correct? Just tried grid = 2 and coordinates function gives me error again. `> coordinates(xy) <- ~x+y Error: cannot allocate vector of size 1.7 Gb` – Srivats Chari Oct 05 '20 at 07:59
  • 1
    no instead of a sequence from min to max temp by 1 unit, it would go by 2 units. if x and y are in the range of 100k - millions, you probably dont need that level of granularity either – rawr Oct 05 '20 at 08:05
  • So does that mean I could also use by = 5 or even 10? And it would only change the grid size but would not impact the results from the KernelUD function. Correct? – Srivats Chari Oct 05 '20 at 08:15
  • 1
    your code is not actually using the `expand.grid` output, it is just taking up space in memory. the error seems to refer to the value of `kernelUD(..., grid = )`, and if 1000 was too small then 5 and 10 would be as well – rawr Oct 05 '20 at 08:23

1 Answers1

1

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. :)