[R] Randomized Points in space/ saving model results

R. Michael Weylandt michael.weylandt at gmail.com
Thu Oct 20 23:56:15 CEST 2011


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:
> A bit new to R and I'm working on something a bit more challenging than I am
> used to- so here's whats going on:
>
> Data inputs:  9 different shapefiles (.shp) of different point locations
> (lat, long)
>                   shapefile bounding box  (lat/long corner points (14, 1)
> (15,1) (14, 2) (15,2))
>                   1 .csv of lat/long coordinates for points
>
>
>
> Goal:  a- I want to randomly drop x number of points in a study area within
> the bounding box
>         b- Then I want to add the .csv points to the mix
>         c- Measure the distances from all these points to each of the 9
> shapefiles locations, one at a time and save the results in a table or list
>         d- run an regression analysis on the table or list created (I have
> this code all set to go)
>         e- I want to save the outputs of the model in a new table  (I have
> this code also)
>         f-  Run this whole process again x number of times and save x
> number of outputs in the table in order of creation
>
> Any help on steps a, b,c, or f would be appreciated
>
> M.
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Randomized-Points-in-space-saving-model-results-tp3922612p3922612.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list