2

I am trying to create kernel density estimates (KDEs) to estimate the home ranges for multiple pairs of long-tailed tits. Despite filtering out pairs ("nest_id" variable) that have less than five GPS locations, I still get the error message "At least 5 relocations are required to fit an home range" when trying to create kernelUDs for all individuals. I'm not sure exactly what the problem is/what I'm doing wrong. I am very new to home range analyses in general, as well as in R and adehabitatHR. Below is my code.

library(dplyr)
# reading in location data
locations <- read.csv("./data/GPS_LOCATIONS_MASTER.csv")

## making nest_id a factor
locations$nest_id <- as.factor(locations$nest_id)

## filtering for points I want to include
location_sub <- filter(locations, start_at_nest == "no")

## taking out pairs (via nest_id) with less than 5 GPS locations
xorig <- subset(location_sub,
                with(location_sub,
                     nest_id %in% names(which(table(nest_id) >= 5))))

glimpse(xorig)


Observations: 257
Variables: 10
$ point_id          <int> 293, 294, 299, 300, 303, 306, 307, 312, 315, 318, 324…
$ nest_id           <fct> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,…
$ female_id         <fct> RPR, RPR, RPR, RPR, RPR, RPR, RPR, RPR, RPR, RPR, RPR…
$ male_id           <fct> OWL, OWL, OWL, OWL, OWL, OWL, OWL, OWL, OWL, OWL, OWL…
$ lat               <dbl> 53.38293, 53.38285, 53.38282, 53.38302, 53.38300, 53.…
$ lon               <dbl> -1.554700, -1.554000, -1.553967, -1.554067, -1.553867…
$ start_at_nest     <fct> no, no, no, no, no, no, no, no, no, no, no, no, no, n…
$ place_in_sequence <int> 3, 1, 3, 4, 3, 3, 4, 3, 3, 3, 3, 4, 5, 1, 2, 3, 4, 5,…
$ date_time         <fct> 2019-02-27T13:26:31Z, 2019-02-27T13:28:46Z, 2019-02-2…
$ notes             <fct> , , , , , , , , , , , , , , , , , , , , , , , , , , 


library(sp)

## projecting so that my x & y (in coords.x1 & coords.x2) are in metres
xorig_s <- SpatialPointsDataFrame(xorig,
                                  coords = cbind(xorig$lon, xorig$lat),
                                  proj4string =  CRS("+proj=longlat +datum=WGS84 +no_defs"))
