surveywts 0.1.2
Breaking changes
- The default output weight column name for
calibrate(),rake(),poststratify(), andadjust_nonresponse()changes from".weight"to"wts"when the input is a plaindata.framewithweights = NULL.
New features
-
calibrate(),rake(),poststratify(), andadjust_nonresponse()gain awt_nameargument (default"wts") that controls the name of the output weight column fordata.frameandweighted_dfinputs. Input weight columns are preserved whenwt_namediffers from the input column name.wt_nameis silently ignored for survey object inputs.
surveywts 0.1.1
Breaking changes
adjust_nonresponse()now returns all rows with nonrespondent weights set to 0, instead of dropping nonrespondent rows. This preserves design structure for variance estimation. Code that usesnrow(result)to count respondents should usesum(result$weight_col > 0)instead.poststratify()now defaults totype = "prop", consistent withcalibrate()andrake(). Existing code that relies on the count default should add explicittype = "count".
Bug fixes
calibrate(),rake(), andpoststratify()now delegate tosurvey::calibrate(),survey::rake(),anesrake::anesrake(), andsurvey::postStratify()instead of vendored algorithm copies. This improves numerical correctness and maintainability (#16).adjust_nonresponse()response_statusargument now resolves viatidyselect::eval_select()instead ofrlang::as_name(), supporting tidy-select semantics and providing a clearer error for multi-column selection (#15).Input validation in
calibrate(),rake(),poststratify(), andadjust_nonresponse()now usessurvey_baseinheritance checks instead of listing specific class names (#15).summarize_weights()grouped path now usespaste(sep = "//")instead ofinteraction(), avoiding separator collisions with factor levels containing dots (e.g.,"Dr.") (#13).survey_nonprobprint method now shows"Variance: model-assisted (SRS assumption)"instead of incorrectly labelling it as Taylor linearization (#13).
surveywts 0.1.0
Breaking changes
adjust_nonresponse()now returns all rows with nonrespondent weights set to 0, instead of dropping nonrespondent rows. This preserves design structure for variance estimation. Code that usesnrow(result)to count respondents should usesum(result$weight_col > 0)instead.poststratify()now defaults totype = "prop", consistent withcalibrate()andrake(). Existing code that relies on the count default should add explicittype = "count".
Phase 0: Weighting Core
This is the first release of surveywts, implementing the core survey weighting workflow.
New classes
weighted_df: An S3 subclass of tibble that carries aweight_colattribute identifying the weight column and aweighting_historyattribute recording every weighting operation applied. Produced as output from calibration and nonresponse functions when the input is a plaindata.frameorweighted_df. Supports dplyr verbs (select(),rename(),mutate()) with automatic downgrade to a plain tibble (with a warning) if the weight column is removed.survey_nonprob(from surveycore): surveywts implementsprint()forsurvey_nonprobobjects, displaying design variables and weighting history.
New functions
calibrate(): Calibrate survey weights to known marginal population totals using linear (GREG) or logit (bounded IRLS) calibration for categorical auxiliary variables.rake(): Iterative proportional fitting to marginal population targets. Supports two methods:"anesrake"(chi-square variable selection with improvement-based convergence) and"survey"(fixed-order IPF with epsilon-based convergence). Margins may be a named list or a long data frame withvariable,level, andtargetcolumns.poststratify(): Exact post-stratification to known joint population cell counts or proportions in a single non-iterative pass.adjust_nonresponse(): Weighting-class nonresponse adjustment that redistributes nonrespondent weights to respondents within cells defined byby. Methods"propensity"and"propensity-cell"are stubbed for Phase 2.effective_sample_size(): Kish’s effective sample size (ESS = (Σw)² / Σw²).weight_variability(): Coefficient of variation of survey weights.summarize_weights(): Full distributional summary (n, mean, CV, ESS, percentiles), optionally grouped by one or more variables.
All functions accept data.frame, weighted_df, survey_taylor, and survey_nonprob inputs, and append a structured weighting history entry on every call.
Bug fixes
-
calibrate(),rake(), andpoststratify()now preserve the input class (survey_taylororsurvey_nonprob) rather than promoting all survey object inputs tosurvey_nonprob(#10).
