我一直在对一个地区的犬科动物群体进行核密度主场范围估计,按人口和每群在不同的时间尺度。然而,当我尝试每年在一个子集上运行kernelUD时,我得到的是Error in kernelUD(P17.sp[, "Pack"], h = "href", grid = 500, same4all = TRUE) : At least 5 relocations are required to fit an home range
。我之前排除了所有迁移少于5次的组,当我仔细检查我的数据框架时,最小的迁移次数是201次。我能够在每个包的全局数据集(跨年)上运行这个,没有问题。如有任何帮助或见解,我将不胜感激。
我使用的代码如下。我的原始数据帧将Pack作为因子(并且是数据帧中唯一的因子向量)和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```
让它工作。它似乎携带了没有子集年数据的包,并且它们没有显示在我的dplyr表中,以便检查数据是否正确。ftable
能够向我展示每个包的级别和相关点数。下面的代码现在可以工作了:
# 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)
希望这篇文章能帮助到其他遇到这个问题的人。