View source: R/inclusion_prob.R
| inclusion_prob | R Documentation |
Calculate stratified (first-order) inclusion probabilities.
inclusion_prob(x, n, strata = NULL, alpha = 0.001, cutoff = Inf)
becomes_ta(x, alpha = 0.001, cutoff = Inf)
x |
|
n |
|
strata |
|
alpha |
|
cutoff |
|
Within a stratum, the inclusion probability for a unit is given by
\pi = nx / \sum x. These values can be greater
than 1 in practice, and so they are constructed iteratively by taking units
with \pi \geq 1 - \alpha (from largest to smallest)
and assigning these units an inclusion probability of 1, with the remaining
inclusion probabilities recalculated at each step. See vignette("take-all")
for details. If \alpha > 0, then
any ties among units with the same size are broken by their position.
The becomes_ta() function reverses this operations and finds the critical
sample size at which a unit enters the take-all stratum. This value is
undefined for units that are always included in the sample (because their
size exceeds cutoff) or never included.
inclusion_prob() returns a numeric vector of inclusion probabilities for
each unit in the population.
becomes_ta() returns a numeric vector giving the sample size at which a
unit enters the take-all stratum.
kit::topn() is used if available to improve performance in the normal
case when the sample size is small relative to the population. Set
options(sps.usekit = FALSE) to disable this.
sps() for drawing a sequential Poisson sample.
# Make inclusion probabilities for a population with units
# of different size
x <- c(1:10, 100)
(pi <- inclusion_prob(x, 5))
# The last unit is sufficiently large to be included in all
# samples with two or more units
becomes_ta(x)
# Determine the number of take-all units before drawing a sample
n_ta <- function(x, n, cutoff = Inf) {
sum(becomes_ta(x, cutoff = cutoff) <= n, na.rm = TRUE) + sum(x >= cutoff)
}
n_ta(x, 7)
# Use the inclusion probabilities to calculate the variance of the
# sample size for Poisson sampling
sum(pi * (1 - pi))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.