简体   繁体   English

为adehabitatHR中的多个动物创建内核密度估计

[英]creating kernel density estimates for multiple animals in adehabitatHR

I am trying to create kernel density estimates (KDEs) to estimate the home ranges for multiple pairs of long-tailed tits. 我正在尝试创建内核密度估计(KDE),以估计多对长尾山雀的原始范围。 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. 尽管滤除了少于五个GPS位置的对(“ nest_id”变量),但在尝试为所有个人创建kernelUD时,我仍然收到错误消息“至少需要5个重定位才能容纳原始范围”。 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. 我对家庭范围分析以及R和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

Updated to point to the current version of kernelUD() function documentation: 更新以指向最新版本的kernelUD()函数文档:

help docs for kernelUD 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: 因此,在上面使用的情况下,您可能还需要使用Vignette ,在该示例中可能已经有一个示例:

I give below a short example of the use of kernelUD, using the puechabonsp dataset. 我在下面给出了使用puechabonsp数据集使用kernelUD的简短示例。 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: 一种了解xy之上需要什么的方法是打印出包示例中包含的示例数据:

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). 上面请注意,puechabonsp $ relocs [,1]是一个SpatialPointsDataFrame对象,其中包含坐标和ID(上面是“名称”)。

Moving on from here, look at the ?SpatialPointsDataFrame help to understand that function and the object it creates: 从这里继续,查看?SpatialPointsDataFrame帮助以了解该功能及其创建的对象:

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. “您的任务,您应该选择接受...”是在SpatialPointsDataFrame中正确创建coords ,其中coords包括坐标和动物ID。

From here it may be helpful to raise a new question like "How to create a SpatialPointsDataFrame that includes animal ids?" 从这里开始,提出一个新的问题(如“如何创建包含动物ID的SpatialPointsDataFrame ?”的问题)可能会有所帮助。 If you do raise that question be sure to include a reproducible data set as that will make a big difference to people helping. 如果您确实提出了这个问题,请确保包括可重现的数据集,因为这将对帮助人员产生很大的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM