I have been making kernel density home range estimations for canid groups in an area by population and per pack across various temporal scales. However, when I attempt to run kernelUD on a subset for each year I get Error in kernelUD(P17.sp[, "Pack"], h = "href", grid = 500, same4all = TRUE) : At least 5 relocations are required to fit an home range
. I previously eliminated all groups that had less than 5 relocations and when I double check my data frame the smallest number of relocations is 201. I was able to run this on the global dataset (across years) per pack and had no problem. Any help or insight would be greatly appreciated.
The code I've used is below. My original data frame has Pack as a factor (and is the only factor vector in the data frame) and numeric coordinates in lat/long.
library(dplyr)
library(raster)
library(sp)
library(adehabitatHR)
library(lubridate)
library(data.table)
# Make spatial
Final.sp <- copy(Final)
coordinates(Final.sp) <- c("Longitude", "Latitude")
proj4string(Final.sp) <- CRS( "+init=epsg:4326")
#Subset by year
P17.sp <- Final.sp[Final.sp@data$Year == 2017, ]
# Make sure every pack has at least 5 relocations
P17 <- as.data.frame(P17.sp)
P17 %>% group_by(Pack) %>% summarise(n()) %>% view()
# What the output from above looks like
Year Pack n()
#1 2017 Gryffindor 201
#2 2017 Slytherin 222
#3 2017 Hufflepuff 234
#4 2017 Ravenclaw 281
#5 2017 Deatheaters 306
#6 2017 Muggles 577
#7 2017 Dementors 582
#8 2017 Hobbits 787
#9 2017 Elves 861
#10 2017 Orcs 914
# Create KDEs
P17.kde <- kernelUD(P17.sp[,"Pack"], h="href", grid=500, same4all = TRUE)
Error in kernelUD(WP17.sp[, "Pack"], h = "href", grid = 200, same4all = TRUE) :
At least 5 relocations are required to fit an home range```
Got it to work. It appears it was carrying over packs with no data for the subset year and they weren't showing up in my dplyr table intended to check that the data was right. ftable
was able to show me the levels and associated number of points for each pack. The following code now works:
# Subset by year
P17.sp <- Final.sp[Final.sp@data$Year == 2017, ]
# Refactor pack or else it will include packs from other years with no data for subset year
P17.sp@data$Pack <- factor(P17.sp@data$Pack)
# Double check all packs have at least 5 relocations
as.data.frame(ftable(P17.sp@data$Pack))
# Create KDEs
P17.kde <- kernelUD(P17.sp[,"Pack"], h="href", grid=500, same4all = TRUE)
Hope this helps anyone else who comes across this issue.