sampling_design() is the entry point for creating survey sampling
specifications. It creates an empty design object that can be built
up using pipe-able verbs like stratify_by(), cluster_by(),
draw(), and stage().
sampling_design(title = NULL)A sampling_design object that can be piped to other design
functions.
The sampling design paradigm separates the specification of a sampling plan from its execution. This allows designs to be:
Reused across different data frames
Partially executed (e.g., stage by stage)
Inspected and validated before execution
Documented and shared
The design specification is frame-independent: it describes how to sample, not what to sample from.
A typical design workflow follows this pattern:
sampling_design() |>
stratify_by(...) |>
cluster_by(...) |>
draw(...) |>
execute(frame)stratify_by() for defining strata,
cluster_by() for defining clusters,
draw() for specifying selection parameters,
stage() for multi-stage designs,
execute() for running designs
if (FALSE) { # \dontrun{
# Simple random sample
sampling_design() |>
draw(n = 100) |>
execute(my_frame, seed = 42)
# Stratified sample with proportional allocation
sampling_design(title = "Regional Survey 2024") |>
stratify_by(region, alloc = "proportional") |>
draw(n = 1000) |>
execute(population_frame, seed = 42)
# Multi-stage cluster sample
sampling_design() |>
stage(label = "Schools") |>
cluster_by(school_id) |>
draw(n = 50, method = "pps_brewer", mos = enrollment) |>
stage(label = "Students") |>
draw(n = 20) |>
execute(school_frame, seed = 42)
} # }