balseq | R Documentation |
Selects at the same time a well-spread and a balanced sample using a sequential implementation.
balseq(pik, Xaux, Xspread = NULL, rord = TRUE)
pik |
A vector of inclusion probabilities. |
Xaux |
A matrix of auxiliary variables. The matrix must contains the |
Xspread |
An optional matrix of spatial coordinates. |
rord |
A logical variable that specify if reordering is applied. Default TRUE. |
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.
Return the selected indices in 1,2,...,N
BalancedSampling:lcube
, sampling:samplecube
.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.