Each unit is independently selected with the same probability p. Sample size is random.

bernoulli(p, N)

Arguments

p

Selection probability (same for all units), between 0 and 1.

N

Population size.

Value

An integer vector of selected indices (1 to N). Length is random with expected value N*p.

Details

Each unit is selected independently with probability p.

Properties:

  • Random sample size with expectation Np and variance Np*(1-p)

  • Equal inclusion probabilities: \(\pi = p\)

  • Very fast: O(N) time

See also

srs() for fixed sample size, up_poisson() for Bernoulli sampling with unequal probabilities

Examples

# Basic usage
set.seed(42)
idx <- bernoulli(0.3, 100)
length(idx)  # Random, expected = 30
#> [1] 34

# Sample size distribution
sizes <- replicate(1000, length(bernoulli(0.3, 100)))
mean(sizes)
#> [1] 30.228
var(sizes)
#> [1] 20.24426