Hello all,

I am trying to extract the 95% kernel density areas for certain
individuals, but keep coming up with the error "subscript out of bounds"
using the getverticeshr function in the adehabitatHR package. I have run
into this problem before, and solved it by increasing the grid size.
However, this approach is not working this time around - I'm still getting
this error, or otherwise I am getting errors due to memory issues because I
am increasing grid size to 1000+. If people hae suggestions/solutions to
this problem, I would greatly appreciate it.
I'll show a sample of my code below. Thanks!

Melanie

############################
### for each fish
# resample for each season
# arrange the data for kernelUD
# calculate kernelUD
# extract the areas
# calculate the average area
###################################################################3962
##sample 100 positions, 100 times for each season (fall, winter)
rf62=replicate(100,f62[sample(nrow(f62),100),9:10])
rw62=replicate(100,w62[sample(nrow(w62),100),9:10])
## put in data frame
df <- do.call("rbind", rf62[1:2,])
df2<-data.frame(t(df))
dfw <- do.call("rbind", rw62[1:2,])
df2w<-data.frame(t(dfw))
#each pair of columns is a replicate
#need to make the df have just two columns (X and Y)
names(df2)<-NA
dff=df2[,1:2]
for (j in seq(3,ncol(df2),2)){
  dff=rbind(dff,df2[,j:(j+1)])
}
names(df2w)<-NA
dffw=df2w[,1:2]
for (j in seq(3,ncol(df2w),2)){
  dffw=rbind(dffw,df2w[,j:(j+1)])
}
#need to put in an ID for each of the replicates (needs to be a factor)
for (i in nrow(dff)){
  dff$ID<-rep(1:100,each=100)
}
colnames(dff)<-c("X","Y","ID")
dff$ID<-as.factor(dff$ID)
for (i in nrow(dffw)){
  dffw$ID<-rep(1:100,each=100)
}
colnames(dffw)<-c("X","Y","ID")
dffw$ID<-as.factor(dffw$ID)
#now convert to Spatial Points Data Frame, containing 1 slot for the
coordinates, and a data slot for the IDs
coords12=coordinates(dff[,1:2])
ID=data.frame(dff[,3])
t62spdf=SpatialPointsDataFrame(coords12,ID)
coords12w=coordinates(dffw[,1:2])
ID=data.frame(dffw[,3])
t62spdfw=SpatialPointsDataFrame(coords12w,ID)

#data is now in proper format to calculate kernelUD for each ID
#result is a list of elements of class estUD (1 for each replicate)
kud<-kernelUD(t62spdf,h="href",grid=50,same4all=TRUE,kern=c("bivnorm"))
kudw<-kernelUD(t62spdfw,h="href",grid=50,same4all=TRUE,kern=c("bivnorm"))
#get the vertices for the 95% and 50% contours
ver95 <- getverticeshr(kud, lev = 95)  ###########here is where the error
occurs for some individuals
ver95w<- getverticeshr(kudw, lev=95)

#extract the areas - sapply works to apply a function over a list that
returns a vector
#so sapply is going to look at each polygon slot in the list of vertices,
and this slot has 5 slots within it
# (labpt=centroid of polygon for a label, AREA!!, hole=logical,ringDir
(=?), and the coords)
# and for each polygon slot, it will extract the "area" slot, and put it in
the Areaxx list
#there is actually an area slot of the same class as "Polygon"....could
maybe use that as well?
Area95 <- sapply(slot(ver95, "polygons"), function(i) slot(i, "area"))
#average the areas
t62m95=mean(Area95)

-- 
Melanie Shapiera
MSc candidate
Memorial University of Newfoundland

	[[alternative HTML version deleted]]

