I've written the function below to simulate the mean 1st through nth nearest neighbor distances for a random spatial pattern using the functions nndist() and runifpoint() from spatsat. It works, but runs relatively slowly - would appreciate suggestions on how to speed up this function. Thanks. --Dale
library(spatstat) sim.nth.mdist <- function(nth,nsim) { D <- matrix(ncol=nth, nrow=nsim) for (i in 1:nsim) { rpp <- runifpoint(22, win=owin(c(0,1),c(0,1)), giveup=1000) for (k in 1:nth) D[i,k] <- mean(nndist(rpp ,k=k)) } D } sim.nth.mdist(5,100) ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.