#big plane today
set.seed(747)
#the number of potential sampling locations
N <- 50^2
#number of samples
n <- 27
#number of legacy sites
nLegacy <- 3
#the grid
X <- as.matrix( expand.grid( 1:sqrt( N), 1:sqrt(N)) / sqrt(N) - 1/(2*sqrt(N)))
#the inclusion probabiltiies with gradient according to non-linear function of X[,1]
p <- 1-exp(-X[,1])
#standardise to get n samples
p <- n * p / sum( p)
#randomly choose legacy sites
legacySites <- sample( 1:N, nLegacy, prob=p)
#alter inclusion probabilities
p2 <- alterInclProbs( legacy.sites=X[legacySites,], potential.sites=X, inclusion.probs=p)
if( requireNamespace( "graphics", quietly = TRUE)) {
#plotting up old and new inclusion probabilities
par( mfrow=c(1,2))
graphics::image( x=unique( X[,1]), y=unique( X[,2]),
z=matrix( p, nrow=sqrt(nrow(X)), ncol=sqrt(nrow( X))),
main="Undadjusted Inclusion Probabilities", ylab="y", xlab="x")
graphics::image( x=unique( X[,1]), y=unique( X[,2]),
z=matrix( p2, nrow=sqrt(nrow(X)), ncol=sqrt(nrow( X))),
main="Adjusted Inclusion Probabilities", ylab="y", xlab="x")
points( X[legacySites,], pch=20, col=1)
}
#tidy
rm( N, n, nLegacy, X, p, legacySites, p2)
Run the code above in your browser using DataLab