
Select a Human Validation Sample with Exact Inclusion Probabilities & IPW Weights
Source:R/sampling.R
select_validation_sample.RdDraws a reproducible human-validation subset from a corpus of LLM-coded texts
using simple random, subgroup-stratified (proportional, equal-per-stratum
for DPF power, or Neyman-optimal), score-quantile stratified, or
cluster-stratified sampling. Returns exact inclusion probabilities
\(\pi_i \in (0, 1]\) and Horvitz-Thompson inverse-probability weights
\(w_i = 1 / \pi_i\) ready to pass directly into weighted ppi_mean() or
ppi_lm() (active / IPW-PPI).
Arguments
- data
A
data.frame(orllm_coded_data) representing the full population/corpus of units to sample from.- n
Target total number of units to select for human validation. For
strategy = "cluster", used to determine the number of clusters ifn_clustersisNULL.- strategy
Sampling design:
"simple": simple random sampling without replacement (SRSWOR)."stratified": stratified sampling acrossstrata_colusingallocation."neyman": shorthand for Neyman-optimal allocation (n_hproportional toN_h * SD_h) usingscore_col(andstrata_col, or quantile bins ofscore_colifstrata_colisNULL)."quantile": stratifies units inton_quantilesbins ofscore_col(covering distribution tails evenly)."cluster": whole-cluster sampling overcluster_col.
- strata_col
Name of the categorical stratification column (required for
strategy = "stratified", optional for"neyman").- score_col
Name of a numeric proxy/LLM score column used to estimate stratum SDs for Neyman allocation or to form quantile strata.
- cluster_col
Name of the cluster identifier column (required for
strategy = "cluster").- allocation
Stratum allocation rule for
"stratified"or"quantile":"proportional"(default),"equal"(maximizes power for subgroup DPF tests), or"neyman"(minimizes overall variance).- n_quantiles
Integer number of quantile strata for
strategy = "quantile"(or"neyman"withoutstrata_col). Default4L.- n_clusters
Optional integer number of whole clusters to select when
strategy = "cluster". Overridesnif supplied.- min_per_stratum
Minimum units selected per stratum (capped by stratum size). Default
2L.- seed
Optional integer random seed. Uses local RNG state restoration so global
.Random.seedis never mutated.
Value
An S3 object of class "llm_validation_sample" containing:
selected_idx: sorted integer vector of selected row indices.selected: logical indicator vector of lengthnrow(data).inclusion_prob: numeric vector of exact positive inclusion probabilities \(\pi_i\).weights: numeric vector of Horvitz-Thompson weights \(w_i = 1 / \pi_i\).data: tibble copy ofdataaugmented withis_validation,inclusion_prob, andsampling_weight.stratum_summary: tibble summarizing population size, selected count, inclusion probability, and weight per stratum.strategy,allocation,n_target,n_selected,n_population.
Examples
data(ema_coded)
agg <- aggregate_scores(ema_coded, score_col = "llm_score")
vs <- select_validation_sample(
agg, n = 40, strategy = "stratified",
strata_col = "group", allocation = "equal", seed = 42
)
vs
#>
#> ── Validation Sample Plan (stratified / equal)
#> Selected 40 of 120 units (33.3%) | Weight range: [2.90, 3.10]
#> # A tibble: 2 × 6
#> stratum n_pop n_selected inclusion_prob weight stratum_sd
#> <chr> <int> <int> <dbl> <dbl> <dbl>
#> 1 group_a 58 20 0.345 2.9 NA
#> 2 group_b 62 20 0.323 3.1 NA