[R-sig-Geo] FW: subscript out of bounds, getvertices adehabitathr
Simone Mordue (PGR)
s.m.mordue at newcastle.ac.uk
Wed Dec 10 12:43:04 CET 2014
Hope someone can help, I have 10 animals and have generated random points based on recorded polygons for each animal. I have run this 100 times per animal. My aim is to generate a mean utilized distribution for each animal based on all 100 runs. so far I have used this code:
xybat <- subset(bat.master, bat.master$id =="Y2889a",select=x:loopno )
# change to spatial points
xy <- xybat[1:2 ] # first two rows save as coords
df <- xybat[-1:-3 ]# remove unneded columns for ud
SPDF <- SpatialPointsDataFrame(coords=xy, data=df ) # combine df and
udHR <- kernelUD(SPDF, h = 200, grid=habitat)
## I would proceed using the raster packages
# stack the UD's as a raster
ud <- stack(lapply(udHR, raster))
## You can now check the first one
plot(ud[[1]])
## take the mean
plot(udm <- mean(ud))
## now convert it back to a estUD, this is a bit of a hack and not the nicest way to do it
Y2889a<- udHR[[1]]
Y2889a at grid <- as(udm, "GridTopology")
I do this first bit of code for each animal, here is a subset of just two of them. I can visulise them using image(liud) but when I try to use the function "getverticeshr" I get an error that the subscript is out of bounds. I have tried changing the grid and the value of h to no avail. I wonder if it something to do with the way I am combining them into and out of a list?
library(adehabitatHR)
# combine all Ud's into one dataset
liud <- list(Y2889a, Y2889b)
class(liud) <- "estUDm"
image(liud) # plot all est ud's
v<-getverticeshr(liud)
I have reproduced the error with the puechabonsp dataset below
library(adehabitatHR)
# Load the data
data(puechabonsp)
loc <- puechabonsp$relocs
## Estimation of UD for each of the animals (two here as an example)
udBrock <- kernelUD(loc[as.data.frame(loc)[,1]=="Brock",], grid=200)
udCalou <- kernelUD(loc[as.data.frame(loc)[,1]=="Calou",], grid=200)
# join the UD's into an estUDm object
liud <- list(udBrock, udCalou)
class(liud) <- "estUDm"
image(liud) # plot all est ud's
v<-getverticeshr(liud)
this results in the same error, subscript is out of bounds. Hope someone can help!
Best wishes, Simone
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list