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")
kernAr<-kernel.area(kud,percent=c(50,95),unin=c("m"),unout=c("km2"))
print(kernAr)
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
-- 
Melanie Shapiera
MSc candidate
Memorial University of Newfoundland

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to