sampfle {sampfling}R Documentation

Random Sampling: the Sampford Algorithm

Description

sampfle implements the Sampford algorithm to obtain a sample without replacement and with unequal probabilities. The probability of the sample is known a priori.

Usage

 sampfle(x, size, prob = NULL)

Arguments

x Either a (numeric, complex, character or logical) vector of more than one element from which to choose, or a positive integer.
size A positive integer giving the number of items to choose.
prob A vector of weights for obtaining the elements of the vector being sampled.

Details

If x has length 1, sampling takes place from 1:x.

The prob argument gives a vector of weights for obtaining the elements of the vector being sampled. They need not sum to one, but they should be nonnegative and, after normalizing, less than 1/size. The number of nonzero weights must be at least size.

The Sampford algorithm draws the first unit i with probability proportional to prob, and subsequent units with probabilities proportional to prob/(1-size*prob[i]) with replacement. As soon as a unit is repeated, the entire sample is rejected and the process is restarted. Thus a sample without replacement is obtained.

The algorithm produces a sample s, subset of x of size n, with probability proportional to

Pr[s]propto (1-sum z_i)prodfrac{z_i}{1-n z_i}

{(1 - Sum z[i]) Prod(z[i]/(1-n*z[i]))} where z[i] is the i-th element of prob, that is, prob[i]; and both the sum and the product extend over the drawn units, i in s.

Value

A vector, which contains the sampled units from x, or indices if x is an integer.

Author(s)

Carlos Enrique Carleos Artime carleos@vodafone.es.

References

Cochran, W.G. (1977) Sampling techniques, John Wiley and Sons.

Sampford, M.R. (1967) On sampling without replacement with unequal probabilities of selection, Biometrika 54:499-513.

See Also

samprop

Examples

library(sampfling)
sampfle(10, 3, 1:10)
sampfle(c("a","b","c"), 2, c(0.3,0.3,0.4))

[Package sampfling version 0.6-3 Index]