【问题标题】:creating kernel density estimates for multiple animals in adehabitatHR在 adehabitatHR 中为多种动物创建核密度估计
【发布时间】:2019-08-07 10:24:33
【问题描述】:

我正在尝试创建核密度估计 (KDE) 来估计多对长尾山雀的归属范围。尽管过滤掉了少于五个 GPS 位置的对(“nest_id”变量),但在尝试为所有个人创建 kernelUD 时,我仍然收到错误消息“至少需要 5 次重新定位才能适应一个家庭范围”。我不确定到底是什么问题/我做错了什么。一般来说,我对家庭范围分析以及 R 和 adehabitatHR 非常陌生。下面是我的代码。

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

【问题讨论】:

    标签: r adehabitathr


    【解决方案1】:

    更新为指向当前版本的 kernelUD() 函数文档:

    help docs for kernelUD

    用法

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

    ...

    参数

    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.
    

    因此,使用上述方法,您还可以使用Vignette,其中有一个您可能已经在关注的示例:

    我在下面给出一个使用 kernelUD 的简短示例,使用 puechabonsp 数据集。请记住,组件的第一列 此数据集的 relocs 包含动物的身份:

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

    了解上述 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 
    

    请注意,puechabonsp$relocs[,1] 是一个 SpatialPointsDataFrame 对象,其中包含坐标和 ID(即上面的“名称”)。

    从这里继续,查看?SpatialPointsDataFrame 帮助以了解该函数及其创建的对象:

    用法

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

    参数

    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.
    

    “您的任务,如果您选择接受...”是在您的 SpatialPointsDataFrame 中正确创建 coords,其中 coords 包含坐标和动物 ID。

    从这里提出一个新问题可能会有所帮助,例如“如何创建包含动物 ID 的 SpatialPointsDataFrame?”如果您确实提出了这个问题,请务必包含一个可重复的数据集,因为这将对帮助的人产生重大影响。

    【讨论】:

    • 嗨克拉德,感谢您的回复!这是有道理的。我已经修改了我的代码 ud
    • 抱歉,我之前的回答链接到了一个过时的kernelUD() 函数版本文档。我现在更新了我的答案以描述当前的 kernelUD() 函数参数并链接到当前版本的文档。
    • @Tobit 你有没有想过这个问题?我有同样的问题。我的数据与他们提供的示例数据集的结构完全相同(SpatialPointsDataFrame)
    • @spops 嗨,我以一种非常丑陋的方式解决了这个问题 - 我基本上分别计算了每个人的家庭范围,而不是一次计算......这当然不是你想要的如果您有很多单独的家庭范围,请这样做。虽然最终由于我收集数据的方式,我不得不使用最小凸多边形。
    • @Tobit 感谢您回复我!我也有一个非常老套的“解决方案”——我将带有物种、x、y 的数据框保存为 csv(这是我用来变成SpatialPointsDataFrame 的原始 df),然后读回来进入 R。读回来发现我在原始数据框中有一个不可见的 ID 列,它把一切都搞砸了。 kernelUD 正在读取这个不可见的 ID 列,发现每个坐标只有一个“重定位”(ID)。
    猜你喜欢
    • 1970-01-01
    • 2019-12-21
    • 2016-03-02
    • 2019-06-03
    • 1970-01-01
    • 2021-05-01
    • 2014-03-22
    • 2018-10-06
    • 2017-02-11
    相关资源
    最近更新 更多