weightflow: declarative, recipe-aware survey weighting in R
Abstract
Producing analysis weights for a complex survey requires a sequence of hierarchical adjustments (resolving unknown eligibility, dropping out-of-scope units, restoring within-household selection, correcting for nonresponse, and calibrating to known population totals), after which design-consistent variances must account for the fact that several adjustments were themselves estimated from the sample. Existing R tools cover parts of this workflow, but none expresses the whole cascade as a single auditable object, nor propagates the variability of every stage into the replicate weights. We present weightflow, a dependency-free (base R) package that builds survey weights through a declarative, pipeable, tidymodels-style API: a recipe is defined lazily as a chain of step*() adjustments and estimated with prep(). Separating definition from application makes the process reproducible and auditable, and lets a rescaling bootstrap and a delete-a-PSU jackknife re-apply the entire recipe on each replicate, so the replicate weights carry the uncertainty of every estimated stage, not only of the final calibration. The package implements raking, post-stratification and linear/GREG calibration (with bounds, ridge penalisation, and domain-partitioned and integrative variants), model-assisted (Wu-Sitter) calibration, weighting-class and machine-learning response-propensity adjustments with cross-fitting, and representativity (R-)indicators. Weights and replicate weights bridge to the survey and srvyr packages for design-based inference. We validate the calibration and variance results against survey, and illustrate the full cascade on a bundled sample and on real household-survey microdata (the Uruguayan ECH), where it recovers a known poverty rate with design-based uncertainty.
Turn this paper into a full lesson
ArcXiv compiles a staged curriculum from this paper: 8-12 lessons across beginner → advanced, synthesised section guides, visuals, flashcards, a quiz, exercises, and on-demand deep dives per section. Grounded in the abstract, never invented.