xorig_utm <- spTransform(xorig_s, CRS("+proj=utm +zone=30 +ellps=WGS84 
                                      +datum=WGS84 +units=m +no_defs"))
glimpse(as.data.frame(xorig_utm))

Observations: 257
Variables: 12
$ point_id          <int> 293, 294, 299, 300, 303, 306, 307, 312, 315, 318, 324…
$ nest_id           <fct> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,…
$ female_id         <fct> RPR, RPR, RPR, RPR, RPR, RPR, RPR, RPR, RPR, RPR, RPR…
$ male_id           <fct> OWL, OWL, OWL, OWL, OWL, OWL, OWL, OWL, OWL, OWL, OWL…
$ lat               <dbl> 53.38293, 53.38285, 53.38282, 53.38302, 53.38300, 53.…
$ lon               <dbl> -1.554700, -1.554000, -1.553967, -1.554067, -1.553867…
$ start_at_nest     <fct> no, no, no, no, no, no, no, no, no, no, no, no, no, n…
$ place_in_sequence <int> 3, 1, 3, 4, 3, 3, 4, 3, 3, 3, 3, 4, 5, 1, 2, 3, 4, 5,…
$ date_time         <fct> 2019-02-27T13:26:31Z, 2019-02-27T13:28:46Z, 2019-02-2…
$ notes             <fct> , , , , , , , , , , , , , , , , , , , , , , , , , , 
$ coords.x1         <dbl> 596131.3, 596178.1, 596180.4, 596173.3, 596186.6, 596…
$ coords.x2         <dbl> 5915843, 5915835, 5915831, 5915853, 5915852, 5915848,…

library(adehabitatHR)

## trying to create :
kud <- kernelUD(xorig_utm[,1], h = "href")
## this procures the error message:
Error in kernelUD(xorig_utm[, 1], h = "href") : 
  At least 5 relocations are required to fit an home range
krads
  • 1,350
  • 8
  • 14
Tobit
  • 41
  • 7

1 Answers1

1

Updated to point to the current version of kernelUD() function documentation:

help docs for kernelUD

Usage

kernelUD(xy, h = "href", grid = 60,
         same4all = FALSE, hlim = c(0.1, 1.5),
         kern = c("bivnorm", "epa"), extent = 1,
         boundary = NULL)

...

Arguments

xy 

An object inheriting the class SpatialPoints containing the x and y relocations
of the animal. If xy inherits the class SpatialPointsDataFrame, it should contain
only one column (factor) corresponding to the identity of the animals for
each relocation.

So using above, you might also use the Vignette where there is an example you may already be following:

I give below a short example of the use of kernelUD, using the puechabonsp dataset. Remember that the first column of the component relocs of this dataset contains the identity of the animals:

> data(puechabonsp)
> kud <- kernelUD(puechabonsp$relocs[,1], h="href")
> kud

One way to understand what you need for above xy is to print out the example data included in the package example:

data("puechabonsp")
head( puechabonsp$relocs[,1] )


            coordinates  Name
    1 (699889, 3161560) Brock
    2 (700046, 3161540) Brock
    3 (698840, 3161030) Brock
    4 (699809, 3161500) Brock
    5 (698627, 3160940) Brock
    6 (698719, 3160990) Brock
    Coordinate Reference System (CRS) arguments: NA 

Note above, puechabonsp$relocs[,1] is a SpatialPointsDataFrame object containing both the coordinates and the ID (which is 'Name' above).

Moving on from here, look at the ?SpatialPointsDataFrame help to understand that function and the object it creates:

Usage

SpatialPointsDataFrame(coords, data, coords.nrs = numeric(0), 
      proj4string = CRS(as.character(NA)), match.ID, bbox = NULL)

Arguments

coords      numeric matrix or data.frame with coordinates (each row 
is a point); in case of SpatialPointsDataFrame an object of class
SpatialPoints-class is also allowed.

"Your mission, should you choose to accept..." is to properly create coords in your SpatialPointsDataFrame where coords includes both the coordinates and the animal id.

From here it may be helpful to raise a new question like "How to create a SpatialPointsDataFrame that includes animal ids?" If you do raise that question be sure to include a reproducible data set as that will make a big difference to people helping.

krads
  • 1,350
  • 8
  • 14
  • 1
    Hi krads, thanks for your response! This makes sense. I've ammended my code ud <- kernelUD(xy = xorig_utm[, c("coords.x1", "coords.x2")], id = xorig_utm[, "nest_id"], h = "LSCV") this should select the transformed lat & lon (coords.x1 & coords.x2) collumns as coordinates, plus the xorig_utm[, "nest_id"] for the id argument should tell the function to group points by nest_id. However, when I run this I still run into trouble getting the error message Error in kernelUD(xy = xorig_utm[, c("coords.x1", "coords.x2")], id = xorig_utm[, : unused argument (id = xorig_utm[, "nest_id"]) – Tobit Apr 10 '19 at 10:55
  • Sorry, my previous answer linked to an out of date `kernelUD()` function version document. I've now updated my answer to describe the the current `kernelUD()` function parameters and linked to the current version docs. – krads Apr 11 '19 at 04:43
  • @Tobit did you ever figure this out? I'm having the same issue. My data is exactly the same structure as the sample dataset they provide (SpatialPointsDataFrame) – spops Nov 11 '19 at 17:31
  • 1
    @spops Hi, I worked around the problem in a very ugly way - I essentially calculated the home range of each individual separately, rather than all at once... this is off course not what you want to be doing if you have lots of individual home ranges. Though in the end I was forced to use minimum convex polygons anyway due to the way I had collected my data. – Tobit Nov 12 '19 at 20:36
  • @Tobit Thanks for getting back to me! I've got a very hacky "solution" as well from my end - I saved the dataframe with species, x, y as a csv (this was the original df I used to turn into a `SpatialPointsDataFrame`), then read it back into R. Reading it back in revealed that I had an invisible ID column in the original dataframe that was messing everything up. `kernelUD` was reading this invisible ID column and seeing that there was only one 'relocation' (ID) per coordinate. – spops Nov 18 '19 at 11:49
  • @spops Ahh interesting! Thanks for letting me know, I'll bare this in mind when using spatial data in the future! :) – Tobit Nov 19 '19 at 12:21