Package: weightflow 0.1.0

Juan Pablo Ferreira

weightflow: Declarative API for Staged Survey Weights

Builds survey weights from design base weights by chaining hierarchical adjustments (unknown eligibility, nonresponse and calibration) through a declarative, pipeable, 'tidymodels'-style API. Calibration follows Deville and Sarndal (1992) <doi:10.2307/2290268>. Variances are obtained with a bootstrap that resamples primary sampling units and re-applies the whole recipe on each replicate, following the rescaling bootstrap of Rao and Wu (1988) <doi:10.1080/01621459.1988.10478591>, so the replicate weights carry the variability of every adjustment. The weights also bridge to the 'survey' and 'srvyr' packages for design-based inference.

Authors:Juan Pablo Ferreira [aut, cre]

weightflow_0.1.0.tar.gz
weightflow_0.1.0.zip(r-4.7)weightflow_0.1.0.zip(r-4.6)weightflow_0.1.0.zip(r-4.5)
weightflow_0.1.0.tgz(r-4.6-any)weightflow_0.1.0.tgz(r-4.5-any)
weightflow_0.1.0.tar.gz(r-4.7-any)weightflow_0.1.0.tar.gz(r-4.6-any)
weightflow_0.1.0.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
weightflow/json (API)

# Install 'weightflow' in R:
install.packages('weightflow', repos = c('https://jpferreira33.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/jpferreira33/weightflow/issues

Pkgdown/docs site:https://jpferreira33.github.io

Datasets:

On CRAN:

Conda:

5.06 score 1 stars 11 scripts 38 downloads 25 exports 0 dependencies

Last updated from:639c646ae1. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64OK147
source / vignettesOK180
linux-release-x86_64OK163
macos-release-arm64OK84
macos-oldrel-arm64OK100
windows-develOK88
windows-releaseOK84
windows-oldrelOK123
wasm-releaseOK147

Exports:as_svrepdesignas_svydesignboot_meanboot_totalbootstrap_estimatebootstrap_weightscollect_replicate_weightscollect_weightsdesign_effectprepreport_weightingstep_assertstep_calibratestep_drop_ineligiblestep_model_calibrationstep_nonresponsestep_rescalestep_roundstep_select_withinstep_trimstep_trim_weightsstep_unknown_eligibilityweight_factorsweighting_specy_model

Dependencies:

Calibration: raking, post-stratification and GREG
What calibration does | Why calibration reduces variance: the regression link | Post-stratification | Raking | Linear calibration (GREG) | Bounded calibration | Equal weights within a cluster | Which to use | References

Last update: 2026-06-26
Started: 2026-06-26

Nonresponse: weighting classes and propensities
Weighting classes | Response propensities | Logistic regression | Trees, forests and boosting | Flexibility, overfitting, and cross-fitting | Person or household level | Which to use

Last update: 2026-06-26
Started: 2026-06-20

Variance estimation
Why the adjustments matter for variance | Method 1: a PSU bootstrap that re-applies the recipe | Estimates with bootstrap standard errors | Method 2: hand the weights to the survey package | Replicate weights for a tidyverse workflow | Which one to use

Last update: 2026-06-26
Started: 2026-06-20

Model calibration (model-assisted weighting)
The idea | In weightflow, with a random forest | Validation: the constraints are met exactly | Does it help the estimate? | What you need: unit-level auxiliaries | The hybrid: model term and consistency constraints | Relationship to the literature

Last update: 2026-06-26
Started: 2026-06-20

Staged survey weighting: the adjustment logic
The starting point: design weights | The cascade | Unknown eligibility | Ineligible units | Within-household selection | Nonresponse | Calibration | Trimming, rounding, rescaling | Reading the cascade: the design effect | Why the order matters

Last update: 2026-06-25
Started: 2026-06-20

Machine learning, cross-fitting and robust calibration
Flexible propensities | The overfitting problem | Cross-fitting | Ridge (penalized) calibration | Potter (MSE-optimal) trimming | Putting it together | References

Last update: 2026-06-25
Started: 2026-06-25

Validation against the survey package
Post-stratification | Raking | Linear (GREG) calibration | Same estimates | What weightflow adds

Last update: 2026-06-20
Started: 2026-06-20

Readme and manuals

Help Manual

Help pageTopics
Export weightflow weights to a survey designas_svrepdesign as_svydesign
Bootstrap estimate, standard error and confidence intervalbootstrap_estimate boot_mean boot_total
Bootstrap replicate weights that re-apply the recipebootstrap_weights
Collect replicate weights into a data frame ready for srvyrcollect_replicate_weights
Extract the data with the computed weightscollect_weights
Kish design effect from unequal weightingdesign_effect
Diagnostic plots for the weightsplot.prepped_weighting_spec
Example target population for weightflowpopulation
Estimate the weighting cascadeprep
Build a nice HTML report of the weighting recipereport_weighting
Example survey sample (select-one-person, multistage)sample_one
Example survey sample (take-all roster)sample_survey
Assert conditions on the weights at this point of the cascadestep_assert
Calibration to population totalsstep_calibrate
Drop ineligible (out-of-scope) unitsstep_drop_ineligible
Model calibration (model-assisted, Wu & Sitter 2001)step_model_calibration
Nonresponse adjustmentstep_nonresponse
Rescale (normalize) the weightsstep_rescale
Round the final weightsstep_round
Within-household selection adjustmentstep_select_within
Trim extreme weightsstep_trim
Automatic weight trimming (survey-style)step_trim_weights
Unknown-eligibility adjustmentstep_unknown_eligibility
Detailed per-step diagnosticssummary.prepped_weighting_spec
Per-unit adjustment factors tableweight_factors
Start a weighting specificationweighting_spec
Specify a working model for a study variable yy_model