Skip to content
Prev 275007 / 398506 Next

Randomized Points in space/ saving model results

Not doing much work with spacial stats or shapefiles, I can't help in
too much detail, but here are some R commands that might help for each
part:

a.

# This will help you pick random points within your bounded box
runif2d <- function(n, xmin, xmax, ymin, ymax){
     stopifnot(all(xmax > xmin, ymax > min))
     y <- runif(n, ymin, ymax)
     x <- runif(n, xmin, xmax)
     cbind(x,y)
}

b. take the output of runif2d (which gives a nx2 matrix) and cbind()
the csv points on as well

c. getdist <- function(inpoints, refpoints) {
    # Takes in two 2 column matrices representing (x,y) coordinates
and returns a matrix with all the distance pairs between them
       stopifnot(all(is.matrix(inpoints), is.matrix(refpoints),
dim(inpoints)[2L] == 2L, dim(refpoints)[2L] == 2L))
       d <- matrix(nrow = nrow(inpoints), ncol = nrow(refpoints))
       for (i in seq_along(refpoints)) {
             d[, i] <- rowSums(inpoints-refpoints[i,]^2)
       }
       d
}

f. Wrap everything in a function and use replicate()

Do these help?

Michael
On Thu, Oct 20, 2011 at 1:32 PM, magono <nroyal01 at gmail.com> wrote: