1

我有一个多边形形式的蝙蝠运动数据集。我为每个多边形创建了一个随机点,并将其循环运行 100 次。这创建了一个数据框,其中每个蝙蝠都有 100 个 loopnos。我正在尝试为每个 loopno 创建一个 kernelUD,将它们逐个堆叠,然后使用以下脚本对它们进行平均。这在我使用完整数据集时有效。但是,当我对其进行二次抽样时,我得到“至少需要 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"
4

1 回答 1

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
于 2016-05-19T14:31:03.570 回答