0

I'm trying to calculate home range size of individuals. So, I'm studying several functions in adehabitatHR package, including MCP(), KernelUD(), kernellbb() and BRB().

I'd like to use same grid of background for those analyses. so I made a grid like this, after read this link and this link.

> str(GU2)
'data.frame':   2669 obs. of  5 variables:
 $ month     : int  2 2 2 2 2 2 2 2 2 2 ...
 $ Collecting: POSIXct, format: "2023-02-04 00:01:00" ...
 $ Longitude : num  108181 108170 108050 108007 107973 ...
 $ Latitude  : num  510220 510186 510133 510114 510075 ..

# Setting CRS 
> coordinates(GU2) <- c("Longitude", "Latitude")
> proj4string(GU2) <- CRS("+proj=longlat +datum=WGS84 +no_defs") #+init=epsg:4326
> GU2 <- spTransform(GU2, CRS("+proj=tmerc +lat_0=38 +lon_0=127 +k=1 +x_0=200000 +y_0=600000 
                           +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"))
# Grid
> x <- seq(min(GU2$Longitude), max(GU2$Longitude), by=50) 
> y <- seq(min(GU2$Latitude), max(GU2$Latitude), by=50)
> xy <- expand.grid(x=x,y=y)
> coordinates(xy) <- ~x+y
> gridded(xy) <- TRUE
> proj4string(xy) <- CRS("+proj=tmerc +lat_0=38 +lon_0=127 +k=1 +x_0=200000 +y_0=600000 
                           +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs") 

# BBMM analysis
> GU2_traj <- as.ltraj(xy = GU2[,c("Latitude", "Longitude")],
                 date = GU2$Collecting, 
                 id = GU2$month)
> GU2_bbmm.2 <- kernelbb(GU2_traj[1], sig1 =0.42, sig2 = 109.06, grid = xy)

However, there is no data in 'GU2_bbmm.2' (Please, look at the 'GU2_bbmm.2@data$ud')

> str(GU2_bbmm.2)
Formal class 'estUD' [package "adehabitatHR"] with 9 slots
  ..@ h          :List of 2
  .. ..$ values: Named num [1:2] 1.76e-01 1.19e+04
  .. .. ..- attr(*, "names")= chr [1:2] "sig12" "sig22"
  .. ..$ meth  : chr "BB-specified"
  ..@ vol        : logi FALSE
  ..@ data       :'data.frame': 837 obs. of  1 variable:
  .. ..$ ud: num [1:837] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
  ..@ coords.nrs : num(0) 
  ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots
  .. .. ..@ cellcentre.offset: Named num [1:2] 107863 509840
  .. .. .. ..- attr(*, "names")= chr [1:2] "Var2" "Var1"
  .. .. ..@ cellsize         : Named num [1:2] 50 50
  .. .. .. ..- attr(*, "names")= chr [1:2] "Var2" "Var1"
  .. .. ..@ cells.dim        : Named int [1:2] 31 27
  .. .. .. ..- attr(*, "names")= chr [1:2] "Var2" "Var1"
  ..@ grid.index : int [1:837] 1 32 63 94 125 156 187 218 249 280 ...
  ..@ coords     : num [1:837, 1:2] 107863 107863 107863 107863 107863 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:2] "Var2" "Var1"
  ..@ bbox       : num [1:2, 1:2] 107838 509815 109388 511165
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "Var2" "Var1"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr "+proj=tmerc +lat_0=38 +lon_0=127 +k=1 +x_0=200000 +y_0=600000 +ellps=GRS80 +units=m +no_defs"
  .. .. ..$ comment: chr "PROJCRS[\"unknown\",\n    BASEGEOGCRS[\"unknown\",\n        DATUM[\"Unknown based on GRS80 ellipsoid\",\n      "| __truncated__

Using the same grid, BRB() function also made only NaNs. But kernelUD() works well.

When I put 50 in the grid argument of kernellbb() and BRB() function, they works. So I think my grid is something wrong. How can I make an appropriate grid for the functions in adehabitatHR package?

  • It's possible that different functions handle grid making or grid input differently. When I looked at `sp:coordinates` fn help page, it became fairly clear that it expected an n x m array or similar data structure. Other functions may accept a specification of `~x+y`. Realize that multiple packages have `coordinate` functions. Both pkg:raster and pkg:sp have a function by that name and there may be other. It's sometimes that case that pkgs will copy from another package. You need to check. Is there is a utility function delivering all the packages with a given function name? I don't know. – IRTFM Jun 29 '23 at 01:07
  • @IRTFM To make a grid, I copy the code from this [link](https://stackoverflow.com/questions/41683905/grid-too-small-for-kernelud-getverticeshr-adehabitathr-home-range-estimation). I could not find the reason of this problem. I also checked calling pkg did not make any change. – pineapple159 Jun 29 '23 at 10:14
  • Deleted my first comment bc it was not correct. Appears from the help page for `kernelbb` that it uses parameters to build a grid rather than having a grid delivered to it. Suggest you review the parameter's description and then review the Examples section. – IRTFM Jun 29 '23 at 21:16

0 Answers0