I have a dataset of bat movement data in the form of polygons. I have created one random point per polygon and looped this to run 100 times. This has created a data frame where each individual bat has 100 loopnos. I am trying to create a kernelUD for each loopno, stack them per individual and then average them using the following script. This works when I use the full dataset. However when I subsample it I get the error that "at least 5 relocations are required to fit a home range". Please could someone advise me the best way to check how many relocations I have per loopno and or individual please?
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"