Package: weightflow 1.3.1

Juan Pablo Ferreira

weightflow: Weighting Probability and Non-Probability Survey Samples with Recipe-Aware Replicate Variances

Builds survey analysis weights by declaring the whole weighting process as an ordered recipe of explicit adjustments, estimated in a single call: unknown eligibility, within-cluster selection, two-phase subsampling, nonresponse by weighting classes or response-propensity models, calibration and trimming. Calibration to known totals runs on linear, raking or logit distances, bounded, ridge-penalized, model-assisted or integrative with one weight per cluster; a calibrated trim bounds the weights while keeping the control totals exact. Non-probability samples are weighted against a probability reference sample by pseudo-weighting, mass imputation and doubly robust estimators that calibrate a single weight on the fitted values of several working models and on the population totals of the auxiliaries at once, so one multipurpose weight serves many variables. Variances come from a recipe-aware bootstrap and jackknife that re-apply the entire cascade on each replicate, so every adjustment is inside the variance instead of being treated as fixed; across panel waves the replicates are coordinated by carrying forward the selection multiplicities of the sampling units, so the sample overlap enters the variance of a net change as covariance. Rotating and pure panels add attrition, longitudinal weights, gross flows and composite estimation, a self-contained HTML report documents each step, and the weights bridge to the 'survey' and 'srvyr' packages, which are optional: the package itself runs on base R. The methods, and the simulation evidence behind the variance estimators, are described in Ferreira (2026) <doi:10.1177/18747655261484262>.

Authors:Juan Pablo Ferreira [aut, cre], Andrés Gutiérrez [aut]

weightflow_1.3.1.tar.gz
weightflow_1.3.1.zip(r-4.7-any)weightflow_1.3.1.zip(r-4.6-any)weightflow_1.3.1.zip(r-4.5-any)
weightflow_1.3.1.tgz(r-4.6-any)weightflow_1.3.1.tgz(r-4.5-any)
weightflow_1.3.1.tar.gz(r-4.7-any)weightflow_1.3.1.tar.gz(r-4.6-any)
weightflow_1.3.1.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:
  • panel_cl - Synthetic rotating- and pure-panel datasets
  • panel_ine - Synthetic rotating- and pure-panel datasets
  • panel_puro - Synthetic rotating- and pure-panel datasets
  • panel_us - Synthetic rotating- and pure-panel datasets
  • population - Synthetic target population
  • sample_one - Synthetic address sample with one selected person per household
  • sample_survey - Synthetic person sample with a take-all household roster

On CRAN:

Conda:

7.53 score 8 stars 27 scripts 506 downloads 77 exports 0 dependencies

Last updated from:b895824695. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-develOK233
source / vignettesOK236
linux-releaseOK176
macos-releaseOK239
macos-oldrelOK208
windows-develOK210
windows-releaseOK195
windows-oldrelOK216
wasm-releaseOK106

Exports:as_sae_inputas_svrepdesignas_svydesignboot_flowsboot_meanboot_totalboot_transitionbootstrap_estimatebootstrap_weightschange_estimatechange_meanchange_totalcollect_estimatescollect_propensitiescollect_replicate_weightscollect_step_detailcollect_weightsdata_defectdesign_effectdisclosure_riskdomain_summaryhas_alertsjack_meanjack_totaljackknife_estimatejackknife_weightslevel_estimatelevel_meanlevel_totalnr_sensitivitypanel_designpanel_estimatepanel_meanpanel_mergepanel_prpanel_totalprepread_recipereference_samplereport_panelreport_weightingstep_assertstep_attritionstep_calibratestep_crestep_cross_sectionalstep_domainstep_drop_ineligiblestep_estimatestep_filterstep_longitudinalstep_model_calibrationstep_nonresponsestep_nr_sensitivitystep_panel_overlapstep_pseudoweightstep_rescalestep_roundstep_select_withinstep_subsamplestep_transitionstep_trimstep_trim_calibratedstep_trim_weightsstep_unknown_eligibilitytransition_matrixtwo_phase_variancewave_bootstrapwave_carrywave_contrastwave_jackknifewave_stepweight_factorsweighting_alertsweighting_specwrite_recipey_model

Dependencies:

Composite estimation: borrowing strength from the previous wave
The estimator | The birth rotation group, and why there are two imputations | Where each symbol lives in the call | The recursion | What it buys | The variance trap | The fat carry | Equal representation across rotation groups | References | Where to look next

Last update: 2026-10-14
Started: 2026-09-10

From raw sample to final weights
The problem is not the weights | A map of what the steps are for | The same strategy as one object | The shortest real recipe | The object is the documentation | Where to go next

Last update: 2026-10-14
Started: 2026-07-09

