0
votes

Hope someone can help, I have a large dataset from which I have generated 10 estUD's with the same grid and h value=200. Here is a subset of just two of them. I can visulise them using image(liud) but when I try to use the fuction 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

## have a look at the data
head(as.data.frame(loc))
## the first column of this data frame is the ID


## 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)

liud <- list(udBrock, udCalou)
class(liud) <- "estUDm"
image(liud)#plot all est ud's

v<-getverticeshr(liud)

Thanks for your comment Chris, I should have explained my dataset. 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 xy


udHR <- kernelUD(SPDF, h = 200, grid=habitat, kernel=epa) 


## I would proceed using the raster packages

ud <- stack(lapply(udHR, raster))

## You can now check the first one

plot(ud[[1]])

## or at all of them
#plot(ud)

## take the mean
plot(udm <- mean(ud))


## now you can either proceed in raster and calculate your isopleths or 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@grid <- as(udm, "GridTopology")

so if I follow your suggestion and run the kernelud function on the whole dataset I still need to stack each of the animal's ud's separatley and then combine them into an EstUDm and I am back to the same problem. I hope you can help me come up with a solution.

Best wishes, Simone

1
Instead of subsetting loc you might try calling kernelUD on the whole dataset and then subsetting within getverticeshr using the whi argument. So ud <-kernelUD(loc[,1]) and then v <- getverticeshr(ud,whi=c("Brock","Calou")).Chris Holbrook
Am I right, you are trying to do same thing as in your previous question (stackoverflow.com/questions/27318889/…) but for multiple animals?johannes
Yes that's correct. I think it may be easier to keep the ud's as raster stacks and generate contours from there instead using 'move', I cant see a way to do it as an estUDm.user3237130

1 Answers

0
votes

This basically just a generalisation for multiple animals of my previouse answer, maybe it is useful:

library(adehabitatHR)
library(raster)

## generate some dummy data for 15 animals, each with 10 replications)
pts <- replicate(15, SpatialPointsDataFrame(coords=cbind(rnorm(1000), rnorm(1000)),
                                            data=data.frame(id=rep(1:10, each=100))))

## generate uds
uds <- lapply(pts, function(x) kernelUD(x, h = "href", same4all = TRUE, kern = "bivnorm"))


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

## You can now check the first one
plot(udsr[[1]][[1]])

## or at all 10 uds of the first animal
plot(udsr[[1]])

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

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

## now you can work with udHR as if it were a HR estimate
iso95 <- lapply(uds, getverticeshr, percent=95)

## plot first animal
plot(iso95[[1]])

## plot second animal
plot(iso95[[2]])