1

I was wondering if there's a built-in function to extrapolate a point pattern outside the 'parent' window in R. For instance, let's generate a spatial point pattern 'X':

require(spatstat)
X <- ppp(runif(200), runif(200), 
c(0,1), c(0,1), unitname=c("metre","metre"))

Let's resample the data:

a <- quadratresample(X, nx=25, ny=5, replace=F, nsamples = 1)

But the the new points are generated within the same area/spatial window

> a
 planar point pattern: 200 points 
window: rectangle = [0, 1] x [0, 1] metres  

My question is: how would I resample the 200 points within a new window bigger than the original window (1 by 1 m); in other words, how would I extrapolate the small set of 200 spatial points to a larger scale while keeping the same resampling density; say I want to see a total of 1,000 data points in a 5 by 5 m extent?

Ege Rubak
  • 4,347
  • 1
  • 10
  • 18
ToNoY
  • 1,358
  • 2
  • 22
  • 43
  • I'm not sure I understand your use of "extrapolate". Do you just want to scale up the resample, that is take the 200 points sampled from your 1x1 window and put them in a 5x5 window with the same relative positions? – Gregor Thomas Sep 16 '15 at 18:33
  • yea you are right, that's what I meant by extrapolation - the density of data would remain the same/unit area but I want to resample over a larger extent, i.e. if 200 points in 1 by 1 m area, there will be a 1,000 across a 5 by 5 m area – ToNoY Sep 16 '15 at 18:36
  • Okay, so **not** scaling up, some sort of data creation. Do want to repeat the resampled pattern of 200 points so that there are 25 copies of it in the 5x5 area? – Gregor Thomas Sep 16 '15 at 18:40
  • yes, but the patterns will be different each time for randomness – ToNoY Sep 16 '15 at 18:42
  • Okay, so you want to take 25 different resamples and put them in a 5x5 grid next to each other? – Gregor Thomas Sep 16 '15 at 18:43

1 Answers1

2

This is pretty easy because spatstat gives us all the right tools. You currently have a 1x1 grid. You want a 5x5 grid which is built out of 25 1x1 grids. We can sample the points for these grids with the nsamples argument:

a <- quadratresample(X, nx = 25, ny = 5, replace = F, nsamples = 25)

Now we have a list of 25 ppps. As you point out, all of these will be in the same 1x1 window. To turn these into a grid, we shift them appropriately, from 0 to 4 units in x shift and 0 to 4 units in y shift:

for (i in seq_along(a)) {
    a[[i]] = shift(a[[i]], vec = c((i - 1) %% 5, (i - 1) %/% 5))
}

To combine them, use superimpose:

b = superimpose(a)

This gives a single ppp object in a 5x5 window with 200 * 25 = 5000 points, which preserves the 200 points per unit squared of the original.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • looks good but the superimpose part giving me an error: > b=superimpose(a) Error in superimpose.default(a) : Argument 1 does not have components x and y – ToNoY Sep 17 '15 at 15:10
  • @ToNoY What version of `spatstat` are you running? In version 1.42-0 they added a list method for superimpose. If you update to the most recent version it should work. – Gregor Thomas Sep 17 '15 at 16:05
  • 1
    I have version 1-43-0 and I still get the same error as @ToNoY. I solved this problem by extracting the list's contents as arguments: `do.call(superimpose, list.of.ppps)`. – Arthur Nov 23 '15 at 22:31