[R-sig-Geo] averaging home range contours

Ross Dwyer ross.dwyer at uq.edu.au
Fri Apr 27 01:30:58 CEST 2012

Hi Melanie,

I think you're going about this the wrong way. My advice is to...
1. Get the data into the correct format for a spatial points data frame (X, Y, ID)
	Where ID = replicate number
2. Run kernelUD to generate UDs for the 100 replicates
3. Use ver95 <- getverticeshr(kud, lev = 95) and ver50 <- getverticeshr(kud, lev = 50) to extract your vertices for each replicate. These can then be easily saved as a .shp.
4. Run the following to extract your areas
Area95 <- sapply(slot(ver95, "polygons"), function(i) slot(i, "area"))) 
Area50 <- sapply(slot(ver50, "polygons"), function(i) slot(i, "area"))) 
5. Then you can simply run mean(Area95) etc to extract the mean of all replicates for each contour.

Best to avoid the loop as I don't think it's really needed here.

Cheers, Ross

-----Original Message-----
From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Melanie Shapiera
Sent: Wednesday, 25 April 2012 11:07 PM
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] averaging home range contours

Hello all

I am trying to run some Monte Carlo simulations on single individuals in R.

So far, I have sampled 100 X and Y coordinates from known positions of an individual, 100 times. This results in a list of 200. I then convert this list into a dataframe that is more condusive to eventual functions I want to run for each sample (kernel.area,kernelUD).
So I had a data frame with 200 columns, and I wanted to perform the kernel.area function (adehabitatHR), using each successive pair of columns (which represent a resampling). I ended up writing a loop that allows me to calculate the kernel.area for each of the simulations, as well as the 95% volume contour, which is saved as a Spatial Polygon.

I now want to take the average of these 95% volume contours, to get an average 95% volume contour that I can view in Arc. However, I am unsure how to do this. Any advice would be greatly appreciated!
I can't replicate my data very well here, so I'll give an example of what the structure is:

# generate dataframe representing X and Y positions df <- data.frame(x=seq(1:200),y=seq(1:200))
# 100 replications of sampling 100 "positions"
resamp <- replicate(100,df[sample(nrow(df),100),])
# convert to data frame (kernel.area needs an xy dataframe) dfnew <- do.call("rbind", resamp[1:2,]) # xy positions need to be in columns for kernel.area
df2 <- t(dfnew)

Ok, here is the for loop I've been using for my actual positions:

#calculate the 50,95% kernel area for each simulation, as well as the 95% volume contour

for (j in seq(1,ncol(df2)-1,2)) {
kud <-kernelUD(SpatialPoints(df2[,j:(j+1)]),kern="bivnorm")
name[[j]]<-getverticeshr(kud, lev = 95)
Again, the next step I wish to take is to average the hundred 95% contours I have created (ie name[[1]],name[[3]]...). Any suggestions?
Melanie Shapiera
MSc candidate
Memorial University of Newfoundland

	[[alternative HTML version deleted]]

R-sig-Geo mailing list
R-sig-Geo at r-project.org

More information about the R-sig-Geo mailing list