surveycore 0.6.2
Bug fixes
- Moved
dplyrfrom Suggests to Imports (used unguarded in metadata functions). - Fixed broken
vignette("estimation")cross-reference increating-survey-objectsvignette. - Fixed non-canonical CRAN URLs in
surveycore-vs-surveyvignette.
Documentation
- Updated README to reflect current API:
as_survey_replicate()(notas_survey_rep()), addedget_diffs(),survey_glm(), andsurvey_nonprob. - Added
@examplesto 12 exported functions and@returntosurvey_basefor CRAN compliance.
surveycore 0.6.0
Breaking changes
-
survey_srsclass andas_survey_srs()constructor have been removed. SRS designs are now created viaas_survey()with noidsorstrata— this produces asurvey_taylorwith no cluster/strata structure. All estimates are numerically identical.
New features
get_diffs()estimates treatment effects (differences from a reference group) via survey-weighted regression. Supports bivariate and multivariate models, Gaussian and non-Gaussian families, and optional subgroup analysis. Two estimation paths: direct coefficients for simple models, andmarginaleffects::avg_slopes()/avg_predictions()for models with covariates or non-Gaussian AMEs. Returns asurvey_diffstibble with optionalmean,pct_change,n_weightedcolumns, significance stars, and p-value adjustment.marginaleffectsmoved from Suggests to Imports.as_survey()now supports multi-column FPC for multi-stage designs (e.g.,fpc = c(fpc_stage1, fpc_stage2)). Each FPC column corresponds to one ID stage. Per-stage FPC is validated for NAs, non-positive values, and within-cluster constancy.print()forsurvey_taylornow displays per-stage FPC bullets for multi-stage designs (e.g.,FPC (stage 1): fpc,FPC (stage 2): fpc2).
Bug fixes
SRS variance estimation now uses Taylor (HT) linearization via
.build_cluster_matrices(), correct for any weight structure. Previously used unweighted sample variance which was incorrect for non-proportional weights.survey_glm()now correctly indexes weights whenna.action = na.omitdrops non-contiguous rows.get_freqs()now routessurvey_nonprobdesigns through the Horvitz-Thompson variance path, consistent with the other five analysis functions.as_survey_twophase()now acceptssurvey_replicateand SRSsurvey_taylorobjects as the phase-1 design (previously restricted to stratified/clusteredsurvey_tayloronly).as_survey()SRS fallback downgraded from warning to message.
surveycore 0.5.0
Breaking changes
as_survey_replicate()replacesas_survey_repweights(). The constructor name now matches the underlyingsurvey_replicateclass.survey_nonprobandas_survey_nonprob()replacesurvey_calibratedandas_survey_calibrated(). “Calibrated” implies a post-processing step on a probability sample;nonprobaccurately reflects the design type.survey_srsandas_survey_srs()have been removed. SRS designs are now created viaas_survey()with noidsorstrata— this produces asurvey_taylorwith no cluster/strata structure. All estimates are numerically identical. Print output now says “Taylor series linearization” instead of “simple random sample”.Single-row data frames are now rejected at construction time (previously a warning). This matches
survey::svydesign()behavior.The positional setter form
set_var_label(svy, age, "label")has been removed. Use the named formset_var_label(svy, age = "label")instead.extract_var_label(),extract_question_preface(), andextract_var_note()now return a named character vector.extract_var_label(svy, age)now returnsc(age = "Age in years")rather than"Age in years".extract_val_labels()now returns a named list.extract_val_labels(svy, sex)now returnslist(sex = c(Male = 1L, Female = 2L))rather thanc(Male = 1L, Female = 2L).set_variable_labels(),set_value_labels(),set_question_prefaces(), andset_variable_notes()have been removed. Useset_var_label(),set_val_labels(),set_question_preface(), andset_var_note()respectively — all four now accept multiple variables via named....
New features
set_universe()andextract_universe()set and retrieve universe (eligibility) annotations for survey variables.set_missing_codes()andextract_missing_codes()set and retrieve missing value code vectors for survey variables.extract_metadata()returns all metadata fields (variable_label,value_labels,question_preface,note,universe,missing_codes,transformations) for one or more variables as a named list.
Enhancements
All setter functions now support three call conventions: named
...(e.g.,set_var_label(svy, age = "Age in years")), a single named vector/list in..., or explicitvariable =/ content-argument pairs. All setters also now work on plaindata.frames.All extractor functions accept multiple variables via
..., support three output formats ("named_vector","list","data_frame"), and accept afillargument to include variables with no metadata in the output.
surveycore 0.4.0
New features
survey_glm()fits survey-weighted generalized linear models for all four design classes (survey_taylor,survey_replicate,survey_twophase,survey_nonprob); returns asurvey_glm_fitobject with design-based (Binder 1983 sandwich) standard errors and degrees of freedom.clean()converts asurvey_glm_fitto a tidysurvey_glm_tidytibble with one row per coefficient, design-based confidence intervals, structured metadata, and optional reference rows for factor predictors.survey_glm_fitobjects support 20 S3 methods:print(),summary(),coef(),vcov(),predict(),fitted(),residuals(),confint(),formula(),terms(),model.matrix(),model.frame(),deviance(),df.residual(),nobs(),hatvalues(),logLik(),AIC(),BIC(), andupdate().survey_glm_fitintegrates with themarginaleffectspackage; whenmarginaleffectsis installed,avg_slopes(),avg_predictions(), and the full marginaleffects API work directly onsurvey_glm_fitobjects.broom::tidy()is supported forsurvey_glm_fitobjects via a shim that delegates toclean().as_survey_rep()has been renamed toas_survey_replicate()to avoid a namespace clash with thesrvyrpackage.
Bug fixes
-
as_survey_twophase()variance estimation (method = "approx"and"full") now uses the correct PSU-level Phase 2 stratum sampling fraction instead of a row-level fraction, resolving an approximately 2× variance underestimation.
surveycore 0.3.3
New features
-
print()methods for all four survey design classes (survey_taylor,survey_replicate,survey_twophase,survey_nonprob) now display aDomain: <n> of <N> rowsline whensurveytidy::filter()has been applied. The line appears after the sample size line and before theGroups:line. For two-phase designs, domain counts reflect Phase 2 rows only.
surveycore 0.3.0
New features
-
names()now works on survey design objects, returning the column names of the underlying data frame. This enables IDE column-name autocomplete in RStudio and Positron when piping into analysis functions (e.g.,design |> get_means().
surveycore 0.2.0
New features
get_freqs()computes weighted frequency tables for categorical survey variables across all five design types, with domain estimation, value-label support, and AAPOR small-cell warnings.get_means()returns survey-weighted means with design-correct standard errors for all five design types, including grouped and domain estimation.get_totals()returns survey-weighted population totals (and population size when called withoutx) for all five design types.get_corr()computes survey-weighted Pearson correlation using the delta-method variance approach, with optionalgroupparameter for per-group correlations and Fisher Z confidence intervals.-
get_quantiles()estimates survey-weighted quantiles using the Woodruff- linearization method; supports multiple
probsin a single call and five CI interval methods.
- linearization method; supports multiple
get_ratios()estimates survey-weighted ratios (numerator total / denominator total) with design-correct SEs via the delta method (Taylor, SRS, calibrated, two-phase) or direct per-replicate computation (replicate designs).All six analysis functions gain a
decimalsargument to round numeric output columns to a fixed number of decimal places.na.rm = FALSEnow includes rows where a grouping variable isNAas a separate group row in all six analysis functions’ output.infer_question_prefaces()auto-detects shared battery prefaces from variable labels using separator-based and longest-common-prefix detection.survey_weighting_history()returns the weighting history stored in a survey design object’s metadata;as_survey(),as_survey_replicate(), andas_survey_nonprob()now promote"weighting_history"attributes from the input data frame automatically.Two-phase variance estimation (
as_survey_twophase()) is now fully supported inget_means()andget_totals(), using the"full","approx", and"simple"methods vendored from thesurveypackage.
Bug fixes
get_freqs()no longer crashes when thegroupvariable containsNAvalues.get_freqs()now outputspctas a proportion (0–1) rather than a percentage (0–100);seandse_srsare on the same scale.
surveycore 0.1.0
New features
as_survey()createssurvey_taylorobjects with a tidy-select interface (ids,weights,strata,fpc,probs); supports Taylor linearization for stratified, clustered, and SRS designs.as_survey_replicate()createssurvey_replicateobjects; supports BRR, Fay BRR, JK1, JK2, JKn, bootstrap, ACS, and successive-difference replicate schemes.as_survey_twophase()createssurvey_twophaseobjects; supports “full”, “approx”, and “simple” two-phase variance estimation methods.update_design()modifies design variables on an existing survey object without reconstructing from scratch; respectsvalidate = TRUE/FALSE.get_means()returns a weighted mean and standard error via Taylor linearization or replicate weights; respectsgetOption("survey.lonely.psu")for single-PSU strata.get_totals()returns a weighted total and standard error using the same dispatch asget_means().Metadata setters:
set_var_label(),set_variable_labels(),set_val_labels(),set_value_labels(),set_question_preface(),set_question_prefaces(),set_var_note(),set_variable_notes(). Single-variable setters automatically import haven"label"/"labels"attributes from the data frame column.Metadata extractors:
extract_var_label(),extract_val_labels(),extract_question_preface(),extract_var_note().Conversion utilities:
as_svydesign(),from_svydesign(),as_tbl_svy(),from_tbl_svy()— round-trip conversion between surveycore objects,survey::svydesign/survey::svrepdesign, andsrvyr::tbl_svy.print()andsummary()S7 methods for all survey design classes display design type, sample size, and a tibble-style data preview.
Internal infrastructure
S7 class hierarchy: abstract
survey_base→survey_taylor,survey_replicate,survey_twophase;survey_metadatafor label storage.Three-layer validation: S7 structural validators, Layer 2 input validators, Layer 3 constructor validators; all errors use typed
class=for programmatic handling.Variance estimation vendored from the
surveypackage (Thomas Lumley, GPL-2/GPL-3) — seeVENDORED.mdfor full attribution.
