Skip to contents

surveywts 0.1.2

Breaking changes

New features

  • calibrate(), rake(), poststratify(), and adjust_nonresponse() gain a wt_name argument (default "wts") that controls the name of the output weight column for data.frame and weighted_df inputs. Input weight columns are preserved when wt_name differs from the input column name. wt_name is 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 uses nrow(result) to count respondents should use sum(result$weight_col > 0) instead.

  • poststratify() now defaults to type = "prop", consistent with calibrate() and rake(). Existing code that relies on the count default should add explicit type = "count".

Bug fixes

Internal

  • Moved shared helpers .check_input_class() and .get_history() to R/utils.R; inlined %||% operator (#12).

  • Moved survey from Suggests to Imports; added anesrake to Imports (#16).

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 uses nrow(result) to count respondents should use sum(result$weight_col > 0) instead.

  • poststratify() now defaults to type = "prop", consistent with calibrate() and rake(). Existing code that relies on the count default should add explicit type = "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 a weight_col attribute identifying the weight column and a weighting_history attribute recording every weighting operation applied. Produced as output from calibration and nonresponse functions when the input is a plain data.frame or weighted_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 implements print() for survey_nonprob objects, 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 with variable, level, and target columns.

  • 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 by by. 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(), and poststratify() now preserve the input class (survey_taylor or survey_nonprob) rather than promoting all survey object inputs to survey_nonprob (#10).