swd | R Documentation |
Selects spatially balanced samples through the use of the
Sum Within Distance design (SWD). To have a constant inclusion
probabilities π_{i}=n/N, where n is sample size and
N is population size, the distance matrix has to be standardized with
function stsum
.
swd(dis, n, beta = 10, nrepl = 1L, niter = 10L)
dis |
A distance matrix NxN that specifies how far all the pairs of units in the population are. |
n |
Sample size. |
beta |
Parameter β for the algorithm. The higher β is, the more the sample is going to be spread. |
nrepl |
Number of samples to draw (default = 1). |
niter |
Maximum number of iterations for the algorithm. More iterations are better but require more time. Usually 10 is very efficient (default = 10). |
Returns a list with the following components:
s
, a matrix nrepl
x n
, which contains the
nrepl
selected samples, each of them stored in a row. In particular,
the i-th row contains all labels of units selected in the i-th sample.
iterations
, number of iterations run by the algorithm.
Benedetti R, Piersimoni F (2017). A spatially balanced design with probability function proportional to the within sample distance. Biometrical Journal, 59(5), 1067-1084. doi: 10.1002/bimj.201600194
# Example 1 # Draw 1 sample of dimension 15 without constant inclusion probabilities dis <- as.matrix(dist(cbind(income_emilia$x_coord, income_emilia$y_coord))) # distance matrix s <- swd(dis = dis, n = 15)$s # drawn sample # Example 2 # Draw 1 sample of dimension 15 with constant inclusion probabilities # equal to n/N, with N = population size dis <- as.matrix(dist(cbind(income_emilia$x_coord,income_emilia$y_coord))) # distance matrix con <- rep(1, nrow(dis)) # vector of constraints stand_dist <- stsum(mat = dis, con = con) # standardized matrix s <- swd(dis = stand_dist$mat, n = 15)$s # drawn sample # Example 3 # Draw 2 samples of dimension 15 with constant inclusion probabilities # equal to n/N, with N = population size and an increased level of spread, i.e. beta = 20 dis <- as.matrix(dist(cbind(income_emilia$x_coord,income_emilia$y_coord))) # distance matrix con <- rep(1, nrow(dis)) # vector of constraints stand_dist <- stsum(mat = dis, con = con) # standardized matrix s <- swd(dis = stand_dist$mat, n = 15, beta = 20, nrepl = 2)$s # drawn samples
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.