lpm2: Local pivotal method 2

View source: R/RcppExports.R

lpm2R Documentation

Local pivotal method 2

Description

Select spatially balanced samples with prescribed inclusion probabilities from a finite population. Euclidean distance is used in the x space.

Usage

lpm2(prob,x)	

Arguments

prob

vector of length N with inclusion probabilities

x

matrix of (standardized) auxiliary variables of N rows and q columns

Value

Returns a vector of selected indexes in 1,2,...,N. If the inclusion probabilities sum to n, where n is integer, then the sample size is fixed (n).

References

Grafström, A., Lundström, N.L.P. and Schelin, L. (2012). Spatially balanced sampling through the Pivotal method. Biometrics 68(2), 514-520.

Examples

## Not run: 
# Example 1
set.seed(12345);
N = 1000; # population size
n = 100; # sample size
p = rep(n/N,N); # inclusion probabilities
X = cbind(runif(N),runif(N)); # matrix of auxiliary variables
s = lpm2(p,X); # select sample 
plot(X[,1],X[,2]); # plot population
points(X[s,1],X[s,2], pch=19); # plot sample

# Example 2
# check inclusion probabilities
set.seed(12345);
p = c(0.2, 0.25, 0.35, 0.4, 0.5, 0.5, 0.55, 0.65, 0.7, 0.9); # prescribed inclusion probabilities
N = length(p); # population size
X = cbind(runif(N),runif(N)); # some artificial auxiliary variables
ep = rep(0,N); # empirical inclusion probabilities
nrs = 10000; # repetitions
for(i in 1:nrs){
  s = lpm2(p,X);
  ep[s]=ep[s]+1;
}
print(ep/nrs);


## End(Not run)

BalancedSampling documentation built on June 29, 2022, 5:06 p.m.