如何使用 dehabitatHR 包计算家域分析的 KUD?

How to calculate KUD for home range analysis using the package adehabitatHR?

我正在尝试为我的企鹅跟踪数据计算 KUD 50% 和 95%,但 运行 出现错误。我的目标是计算家庭范围密度,然后将数据导出为多边形。

library(adehabitatHR)  
library(sp)
library(readxl)
library(rgdal)

HRtracks<- as.data.frame(read_excel("allinterpolatedtracks.xlsx")) 

# assign the correct columns as coordinates
coordinates(HRtracks)<-c("x","y")   
proj4string(HRtracks)<- CRS("+init=epsg:3857")

#convert the coordinates to utm format
tracks.utm<-spTransform(HRtracks, CRS("+proj=utm +zone=60 +datum=WGS84"))

运行执行这部分脚本后出现错误,tracks.utm[X] 表示数据排序依据的列,它是按单个 tripID 排序的,因此它应该创建一个范围每个单独的轨道。

colkud<-kernelUD(tracks.utm[,3],h="href", grid=1000,same4all=T)

错误:

Error: Can't subset columns that don't exist.
x Location 3 doesn't exist.
i There are only 1 column.

我怀疑我的脚本中遗漏了一些东西,但我还不是一个有经验的用户,所以希望得到一些建议。

数据:

tracks.utm <- dput(new("SpatialPointsDataFrame", data = structure(list(TripID = c(1, 
1, 1, 1, 1, 1)), row.names = c(NA, -6L), class = c("data.frame")), 
coords.nrs = numeric(0), coords = structure(c(165846.488217799, 
165846.488227808, 165846.488167749, 165846.488257839, 165846.488237819, 
165846.488718291, -19995889.0262206, -19995889.0261311, -19995889.0262007, 
-19995889.0261311, -19995889.0260814, -19995889.0254053), .Dim = c(6L, 
2L), .Dimnames = list(NULL, c("x", "y"))), bbox = structure(c(165846.488167749, 
-19995889.0262206, 165846.488718291, -19995889.0254053), .Dim = c(2L, 
2L), .Dimnames = list(c("x", "y"), c("min", "max"))), proj4string = new("CRS", 
projargs = "+proj=utm +zone=60 +datum=WGS84 +units=m +no_defs")))

干杯

根据 dput,您的数据中只有一列。检查您的数据是一种很好的做法!如果您查看 str(tracks.utm@data),唯一的列是 TripID,您正试图指定第三列。

如果您查看函数帮助,您会看到您传递的 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.

这意味着 TripID 应该是唯一的列,是一个因素并对应于个体动物 ID。由于预计只有一个列,因此不需要指定,只需指定 sp 对象。但是,显然不需要单个列似乎不是这种情况,您可以有多个列但需要指定包含唯一动物 ID 的列,因此列括号索引。

为了确保您的动物 ID 是一个因素(根据帮助),我建议将适当的列(例如,TripID)强制转换为一个因素。

library(sp)
library(adehabitatHR)

tracks.utm <- dput(new("SpatialPointsDataFrame", data = structure(list(TripID = c(1, 
1, 1, 1, 1, 1)), row.names = c(NA, -6L), class = c("data.frame")), 
coords.nrs = numeric(0), coords = structure(c(165846.488217799, 
165846.488227808, 165846.488167749, 165846.488257839, 165846.488237819, 
165846.488718291, -19995889.0262206, -19995889.0261311, -19995889.0262007, 
-19995889.0261311, -19995889.0260814, -19995889.0254053), .Dim = c(6L, 
2L), .Dimnames = list(NULL, c("x", "y"))), bbox = structure(c(165846.488167749, 
-19995889.0262206, 165846.488718291, -19995889.0254053), .Dim = c(2L, 
2L), .Dimnames = list(c("x", "y"), c("min", "max"))), proj4string = new("CRS", 
projargs = "+proj=utm +zone=60 +datum=WGS84 +units=m +no_defs")))

tracks.utm@data$TripID <- factor(tracks.utm@data$TripID)
  str(tracks.utm@data) 
( colkud <- adehabitatHR::kernelUD(tracks.utm[,1], h="href", 
                                 grid=1000, same4all=TRUE) )
  image(colkud)
    points(tracks.utm, pch=20)