r - 网格对于 kernelUD/getverticeshr/adehabitatHR 家庭范围估计来说太小

标签 r adehabitathr

adehabitat HR 的文档建议使用以下代码来在创建 UD 对象后计算家庭范围的 95% 内核:

 ## Calculation of the 95 percent home range
    ver <- getverticeshr(ud, 95)

对于我的某些数据,出现以下错误:

Error in getverticeshr.estUD(x[[i]], percent, ida = names(x)[i], unin,  : 
  The grid is too small to allow the estimation of home-range.
You should rerun kernelUD with a larger extent parameter

在 Nabble 论坛上,人们建议更改“网格”和“范围”输入,但在使用这两个参数的多种组合后,我无法获得更好的结果。有什么建议么?

最佳答案

这是我在一些论坛中发现的常见问题。但答案很简单,就在错误消息中。 “你需要扩展你的网格”。发生这种情况是因为当您应用 getverticeshr(ud, 95) 时,部分多边形位于网格之外,因此无法获取区域。 例如,在下面的代码中,估计了两种假设动物的 KDE。我使用从 0 到 100 的随机点,因此我定义了一个 100x100 的网格(域)。

#"""
# Language: R script
# This is a temporary script file.
#"""

# 1. Packages
library(adehabitatHR)         # Package for spatal analysis

# 2. Empty Dataframe
points <- data.frame(ID = double())
XY_cor <- data.frame(X = double(),
                     Y = double())
# 3. Assigning values (this will be our spatial coordinates)
set.seed(17)
for(i in c(1:100)){
    if(i >= 50){points[i, 1] <- 1}
    else {points[i, 1] <- 2}
    XY_cor[i, 1] <- runif(1, 0, 100)
    XY_cor[i, 2] <- runif(1, 0, 100)}

# 4. Transform to SpatialDataframe
coordinates(points) <- XY_cor[, c("X", "Y")]
class(points)

# 5. Domain
x <- seq(0, 100, by=1.) # resolution is the pixel size you desire 
y <- seq(0, 100, by=1.)
xy <- expand.grid(x=x,y=y)
coordinates(xy) <- ~x+y
gridded(xy) <- TRUE
class(xy)

# 6. Kernel Density
kud_points <- kernelUD(points, h = "href", grid = xy)
image(kud_points)

# 7. Get the Volum
vud_points <- getvolumeUD(kud_points)

# 8. Get contour
levels <- c(50, 75, 95)
list <- vector(mode="list", length = 2)

list[[1]] <- as.image.SpatialGridDataFrame(vud_points[[1]])
list[[2]] <- as.image.SpatialGridDataFrame(vud_points[[2]])

# 9. Plot
par(mfrow = c(2, 1))
image(vud_points[[1]])
contour(list[[1]], add=TRUE, levels=levels)
image(vud_points[[2]])
contour(list[[2]], add=TRUE, levels=levels)

enter image description here enter image description here

该图显示 50% 的轮廓在网格内,但 75% 的轮廓被切割,这意味着该轮廓的一部分在网格外。

如果您尝试将 KDE 的顶点估计为 50%,您将获得良好的结果:

# 10. Get vertices (It will be fine)
vkde_points <- getverticeshr(kud_points, percent = 50,
                                 unin = 'm', unout='m2')
plot(vkde_points)

但是,如果您尝试使用 75% 的级别,您将获得经典错误: getverticeshr.estUD(x[[i]],percent,ida=names(x)[i],unin, 中的错误: 网格太小,无法估计家庭范围。 您应该使用更大的范围参数重新运行 kernelUD

# 10. Get vertices (Will be an Error)
vkde_points <- getverticeshr(kud_points, percent = 75,
                                 unin = 'm', unout='m2')
plot(vkde_points)

现在,你可以清楚地看到发生了什么,R 无法估计顶点到 75%,因为它们在网格之外,所以你需要增加域(网格)!这里我将域名增加50(参见#5.域名)

# 5. Domain                 HERE GRID IS INCREASED 50 AT X AND Y!!
x <- seq(-50, 150, by=1.) # resolution is the pixel size you desire 
y <- seq(-50, 150, by=1.)
xy <- expand.grid(x=x,y=y)
coordinates(xy) <- ~x+y
gridded(xy) <- TRUE
class(xy)

# 6. Kernel Density
kud_points <- kernelUD(points, h = "href", grid = xy)
image(kud_points)

# 7. Get the Volum
vud_points <- getvolumeUD(kud_points)

# 8. Get contour
levels <- c(50, 75, 95)
list <- vector(mode="list", length = 2)

list[[1]] <- as.image.SpatialGridDataFrame(vud_points[[1]])
list[[2]] <- as.image.SpatialGridDataFrame(vud_points[[2]])

# 9. Plot
par(mfrow = c(2, 1))
image(vud_points[[1]])
contour(list[[1]], add=TRUE, levels=levels)
image(vud_points[[2]])
contour(list[[2]], add=TRUE, levels=levels)

enter image description here enter image description here

您可以看到所有轮廓都在网格(域)内。所以,现在您将能够估计顶点。

# 10. Get vertices
vkde_points <- getverticeshr(kud_points, percent = 75,
                                 unin = 'm', unout='m2')
plot(vkde_points)

关于r - 网格对于 kernelUD/getverticeshr/adehabitatHR 家庭范围估计来说太小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41683905/

相关文章:

regex - 在R中的字符串中用 "+-"替换 "-"

r - 如果单元格不为空,则从 R 格式化 Excel 单元格

r - as.numeric()删除R中的小数位,如何更改?

r - 错误 : . onLoad 在 'tcltk' 的 loadNamespace() 中失败,详细信息 :call: fun(libname, pkgname)

R:具有给定坐标的快速滑动窗口

R编程: choose every combination of factors from a data.帧