[R] Questions about spatial data

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Thu Mar 11 20:10:40 CET 2004


Ronaldo Reis Jr. wrote:

> 1) I have this grid
> 
> x <- rep(c(1:8),c(rep(6,8)))
> y <- rep(c(1:6),8)
> 
> I need to make some others grids with same length and different numbers of 
> points whit a random spatial pattern.

  This is a bit imprecise. What do you mean by 'same length and 
different numbers of points'?

  Your grid above has 8*6 = 42 points. Do you want to generate a random 
subset of these grid points, selecting each point with a fixed 
probability, or selecting exactly N points?

  Firstly, I would make your grid above using 'expand.grid':

fullGrid <- expand.grid(1:8,1:6)
plot(fullGrid)

  Then you can use the sample() function to choose 10 different integers 
from 1 to 42, and use that to choose rows of the fullGrid data frame:

thinGrid <- fullGrid[sample(42,10),]
plot(thinGrid)

  This gives you exactly 10 points.

  Or you could choose each point with some probability, using runif(42) 
to generate uniform random numbers and compare this with a threshold:

thin2 <- fullGrid[runif(42)>.8,]
plot(thin2)

  This gives grids with differing numbers of points, but each of the 42 
points has a 0.2 probability of being included.

> 2) I need to produce some grids with the same numbers of points in different 
> degrees of aggregation, the level of aggregation for all grids must be 
> statistically different.
> 
> How to do these grids in R and how to test the significance between these 
> grids?

  I think at this point you need to find a good textbook on spatial 
point processes, then come back and look at R packages spatstat and to a 
lesser extent, splancs.

  Hope this helps,

Baz




More information about the R-help mailing list