Learn R Programming

StratifiedSampling (version 0.4.1)

balseq: Sequential balanced sampling

Description

Selects at the same time a well-spread and a balanced sample using a sequential implementation.

Usage

balseq(pik, Xaux, Xspread = NULL, rord = TRUE)

Value

Return the selected indices in 1,2,...,N

Arguments

pik

A vector of inclusion probabilities.

Xaux

A matrix of auxiliary variables. The matrix must contains the pik vector to have fixed sample size.

Xspread

An optional matrix of spatial coordinates.

rord

A logical variable that specify if reordering is applied. Default TRUE.

Details

The function selects a sample using a sequential algorithm. At the same time, it respects the balancing equations (Xaux) and select a well-spread sample (Xspread). Algorithm uses a linear program to satisfy the constraints.

See Also

BalancedSampling:lcube, sampling:samplecube.

Examples

Run this code
N <- 100
n <- 10
p <- 10

pik <- rep(n/N,N)

Xaux <- array(rnorm(N*p,3,1),c(N,p))

Xspread <- cbind(runif(N),runif(N)) 
Xaux <- cbind(pik,Xaux)

s <- balseq(pik,Xaux)
colSums(Xaux[s,]/as.vector(pik[s]))
colSums(Xaux)


s <- balseq(pik,Xaux,Xspread)
colSums(Xaux[s,]/as.vector(pik[s]))
colSums(Xaux)

Run the code above in your browser using DataLab