Draws a sub-sample from a set of units spatially located irregularly over some defined geographical region by imposing a minimum distance between any two sampled units.

1 | ```
discrete.sample(xy.all, n, delta, k = 0)
``` |

`xy.all` |
set of locations from which the sample will be drawn. |

`n` |
size of required sample. |

`delta` |
minimum distance between any two locations in preliminary sample. |

`k` |
number of locations in preliminary sample to be replaced by nearest neighbours of other preliminary sample locations in final sample (must be between 0 and |

To draw a sample of size `n`

from a population of spatial locations *X_{i} : i = 1,…,N*, with the property that the distance between any two sampled locations is at least `delta`

, the function implements the following algorithm.

Step 1. Draw an initial sample of size

`n`

completely at random and call this*x_{i} : i = 1,…, n*.Step 2. Set

*i = 1*and calculate the minimum,*d_{\min}*, of the distances from*x_{i}*to all other*x_{j}*in the initial sample.Step 3. If

*d_{\min} ≥ δ*, increase*i*by 1 and return to step 2 if*i ≤ n*, otherwise stop.Step 4. If

*d_{\min} < δ*, draw an integer*j*at random from*1, 2,…,N*, set*x_{i} = X_{j}*and return to step 3.

Samples generated in this way will exhibit a more regular spatial arrangement than would a random sample of the same size. The degree of regularity achievable will be influenced by the spatial arrangement of the population *X_{i} : i = 1,…,N*, the specified value of `delta`

and the sample size `n`

. For any given population, if `n`

and/or `delta`

are too large, a sample of the required size with the distance between any two sampled locations at least `delta`

will not be achievable; the suggested solution is then to run the algorithm with a smaller value of `delta`

.

**Sampling close pairs of points**.
For some purposes, it is desirable that a spatial sampling scheme include pairs of closely spaced points. In this case, the above algorithm requires the following additional steps to be taken.
Let `k`

be the required number of close pairs.

Step 5. Set

*j = 1*and draw a random sample of size 2 from the integers*1, 2,…,n*, say*(i_{1}, i_{2} )*.Step 6. Find the integer

*r*such that the distances from*x_{i_{1}}*to*X_{r}*is the minimum of all*N-1*distances from*x_{i_{1}}*to the*X_{j}*.Step 7. Replace

*x_{i_{2}}*by*X_{r}*, increase*i*by 1 and return to step 5 if*i ≤ k*, otherwise stop.

A matrix of dimension `n`

by 2 containing the final sampled locations.

Emanuele Giorgi e.giorgi@lancaster.ac.uk

Peter J. Diggle p.diggle@lancaster.ac.uk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ```
x<-0.015+0.03*(1:33)
xall<-rep(x,33)
yall<-c(t(matrix(xall,33,33)))
xy<-cbind(xall,yall)+matrix(-0.0075+0.015*runif(33*33*2),33*33,2)
par(pty="s",mfrow=c(1,2))
plot(xy[,1],xy[,2],pch=19,cex=0.25,xlab="Easting",ylab="Northing",
cex.lab=1,cex.axis=1,cex.main=1)
set.seed(15892)
# Generate spatially random sample
xy.sample<-xy[sample(1:dim(xy)[1],50,replace=FALSE),]
points(xy.sample[,1],xy.sample[,2],pch=19,col="red")
points(xy[,1],xy[,2],pch=19,cex=0.25)
plot(xy[,1],xy[,2],pch=19,cex=0.25,xlab="Easting",ylab="Northing",
cex.lab=1,cex.axis=1,cex.main=1)
set.seed(15892)
# Generate spatially regular sample
xy.sample<-discrete.sample(xy,50,0.08)
points(xy.sample[,1],xy.sample[,2],pch=19,col="red")
points(xy[,1],xy[,2],pch=19,cex=0.25)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.