Non-probability samples
The two files | A volunteer sample that is wrong in four different ways | The reference is a sample, so give it its replicates | Step one: the pseudo-weight | What the sum of the weights is telling you | Step two: one calibration that carries every variable | Where it stops working: the rank ceiling | What sharing costs | What the reference contributes | Dissemination | How large is this sample, really? | Hold something out, because the weights cannot see selection bias | The whole thing | In short | References

Last update: 2026-10-14
Started: 2026-08-29

Pure panels: the longitudinal weight and gross flows
The sequence, and which verb does each step | The longitudinal file is an intersection | Three ways to be missing, and only one of them is nonresponse | Attrition compounds | Calibrate to the first wave | Gross flows | Cross-sectional estimates from a longitudinal file are reference only | Where to look next

Last update: 2026-10-14
Started: 2026-09-10

Rotating panels: net change, chaining and gross flows
The structure comes first | Net change between two periods | Chaining: how production actually runs | The estimands are declared, not programmed | The chain | What has to be saved | Combinations over the chain | The composite estimator | Gross flows: who moved | Where to look next

Last update: 2026-10-14
Started: 2026-09-10

Coordinated replication: what travels between waves
What has to travel | The four cases | Reading $strata | The covariance is the pairing | previous is a list, and the lag is a design property | What coordination does not touch | Where to look next

Last update: 2026-09-28
Started: 2026-09-10

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 | Equal weights within a household | Relationship to the literature | See also

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

Two-phase (double) sampling
When there is a second phase of sampling | A worked example | The two-phase variance | The cascade is re-run on every replicate | Calibrating the subsample to the first-phase sample | Scope | References

Last update: 2026-09-28
Started: 2026-08-29

Validation against survey and ReGenesees
Post-stratification | Raking | Calibration distances | Linear (chi-square) distance -- the GREG estimator | Raking (exponential) distance -- always-positive weights | Logit distance -- bounded g-weights | Distribution of the adjustment factors | Integrative calibration (one weight per household) | Domain (partitioned) calibration | Estimates agree too | Agreement summary | Beyond survey: two checks against ReGenesees | Trimmed calibration matches trimcal() | Net change matches the analytic Berger-Priam estimator | What weightflow adds

Last update: 2026-09-10
Started: 2026-09-10

weightflow in production (GSBPM 5.6)
The recipe is the artifact | A programmatic quality gate | Reproducibility | The report is the quality document | Variance and dissemination | Where it sits | See also

Last update: 2026-08-29
Started: 2026-08-29

Calibrating to a reference survey
A reference survey is a weighted data frame | Estimated totals carry variance, so propagate it | Only the bootstrap propagates this component | When to use which

Last update: 2026-08-24
Started: 2026-08-24

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 | See also | References

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

Documenting and auditing the weights: the quality report
A worked recipe | What the report contains | Arguments

Last update: 2026-08-24
Started: 2026-08-03

Inspecting and auditing the cascade
Every step has a stable id | The quality-alert gate | Unit by unit: what did a step do? | Domain by domain: is each domain reliable? | HTML report vs programmatic QC

Last update: 2026-08-24
Started: 2026-08-24

Nonresponse: weighting classes, propensities and calibration
Weighting classes | Response propensities | Logistic regression | Trees, forests and boosting | Flexibility, overfitting, and cross-fitting | Weighting the propensity model | Person or household level | Nonresponse by calibration | Which to use | See also

Last update: 2026-08-24
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 | Method 3: a delete-a-PSU jackknife that re-applies the recipe | Lonely PSUs and parallel replicates | When the finite-population correction matters | Confidence intervals: normal, t and percentile | Estimated control totals | Which one to use

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

Ways to specify calibration totals
Post-stratification | One variable | Several variables crossed | Raking | Linear / GREG calibration | Why the totals are usually awkward | The tidy way | Mixing categorical and continuous auxiliaries | Domain (partitioned) calibration | Model calibration | Validation and messages | Which one should I use? | See also

Last update: 2026-08-24
Started: 2026-07-04

Trimming survey weights
Automatic caps: step_trim_weights() | Ratio caps: step_trim() | Calibration-preserving caps: step_trim_calibrated() | Bounds that differ by subgroup | Which one should I use? | References

Last update: 2026-08-06
Started: 2026-08-06

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

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

Preparing the sample: eligibility and response before weighting
The disposition tree | What each branch means, and when it happens | Why there is unused and out-of-scope sample: sizing the design | What your input data needs | Order of operations | A full pipeline on the multistage sample | The same recipe with the ready-made indicator columns | References

Last update: 2026-07-13
Started: 2026-07-05

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-07-13
Started: 2026-06-20

Readme and manuals

