KernelUD中的错误"至少需要5次重新定位以适应家庭范围"

时间:2015-09-21 16:45:56

标签: adehabitathr

我有一个多边形形式的蝙蝠运动数据数据集。我已经为每个多边形创建了一个随机点,并将其循环运行100次。这创建了一个数据框,每个单独的bat有100个loopnos。我正在尝试为每个loopno创建一个kernelUD,每个人堆叠它们,然后使用以下脚本对它们进行平均。这在我使用完整数据集时有效。然而,当我对它进行二次采样时,我得到的错误是“#34;至少需要5次重新定位以适应家庭范围"”。请有人可以告诉我最好的方法来检查每个loopno或者个人的重新安置次数吗?

library(adehabitatHR)
library(raster)
library(maptools)
library(stats)

setwd("C:/Users/a6915409/Dropbox/Paper write up")


# read in bat master
bat.master<- read.csv("./original csv files/LCfirsthalf09.09.csv")

#make bat.points spatial data
xy <- bat.master[2:3]#first two rows save as coords
df <- bat.master [-1:-4]#remove unneded columns for ud
df<-df[-2]

SPDF <- SpatialPointsDataFrame(coords=xy, data=df)#combine df and xy

#read in landcover data for habitat grid
r <- raster("landcover.asc")

#need to set up graphical parametrs
par(mfrow=c(2,1))
par(mar=c(0,0,2,0))
g <- as(r, 'SpatialGridDataFrame')
p <- as(r, 'SpatialPixelsDataFrame')
habitat<-p

#chnage spatial projections so they match
proj4string(SPDF)<-proj4string(habitat)

#split bat master by ID into a list of spatial dataframes each with 100 replicates 
pts1<-split(SPDF , bat.master$id)

 ## generate uds on each animal for each loop
pts2 <- lapply(pts1, function(x) {slot(x, "data") <- data.frame(x@data   [,1]); return(x)})

############################################################## Works up to  here


  uds<- lapply(pts2, function(x) kernelUD(x, h=200, grid=habitat))#flags an error "at least 5 relocations are required to fit an home range"

#stack the ud's as raster layers, 100 for each animal

udsr <- lapply(uds, function(x) stack(lapply(x, raster)))


## take the mean
udsm <- lapply(udsr, mean)

for (i in seq_along(udsm)) {
  uds[[i]]<- uds[[i]][[1]]
  uds[[i]]@grid <- as(udsm[[i]], "GridTopology")
}


class(uds)<-"estUDm"

1 个答案:

答案 0 :(得分:0)

这是问题的解决方案,

#read in csv file
bat.master<- read.csv("./CLUSTERS NEW/LC1point10loops.csv")

library(dplyr)

#check if any bats have less than 5 relocations using dplyr
check<- bat.master%>%group_by(id, loopno)%>%summarise(loop=length(loopno))% >%dplyr::filter(loop<6)

#convert this to a dataframe
check<- as.data.frame(check)

#subset bat.master to exclude those individuals found to have less than 5 relocations

bat.master<-bat.master %>% anti_join(check)
# proceed with rest of code