Skip to contents

Draw sample_size samples from population_vector without replacement, weighted by sampling_probabilities

This function is intended for advanced use cases in which users require detailed control of sampling algorithms and data structures. Minimal input validation and error checks are performed – users are responsible for providing the correct inputs. For tutorials on the "proper" usage of the stochtree's advanced workflow, we provide several vignettes at stochtree.ai

Usage

sample_without_replacement(
  population_vector,
  sampling_probabilities,
  sample_size
)

Arguments

population_vector

Vector from which to draw samples.

sampling_probabilities

Vector of probabilities of drawing each element of population_vector.

sample_size

Number of samples to draw from population_vector. Must be less than or equal to length(population_vector)

Value

Vector of size sample_size

Examples

a <- as.integer(c(4,3,2,5,1,9,7))
p <- c(0.7,0.2,0.05,0.02,0.01,0.01,0.01)
num_samples <- 5
sample_without_replacement(a, p, num_samples)
#> [1] 4 3 2 5 7