Help Manual

Help pageTopics
Direct estimates and design SEs per domain, ready for small-area estimationas_sae_input
Export weightflow weights to a survey designas_svrepdesign as_svydesign
Gross-flow TOTALS with standard errors, plus net flows and marginsboot_flows
Transition matrix with per-cell bootstrap standard errorsboot_transition
Bootstrap estimate, standard error and confidence intervalbootstrap_estimate boot_mean boot_total
Recipe-aware bootstrap replicate weightsbootstrap_weights
Net change between two panel waves, with honest variancechange_estimate change_mean change_total
Evaluate an estimation pipelinecollect_estimates
Recover the fitted response propensities of a nonresponse stepcollect_propensities
Collect replicate weights into a data frame ready for srvyrcollect_replicate_weights
Per-unit detail of one step of the cascadecollect_step_detail
Extract the data with the computed weightscollect_weights
Data-defect diagnostics for a non-probability sampledata_defect
Kish design effect from unequal weightingdesign_effect
Flag re-identification risk from outlier weights within a publication celldisclosure_risk
Per-domain weight summary at every stage of the cascadedomain_summary
Jackknife estimate, standard error and confidence intervaljackknife_estimate jack_mean jack_total
Recipe-aware delete-a-PSU jackknife replicate weightsjackknife_weights
Level estimate for a single panel wave, with its replicate variancelevel_estimate level_mean level_total
Read the nonresponse-sensitivity analysis from a prepped recipenr_sensitivity
Synthetic rotating- and pure-panel datasetspanel_cl panel_datasets panel_ine panel_puro panel_us
Describe the rotating-panel structure of a surveypanel_design
Linear combination of panel waves, with honest between-wave variancepanel_estimate panel_mean panel_total
Build the wide longitudinal file from per-wave surveyspanel_merge
Panel-selection probability for a set of combined wavespanel_pr
Diagnostic plots for the weightsplot.prepped_weighting_spec
Synthetic target population (sampling frame)population
Estimate the weighting cascadeprep
Print a bootstrap replicate-weight objectprint.weightflow_boot
Print a jackknife replicate-weight objectprint.weightflow_jack
Read a weighting recipe from a YAML fileread_recipe
Use a weighted survey as the calibration reference instead of a framereference_sample
Panel / longitudinal HTML reportreport_panel
Self-contained HTML quality report for a weighting recipereport_weighting
Synthetic address sample with one selected person per householdsample_one
Synthetic person sample with a take-all household rostersample_survey
Assert quality conditions on the weightsstep_assert
Attrition adjustment for panel wavesstep_attrition
Calibration to population totalsstep_calibrate
Composite regression estimator (CRE / regression composite estimation)step_cre
Declare the recipe's scope: cross-sectional or longitudinal weightsstep_cross_sectional step_longitudinal
Declarative estimation over a coordinated panel objectstep_domain step_estimate step_filter step_transition
Drop ineligible (out-of-scope) unitsstep_drop_ineligible
Model calibration (Wu and Sitter 2001)step_model_calibration
Nonresponse adjustmentstep_nonresponse
Sensitivity of a mean to nonignorable nonresponse or selectionstep_nr_sensitivity
Adjust base weights by the panel-selection probability (CEPAL ch. XVI)step_panel_overlap
Pseudo-weights for a non-probability sample against a referencestep_pseudoweight
Rescale the weights to a fixed sumstep_rescale
Round the final weightsstep_round
Within-cluster selection adjustmentstep_select_within
Second-phase subsampling (two-phase sampling)step_subsample
Trim extreme weights against a ratiostep_trim
Trimmed calibration (range-restricted, totals-preserving)step_trim_calibrated
Automatic weight trimming to an absolute bandstep_trim_weights
Unknown-eligibility adjustmentstep_unknown_eligibility
Detailed per-step diagnosticssummary.prepped_weighting_spec
Gross-flow transition matrix between two panel wavestransition_matrix
Decompose a two-phase variance into V = V1 + V2two_phase_variance
Coordinated bootstrap across panel waveswave_bootstrap
Extract the carry artifact of a periodwave_carry
Linear combination of an estimand across a chain of periodswave_contrast
Coordinated delete-one jackknife across panel waveswave_jackknife
One period of a coordinated panel bootstrap, chained from the previous oneswave_step
Per-unit adjustment factors tableweight_factors
Quality alerts raised while preparing a recipeweightflow-alerts
Conventions shared by every weightflow stepweightflow-concepts
Quality alerts recorded while preparing a recipehas_alerts weighting_alerts
Start a weighting specificationweighting_spec
Write a weighting recipe to a YAML filewrite_recipe
Specify a working model for a study variable yy_model